[R] Struggeling with nlminb...
MMar86
marcial.messmer at gmail.com
Sun Nov 4 16:31:23 CET 2012
Hallo together,
I am trying to estimate parameters by means of QMLE using the nlminb
optimizer for a tree-structured GARCH model. I face two problems.
First, the optimizer returns error[8] false convergence if I estimate the
functions below. I have estimated the model at first with nlm without any
problems, but then I needed to add some constraints so i choose nlminb.
my.loglike.normal<-function(theta){
x.start<- 1/n * sum(returns)
sigmasq.start<- 1/(n-1) * sum((returns-x.start)^2)
data<-c(x.start,returns)
my.sigmasq<- rep(0,n+1)
my.sigmasq[1]<-sigmasq.start
for (i in 2:(n+1)) {
my.sigmasq[i]<-(theta[1] + theta[2]*data[i-1]^2 +
theta[3]*my.sigmasq[i-1])*(data[i-1]<=d1)*(my.sigmasq[i-1]<=d2) +
(theta[4] + theta[5]*data[i-1]^2 +
theta[6]*my.sigmasq[i-1])*(my.sigmasq[i-1]>d2)*(data[i-1]<=d1)+ (theta[7] +
theta[8]*data[i-1]^2 +
theta[9]*my.sigmasq[i-1])*(data[i-1]>d1)*(my.sigmasq[i-1]<=d3)+(theta[10] +
theta[11]*data[i-1]^2 +
theta[12]*my.sigmasq[i-1])*(data[i-1]>d1)*(my.sigmasq[i-1]>d3)
}
my.mean<-rep(0,n+1)
for(j in 2:(n+1)) {
my.mean[j]<-theta[13]*data[j-1]
}
1/2*sum(log(my.sigmasq[2:(n+1)])) + n/2*log(2*pi) +
1/2*sum((data[2:(n+1)]-my.mean[2:(n+1)])^2/(my.sigmasq[2:(n+1)]))
}
constLow=c(rep(0,(length(par.start)-1)),-2)
my.optpar3<-
nlminb(par.start,my.loglike.normal,lower=constLow,control=list(eval.max=500,iter.max=100)
)
Second, I estimate a similar function but with only 7 instead of 13
parameters, I fix theta[1]-theta[6] to some constant, but vary d3 in a loop.
It seems like that the optimizer faces some NA/Inf issues for some d3.
for(j in (my.d1j+1):7){
cat(j,"\n")
d3 <- emp.quant[j]
constLo=c(rep(0.00001, (length(par.start)-1)), -999999)
my.optpar3 <- nlminb(par.start, my.loglike.normal, lower=constLo,
control=list(eval.max=60,iter.max=30))
value <- valore.normal(my.optpar3$par)
}
Thank you for your help!
Best,
Marcial
--
View this message in context: http://r.789695.n4.nabble.com/Struggeling-with-nlminb-tp4648413.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list