0

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()

unk
  • 1
  • 1

1 Answers1

0

The reason this is so hard (in both nlme::lme and lme4::lmer) is that the fixed-effect parameters are profiled out, meaning that the negative log-likelihood function we are optimizing is not an explicit function of the fixed-effect parameters (see Pinheiro and Bates 2000 for the mathy details for lme, vignette("lmer", package = "lme4") [== Bates et al. J. Stat. Software 2015] for the details of lmer). The optimization uses only the parameters that determine the random-effects covariance matrix.

It's easier to achieve this goal:

  • for GLMMs (e.g. in lme4::glmer), where the fixed-effect parameters are not profiled out (unless you use the setting nAGQ=0)
  • in glmmTMB, which uses a generic maximum likelihood engine

This document shows how to fit fixed-effect constraints on GLMMs using glmer, and attempts to do the same for LMMs (but it's not fully worked out/debugged/functional)

This question asks how to constrain a fixed-effect parameter to a fixed value

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453