[R] Problem with optim()
Fernando Saldanha
fsaldan1 at gmail.com
Mon May 1 15:57:54 CEST 2006
I am having a problem with optim() using the "L-BFGS-B" method. When I
set the lower limit for the third parameter equal to zero I get an
error message:
> low.lim.3 <- 0
> phi_opt <- optim(phi_, model_lik, NULL, method = "L-BFGS-B", lower=c(0.2, -100, low.lim.3, 0), upper= c(10, 100, 10, 10), control = list(maxit = 1000, parscale = c(0.2, u1, 0.002, 0.002), trace = 0, REPORT = 3), hessian = FALSE)
Error in chol(M) : the leading minor of order 1 is not positive definite
However, setting that limit just above zero fixes things:
> low.lim.3 <- 0.001
> phi_opt <- optim(phi_, model_lik, NULL, method = "L-BFGS-B", lower=c(0.2, -100, low.lim.3, 0), upper= c(10, 100, 10, 10), control = list(maxit = 1000, parscale = c(0.2, u1, 0.002, 0.002), trace = 0, REPORT = 3), hessian = FALSE)
> cat("Optimal parameters:", phi_opt$par, "\n")
Optimal parameters: 0.3 0.005316 0.001280 0.0006127
> cat("Max likelihood:", -phi_opt$value, "\n\n")
Max likelihood: 1035
This does not seem to be happening because the function to be
optimized, which is minus the likelihood of a SS object (see package
SSPIR) is badly behaved:
> model.opt <- model
> phi(model.opt) <- phi_opt$par
> for(i in seq(0.0001, 0.0015, by = 0.0001)) {
+ phi(model.opt)[3] <- i
+ model.f <- kfilter(model.opt)
+ cat(i, model.f$likelihood, "\n")
+ }
1e-04 828.8
2e-04 888.2
3e-04 930.5
4e-04 961.1
5e-04 983.5
6e-04 1000
7e-04 1012
8e-04 1021
9e-04 1027
0.001 1031
0.0011 1034
0.0012 1035
0.0013 1035
0.0014 1035
0.0015 1033
>
This is in practice a problem as one has to manually tweak these
limits. Any insights on how to deal with this issue?
Thanks in aedvance.
Fernando Saldanha
More information about the R-help
mailing list