[R] optim

Savano savano at pegasusnet.com.br
Sun Nov 2 18:55:05 CET 2003


Friends,

I wrote a log-likelihood fuction and optimized but the optim function 
return a error.  The program and the error are below.

Can you help me?



  rm(list=ls(all=TRUE))
 >
 > duration<-read.table("C:/Documents and Settings/Savano/Meus 
documentos/Savano/PUC/estudo/NYSE/durationadj.txt",header=T,sep="");
 >
 > x <- duration$ibm;
 > psi <- array(NaN,c(length(x),1));
 >
 >     logexp <- function(omega,alpha,bbeta){
+
+                 (-sum(log(psi))+sum(x/psi)) #verossimilhança
+
+                 psi[1] <- omega/(1-bbeta)   #valor inicial de psi[1]
+
+                  for(i in 2:length(x)) {
+                     psi[i] <- omega+alpha*x+bbeta*psi[i-1] #calculo de psi
+                  }
+                  return(logexp)
+               }
 >
 >
 >
 > optim(c(0.1,0.2,0.3),logexp,method="BFGS")
Error in fn(par, ...) : Argument "bbeta" is missing, with no default
 >




More information about the R-help mailing list