Dear all, For the following code, I have the error message "Error in uniroot(f1star, lower = -10, upper = 0, tol = 1e-10, lambda = lam[i], : f() values at end points not of opposite sign".
It seems the problem occurs when lambda is equal to 0.99. However, there should be a solution for "f1star(lamda=0.99, p1=0.1, z)=0" for z values. Thank you very much in advance for the help. Hannah f1star <- function(lambda, p1,z){ lambda*((u1^2)*p1*exp(u1*z-u1^2/2)+(u2^2)*(0.2-p1)*exp(u2*z-u2^2/2))-(1- lambda)*pi0} f2star <- function(p1, cl, cu){ pi0*(pnorm(cl)+(1-pnorm(cu)))/(pi0*(pnorm(cl)+(1-pnorm(cu)))+(u1^2)*p1*( pnorm(cl-u1)+(1-pnorm(cu-u1)))+(u2^2)*(0.2-p1)*(pnorm(cl-u2)+(1-pnorm(cu-u2 ))))} f3star <- function(p1, cl, cu){ ((u1^2)*p1*(pnorm(cu-u1)-pnorm(cl-u1))+(u2^2)*(0.2-p1)*(pnorm(cu-u2)-pnorm( cl-u2)))/(pi0*(pnorm(cu)-pnorm(cl))+(u1^2)*p1*(pnorm(cu-u1)-pnorm(cl-u1))+( u2^2)*(0.2-p1)*(pnorm(cu-u2)-pnorm(cl-u2)))} p1 <- 0.1 lam <- seq(0.01,0.99, by=0.001) x1 <- numeric(length(lam)) x2 <- numeric(length(lam)) for (i in 1:length(lam)){ cl <- uniroot(f1star, lower = -10, upper = 0, tol = 1e-10,lambda=lam[i], p1=p1)$root cu <- uniroot(f1star, lower = 0, upper = 10, tol = 1e-10,lambda=lam[i], p1=p1)$root x1[i]<- f2star(p1=p1, cl=cl, cu=cu) x2[i]<- f3star(p1=p1, cl=cl, cu=cu)} [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.