Issue: Do constrained optimization of parameters in nlme::nlme
I'm trying to fit a non-linear mixed effects model using nlme::nlme, which can use 2 optimization schemes: stats::nlminb or stats::nlm.
I want to do constrained optimization, so I choose to use nlminb. In the documentation of nlminb two arguments are needed in order to do so: upper = c(..), lower = c(..).
However, nlme passes only certain control values to nlminb and unfortunately the ones I need are not among them. Below is a small copy/paste from the nlme code, which shows the vector "keep", that defines what arguments to be passed to nlminb.
I would be grateful if someone could answer my questions:
- Is there a good workaround to this problem?
- Is there a reason why nlme does not want to have bounded optimization in their package? It seems intentionally left out.
Solutions found online:
I can see other people have this question as well and suggestions like transforming the parameters manually are given. But it would just be very nice if constrained optimization in nlminb could be used with the build in function, since it has the feature implemented... (http://blackwell.math.yorku.ca/georges/pub/lme/0102.html, https://stackoverflow.com/questions/11962492/limits-on-nlme-regression)
Sample from the nlme code line 573 - 583
if (controlvals$opt == "nlminb") {
control <- list(trace = controlvals$msVerbose, iter.max = controlvals$msMaxIter)
keep <- c("eval.max", "abs.tol", "rel.tol", "x.tol",
"xf.tol", "step.min", "step.max", "sing.tol",
"scale.init", "diff.g")
control <- c(control, controlvals[names(controlvals) %in%
keep])
optRes <- nlminb(c(coef(nlmeSt)), function(nlmePars) -logLik(nlmeSt,
nlmePars), control = control)
...