[R] Error in minimizing an integrand using optim

ch_dinesh dinesh.chaudhary at gmail.com
Mon May 30 19:30:46 CEST 2011


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.



More information about the R-help mailing list