Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

multiple random effects in nlme

Tags:

random

r

nlme

I need to include one more random effect in my lme model. However, these 2 random effects are not related, therefore cannot be nested.

I am not sure how to write the code for this. I've tried the following:

modelA <- lme(FT~ Init.Age + Sex + Status, random= (1|Patient) + (1|Site), data = data, na.action = na.omit)

modelB <- lme(FT~ Init.Age + Sex + Status, random= list (~1|Patient, ~1|Site), data = data, na.action = na.omit)

only model B works. But it gives me exactly the same results as random= ~1|Patient and I think that cannot be correct. The results are the following: enter image description here

Thanks for your help! lil

like image 749
Lili Avatar asked Mar 27 '26 17:03

Lili


1 Answers

This is a popular learning opportunity on nlme that assumes nested random effects intrinsically. To specify crossed random intercepts by two factors, we need

lme(FT ~ Init.Age + Sex + Status, random = list(one = pdBlocked(
  pdIdent(~ 0 + Patient), pdIdent(~ 0 + Site))), 
  data = data |> transform(one = factor(1)))

Note that we must code both Patient and Site as factors instead of numeric integers. See more details at How to specify correlated crossed random effects in nlme? and https://stats.stackexchange.com/questions/274777/modelling-random-structure-in-lmer-and-nlmelme/613085.

Crossed random effects are only necessary if a large portion of patients each visit both sites. If a patient visits only one of the two sites, then nested structure should be used.

If Site has only two categories, I do not think it is appropriate to treat Site as random effects, either crossed or nested. You should try fixed effects of site by adding it as a regular predictor. The mean difference between two sites might be important, and you can interact Site with other predictors to see whether effects of age, age squared, sex, and status vary by Site. For example,

lme(FT ~ (Init.Age + I(Init.Age^2) + Sex + Status) * Site, 
  random = ~ 1 | Patient, 
  data = data)

You may also want to center age and any continuous variables to have mean zero, otherwise the algorithm may have difficulty in convergence.

like image 179
DrJerryTAO Avatar answered Mar 31 '26 07:03

DrJerryTAO



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!