Currently I want to fit a mixed effects model with positive or negative constraints on the parameters.
For parameter estimation using Joint Modeling, we use nlme package, which is required by the JM package.
In the lme function of the nlme package, it seems that optimization details can be specified by using lmeControl().
https://stat.ethz.ch/R-manual/R-devel/library/nlme/html/lmeControl.html
In "L-BFGS-B" using the optim function described as an option here,
It looks like we can specify the maximum and minimum values of the estimated parameters.
https://stat.ethz.ch/R-manual/R-devel/library/stats/html/optim.html
However, only "optim" or "nlminb" as character can be specified with lmeControl(),
It doesn't look like I can write an optimization function by reading the source code.
https://github.com/cran/nlme/blob/master/R/lme.R
Is it possible to create a parameter constrained mixed effects model using the nlme package?
Thank you.
memo:
Specifying upper and lower options to the lme and lmeCntrol functions was not effective.
Also giving the lmeCntrol function an optimization function didn't work.
(Maybe I could not write the funciton properly.)
require(JM)
require(nlme)
require(tidyverse)
data(aids)
data(aids.id)
#fit mixed effect model
fitLME <- lme(sqrt(CD4) ~ obstime + obstime:drug, random = ~ obstime | patient, data = aids, )
fitLME %>% summary()
#create lme control.
ctrl <- lmeControl(optimMethod = "L-BFGS-B", opt ="optim", lower = c(0,0, 0), upper = c(1,20,1))
#fit with lme control
fitLME_ctrl <- lme(sqrt(CD4) ~ obstime + obstime:drug, random = ~ obstime | patient, data = aids, control = ctrl)
#this does not change result.
fitLME_ctrl %>% summary()