[R] maximum likelihood using nlm to estimate 4 variables

Edward Bowora n.bowora at gmail.com
Tue Jun 28 03:56:17 CEST 2011


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



More information about the R-help mailing list