Forum: open-discussion
Monitor Forum | Start New ThreadRE: maxLik [ Reply ] By: Arne Henningsen on 2011-06-22 23:16 | [forum:4610] |
Please note that the name of the first argument of maxLik() is not "loglik" but "logLik" (with a capital "L") . Alternatively, you could just omit the name of this argument: maxLik( dume, grad=llgarad, start=param, method='BHHH') Please note further that the gradient function returns some NAs at the initial values: llgarad(param) |
maxLik [ Reply ] By: Uchennaya Nduka on 2011-06-22 14:45 | [forum:4609] |
I have written codes using maxLik() and I tried running the codes but it returns an error saying 'Error in is.function(func), func is missing. I don't know what to do. Who can come to my rescue? The code: library('maxLik') y<-c(0.2,3.53,2.34,4.35,9.73,4.96,7.32,6.89,8,10,0.35,1.4,0.71,0.1,1.76,0.95,6.6,10.3,5.11,5.9,9.63,.61, 0,0.06,0.05,0.06,3.3,7.6,7.72,15.9,2.8,5.92,11.7,8.4,0.49,0,0.05,0.06,3.3,7.6,7.7, 15.9,2.8,5.92,11.7,8.4,0.49,0,0,0.78,1.82,2.45,10.1,7.37,7.37,10.2,19.1,5.7,2.4, 0,0.13,0.05,0.99,2.76,6.27,7.06,8.72,5.99,12.7,9.3,0,0,0.87,1.84,0.6,3.73,10.1,6.97, 8.55,2.97,7.03,6.76,0,0,0,0,0.12,0.1,6,3.26,8.1,2.97,8,0.78,0,0.08,0,0,0.51,4.4, 4.21,11.3,9.85,12.4,9.98,3.95,0.67,0,0.53,0,6.64,4.12,9.4,6.54,6.24,14.9,10.8,5.07,.4, 0,0.06,0.31,4.1,3.15,7.7,4.57,8.72,6.41,6.65,3.27,1.8,0,0,0,1.06,2.63,7.12,6.46,7.9, 9.42,7.18,4.37,0,0,0.22,0,1.49,3.07,4.99,7.1,7.07,7.3,9.2,6.64,0,0,0,0,0.14,5.41,8.7) dume <-function(param){ a0<-param[1] a1<-param[2] a2<-param[3] a3<-param[4] a4<-param[5] a5<-param[6] a6<-param[7] a7<-param[8] a8<-param[9] a9<-param[10] ll<-(-n/2*log(a9^2)-0.5*a9^2*sum(a[t]^2)) ll } llgarad <-function(param){ a0<-param[1] a1<-param[2] a2<-param[3] a3<-param[4] a4<-param[5] a5<-param[6] a6<-param[7] a7<-param[8] a8<-param[9] a9<-param[10] gradv<-(cbind((-1/2*a9+a^2[t]/2*a9^2),(a[t]/a9),(a[t]/a9*cos(2*pi/n*t)),(a[t]/a9*sin(2*pi/n*t)), (a[t]/a9*cos(4*pi/n*t)),(a[t]/a9*sin(4*pi/n*t)),(-a[t]*a[t-1]/a9),(-a[t]*a[t-2]/a9), (a[t]*e[t-1]/a9),(a[t]*e[t-2]/a9))) return(gradv) } n<- length(y) a<- numeric(n) e<- numeric(n) a0<-param[1] a1<-param[2] a2<-param[3] a3<-param[4] a4<-param[5] a5<-param[6] a6<-param[7] a7<-param[8] a8<-param[9] a9<-param[10] t<-3:n e[t]<-y[t]-a0-a1*cos(2*pi/n*t)-a2*sin(2*pi/n*t)-a3*cos(4*pi/n*t)-a4*sin(4*pi/n*t) a[t]<-y[t]-a0-a1*cos(2*pi/n*t)-a2*sin(2*pi/n*t)-a3*cos(4*pi/n*t)-a4*sin(4*pi/n*t)+a5*a[t-1]+a6*a[t-2]-a7*e[t-1]-a8*e[t-2] mle<- maxLik(loglik=dume,grad=llgarad,start=param,method='BHHH') summary(mle) param<-c(0.1,0.3,0.4,0.5,0.1,0.3,0.5,0.1,0.2,0.3) |