Hi I need help I am new to R and am having problems estimating parameters out of 3stage constrained function. I have constructed a code as below and my data are two colomns of R_j and R_m(sample given below). R_j and R_m represents the dependent and independent variables respectively. The parameters al_j, au_j, b_j , and sigma_j need to be estimate and there are no initial estimates to them llik=function(R_j,R_m) { LF=if(R_j< 0)sum[ln(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+al_j-b_j*R_m))^2] + if(R_j> 0)sum[ln(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2] + if(R_j==0)sum[(ln(%pnorm((au_j-b_j*R_m)/sigma_j)-%pnorm((al_j-b_j*R_m)/sigma_j)))] } est.nlm = nlm(llik,0) #not sure what to put for the 4 initial estimates so I just put 0 est.nlm$estimate Sample Data R_j R_m 0.002 0.026567295 0.003 -0.009798475 0.05 0.008497274 -0.01 0.012464578 -0.0009 0.002896023 0.09 0.000879473 0.01 -0.003194435 0.0006 0.010281122 I will appreciate if you help me to modify my code to get my estimates or give me any better method to use. Thank you in advance Edward Student: Institute of Actuaries -- View this message in context: http://r.789695.n4.nabble.com/maximum-likelihood-using-nlm-to-estimate-4-variables-tp3629290p3629290.html Sent from the R help mailing list archive at Nabble.com.
Edward Bowora
2011-Jun-28 01:56 UTC
[R] maximum likelihood using nlm to estimate 4 variables
Hi I need help I am new to R and am having problems estimating parameters out of 3stage constrained function. I have constructed a code as below and my data are two colomns of R_j and R_m(sample given below). R_j and R_m represents the dependent and independent variables respectively. The parameters al_j, au_j, b_j , and sigma_j need to be estimate and there are no initial estimates to them llik=function(R_j,R_m) { LF=if(R_j< 0)sum[ln(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+al_j-b_j*R_m))^2] + if(R_j> 0)sum[ln(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2] + if(R_j==0)sum[(ln(%pnorm((au_j-b_j*R_m)/sigma_j)-%pnorm((al_j-b_j*R_m)/sigma_j)))] } est.nlm = nlm(llik,0) #not sure what to put for the 4 initial estimates so I just put 0 est.nlm$estimate Sample Data R_j R_m 0.002 0.026567295 0.003 0.009798475 0.05 0.008497274 -0.01 0.012464578 -0.0009 0.002896023 0.09 0.000879473 0.01 0.003194435 0.0006 0.010281122 I will appreciate if you help me to modify my code to get my estimates or give me any better method to use. Thank you in advance Edward Student: Institute of Actuaries