Hi, Am not sure if my code itself is correct. Here's what am trying to do: Minimize integration of a function of gaussian distributed variable 'x' over the interval qnorm(0.999) to Inf by changing value of parameter 'mu'. mu is the shift in mean of 'x'.
Code: # x follows gaussian distribution # fx2 to be minimized by changing values of mu # integration to be done over the interval (qnorm(0.999),Inf) p<-0.009 #constant R<-0.25 # constant e<-11 #constant integrand<-function(x){ (e*pnorm((qnorm(p)+sqrt(R)*x)/sqrt(1-R))*dnorm(x))^2/dnorm(x+mu)} fx2<-function(mu) { integrate(integrand, lower = qnorm(0.999), upper=Inf)$value} mu<-c(-1) #initial value for mu, which needs to be optimized such that fx2 is minimized output<-optim(par=mu, fx2, method="BFGS") I get the following error message: Error in integrate(integrand, lower = qnorm(0.999), upper = Inf) : non-finite function value If upper is changed to 10, error doesn't appear. However, mu retains its value and is not optimized. Pls. help. Thanks Dinesh -- View this message in context: http://r.789695.n4.nabble.com/Error-in-minimizing-an-integrand-using-optim-tp3561226p3561226.html Sent from the R help mailing list archive at Nabble.com. ______________________________________________ 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.