I trying to find the solution of the following using uniroot()
in R
.
library(rootSolve)
set.seed(2)
y=rgamma(10,5,2)
myfun=function(y,t)as.numeric(integrate(function(x){ ((x^4) * exp(-x/2))/768 },0,upper=2)[1])-t
myfun(y, y)
final_fun=function(y)uniroot(myfun,c(-2, 2),tol=0.01,t=y)
final_fun(y)
However, I am getting the following errors.
Error in uniroot(myfun, c(-2, 2), tol = 0.01, t = y) :
f() values at end points not of opposite sign
I tried several values for upper
and lower
limits, but R
is giving the same errors. My question is, how to find the correct upper
and lower
values? Thanks for the help.