# Hint improve my code

3 messages
Open this post in threaded view
|

## Hint improve my code

 Hi I have developed the code below. I am worried that the parameters I want to be estimated are "not being found" when I ran my code. Is there a way I can code them so that R recognize that they should be estimated. This is the error I am getting. > out1=optim(llik,par=start.par) Error in pnorm(au_j, mean = b_j * R_m, sd = sigma_j) :   object 'au_j' not found #Yet al_j,au_j,sigma_j and b_j are just estimates that balance the likelihood function? llik=function(R_j,R_m) if(R_j< 0) { sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+al_j-b_j*R_m))^2] }else if(R_j>0) { sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2] }else if(R_j==0) { sum(log(pnorm(au_j,mean=b_j*R_m,sd=sigma_j)-pnorm(al_j,mean=b_j*R_m,sd=sigma_j))) } start.par=c(al_j=0,au_j=0,sigma_j=0.01,b_j=1) out1=optim(par=start.par,llik) My Data      R_j         R_m   2e-03   0.026567295   3e-03   0.009798475   5e-02   0.008497274  -1e-02   0.012464578  -9e-04   0.002896023   9e-02   0.000879473   1e-02   0.003194435   6e-04   0.010281122 Thank you in advance. Edward UCT