I am trying to create a linear mixed model for longitudinal data using data that looks similar as the data in the following:
> head(df, 10)
ID S A BT AT outcome Time
1 1 0 0.40 0 5 90 4
2 1 0 0.40 0 5 90 6
3 1 0 0.40 0 5 90 7
4 1 0 0.40 0 5 90 11
5 2 0 1.32 0 7 90 5
6 2 0 1.32 0 7 90 7
7 2 0 1.32 0 7 90 11
8 3 1 5.78 0 3 85 0
9 3 1 5.78 0 3 85 2
10 4 1 5.98 1 3 58 2
The data is unbalanced in the sense that a different number of observations exists for each subject with irregular time intervals. Unfortunately, with the data as specified in the former, a model with random slopes (or other more complex random structures) does not converge, however I added the data for illustration of the real data, since the real data looks similar.
When trying to fit a model using nlme::lme()
with e.g. random intercepts and slopes, a correlation structure and a variance function on the real data, the weights
argument is ignored and summary
returns the model without taking into account the variance function.
An example:
#(1)
model_lme <- lme((outcome ~ S + BT + A + AT*Time, random = ~ 1 + Time|ID,
method = "REML", data = df, na.action = na.exclude,
weights = varIdent(form = ~AT),
correlation = corCAR1(form = ~ 1 | ID),
control = lmeControl(opt = "optim")
)
gives the exact same results as:
#(2)
model_lme <- lme((outcome ~ S + BT + A + AT*Time, random = ~ 1 + Time|ID,
method = "REML", data = df, na.action = na.exclude,
correlation = corCAR1(form = ~ 1 | ID),
control = lmeControl(opt = "optim")
)
This happens only for VarIdent
, since the model does not seem to ignore e.g. VarExp
when using weights = ...
.
However, when specifying no weights
and no correlation, e.g.
#(3)
model_lme <- lme((outcome ~ S + BT + A + AT*Time, random = ~ 1 + Time|ID,
method = "REML", data = df, na.action = na.exclude,
varIdent(form = ~AT),
control = lmeControl(opt = "optim")
)
the model runs for much longer, has lower AIC in my case than the models without this specification of the variance function, and explicitly returns
Variance function:
Structure: Different standard deviations per stratum
Formula: ~AT | ID
# Followed by parameter estimates for each unique ID, one value per ID.
in the summary output.
What happens in model #(3), happens not only for VarIdent
, but for all of the variance functions, so I am assuming that I am misspecifying something here.
Therefore, I would like to check whether I understand correctly what I am trying to specify:
When using model #(3), the summary output gives me Formula: ~AT | ID
, which to me would indicate that for each value of AT (which is continuous), grouped by ID (since it is the within-group variance), a different residual variance is estimated. For VarExp
, this would result in Formula: ~AT
, indicating that the variance of the residuals increases exponentially for the values of the covariate AT (regardless of the grouping?).
Therefore, I have two questions: (1) Am I understanding the meaning of the variance functions correctly, and (2) What could be happening with the model specification that it takes so long to run in model 3 (also with e.g. VarExp
), and the variance function VarIdent
is ignored when using weights = ...
?
varIdent
gets ignored. I'm also experiencing that and other "ignoring" issues involving varFunc and corStruct calls in the nlme package and would love an explanation. $\endgroup$