Re: [R] Struggeling with nlminb...

2012-11-05 Thread Ravi Varadhan
Try optimx() in the "optimx" package with the control option  
`all.methods=TRUE'.

Ravi

Ravi Varadhan, Ph.D.
Assistant Professor
The Center on Aging and Health
Division of Geriatric Medicine & Gerontology
Johns Hopkins University
rvarad...@jhmi.edu
410-502-2619


[[alternative HTML version deleted]]

__
R-help@r-project.org 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.


[R] Struggeling with nlminb...

2012-11-04 Thread MMar86
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.1, (length(par.start)-1)), -99)
  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.

__
R-help@r-project.org 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.