[R] help optimize

Edward Bowora n.bowora at gmail.com
Fri Jul 1 10:16:25 CEST 2011


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



More information about the R-help mailing list