help optimize

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

help optimize

EdBo
Hi

I need help figure out how to fix my code.

When I call into R
>optimize(llik,init.params=F)
 I get this error message
####Error in optimize(llik, init.params = F) : element 1 is empty;
  the part of the args list of 'min' being evaluated was:
  (interval)####


My data and my code looks like below.


R_j             R_m
0.002           0.026567296
0.01            0.003194435
.               .
.               .
.               .
.               .
0.0006  0.010281122

a=read.table("D:/ff.txt",header=T)
attach(a)
llik=function(R_j,R_m)
#The parameters al_j, au_j, b_j ,
and sigma_j need to be estimated and there are no initial estimates to
them.
if(R_j< 0)
{
 LF=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)
{
 LF=sum[log(1/(2*pi*(sigma_j^2)))-(1/(2*(sigma_j^2))*(R_j+au_j-b_j*R_m))^2]
}else
{
 LF=sum[(log(pnorm((au_j-b_j*R_m)/sigma_j)-pnorm((al_j-b_j*R_m)/sigma_j)))]
}
optimize(llik,init.params=F)
Error in optimize(llik, init.params = F) : element 1 is empty;
  the part of the args list of 'min' being evaluated was:
  (interval)

Thank you

Edward

______________________________________________
[hidden email] 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.