[R] Optimization and simulation

From: Jin Huang <crystal_huangjin_at_yahoo.com.cn>
Date: Wed 04 Apr 2007 - 01:30:25 GMT

Dear all,    

  I would need to maximize a self-defined 'target' function(see below) with respect to theta, where v follows a log-normal distribution with mean 'mu(x)' and a constant variance. For each v drawn from its distribution, one maximized value and optimal theta are produced. I'd like to do this repeatedly and store the maximized value and corresponding theta. I wrote the following code that can produce a result. But the problem is that the result doesn't seem to be the optimized one because if I arbitrarily choose theta=c(4,27), I will get much bigger value than those simulated ones. I am not sure where is wrong. Could anyone help me with this? Thank you in advance! Here is the code:    

  for (i in 1:10){
  #Define the target function
  mu<-function(x,d=d0,ta=23.86,ti=11.067,ppt=1.321,a=-12.31, S=5.62, L=3.83, b=c(0.338,-0.0055,0.113,-0.00466,-0.008,-0.205,-0.044,0.266,1.719,-0.169)){ return(a+sum(b*c(x,x^2,d,d^2,S,L,ta,ti,ppt,ti*ppt)))}


if(8.179+0.00023*(5.29+0.16*x-0.21*d)^5>45){return(45)} return(8.179+0.00023*(5.29+0.16*x-0.21*d)^5)



rdt[i,2:3]<-result$par }       

        [[alternative HTML version deleted]]

R-help@stat.math.ethz.ch 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. Received on Wed Apr 04 11:40:34 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Wed 04 Apr 2007 - 04:30:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.