[R] Need help

J C Nash pro|jcn@@h @end|ng |rom gm@||@com
Thu Aug 4 15:40:28 CEST 2022


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
>



More information about the R-help mailing list