I'm working on a longitudinal analysis using the nlme package in R, where I'm modeling the effect of treatment (tx) and menopausal status (menscat) on a biomarker level that tested at two visits: V00 and V30. Also, in my research question, I care about the change of biomarker at two visits, which may be affected by both treatment (tx) and menopausal status (menscat). The biomarker levels are normally distributed.
My model currently includes visit both as a fixed effect and a random effect (random slope), as shown below:
# Simulate the data
set.seed(123)
n <- 100 # Number of subjects
data <- data.frame(
id = rep(1:n, each = 2),
visit = factor(rep(c("V00", "V36"), n)),
tx = factor(rep(c("Placebo", "Active"), each = n)),
menscat = factor(rep(1:2, each = n)),
biomarker = rnorm(2 * n, mean = 50, sd = 10)
)
# Model with visit as both fixed and random effects
model <- lme(
fixed = biomarker ~ tx * visit + menscat * visit,
random = ~ visit | id,
data = data,
method = "REML"
)
summary(model)
My questions are:
- Is it statistically appropriate to include visit as both a fixed effect and a random effect?
- What are the implications of this model structure? Specifically, how does having visit in both the fixed and random parts of the model affect the interpretation?
- Are there any potential issues (e.g., identifiability, multicollinearity) with this approach that I should be aware of?
id
. Since you don't have that, you can't includevisit
in the random effects. The parameters are unidentifiable, which is whylme
complains about "Singularity in backsolve at level 0, block 1". $\endgroup$