Dear R Experts, I hope that you are doing well. I am facing a problem to find out the value of the following function. I need help in this regard. ##### a=rnorm(1000, 110, 5) b = rnorm(1000, -0.3, 0.4) s = length(a) lam=0.15 thr=70 r= 10 ff = function(zz){ inner = vector("numeric", length = s) for(k in 1:s){ inner[k]=(1- lam*((1+b[k]*((zz-thr)/a[k]))^(-1/b[k]))) } answer = mean(inner)- (1- (1/r)) return(answer) } ######## out=uniroot(ff, lower = 0, upper = 10000 )$root out ########### Error ######## Error in uniroot(ff, lower = 0, upper = 10000) : f.upper = f(upper) is NA Please help me. Thanks in advance. Take care. Hossain -- Best Regards, Md. Moyazzem Hossain Associate Professor Department of Statistics Jahangirnagar University Savar, Dhaka-1342, Bangladesh [[alternative HTML version deleted]]
Have you checked that your function actually crosses zero? You should also set a seed if you want a reproducible result. JN On 2022-08-04 09:30, Md. Moyazzem Hossain wrote:> Dear R Experts, > > I hope that you are doing well. > > I am facing a problem to find out the value of the following function. I > need help in this regard. > > ##### > a=rnorm(1000, 110, 5) > b = rnorm(1000, -0.3, 0.4) > s = length(a) > lam=0.15 > thr=70 > r= 10 > > ff = function(zz){ > inner = vector("numeric", length = s) > for(k in 1:s){ > inner[k]=(1- lam*((1+b[k]*((zz-thr)/a[k]))^(-1/b[k]))) > } > answer = mean(inner)- (1- (1/r)) > return(answer) > } > ######## > out=uniroot(ff, lower = 0, upper = 10000 )$root > out > > ########### Error ######## > Error in uniroot(ff, lower = 0, upper = 10000) : > f.upper = f(upper) is NA > > Please help me. Thanks in advance. > > Take care. > > Hossain >