I'm new to R and to multilevel modeling. I have a data set where I have a dependent variable y and predictor x, both of which are measured one time per day over a number of days within subjects. In addition, each subject is part of a twin pair. So in terms of my nesting structure, I have my measurements, nested within subject, nested within family (FamID). I expect my measurement values to be correlated over days within subjects, so I would like to specify an autocorrelation structure of order 1. Below is how I am specifying my model:
m1 <- lme(y ~ x,
random = list(~1 + Subject | FamID, ~1 + x | Subject),
data = dataset, method="ML",
correlation=corAR1(,form=~1|Subject),
na.action="na.omit")
However, I receive the error message,
incompatible formulas for groups in 'random' and 'correlation'
Might anyone be able to help me appropriately specify this model?
As @Roland says, the correlation and random effects formulas must match. See below ...
Simulate data:
Notes:
1|FamID/Subjectspecifies "Subject nested within FamID", which sounds like what you described. Your current random effect specificationlist(~1 + Subject | FamID, ~1 + x | Subject)makes little sense to me: this would indicate(the simpler
1|FamID/Subjectspecification does imply correlation between subjects, through the shared family effect; however, this correlation must be ≥ 0, unlike the1 + Subject | FamIDspecification. The1 + Subject | FamID` specification is also a little bit weird because it implies that the twins in a family are non-exchangeable, i.e. 'twin 1' and 'twin 2' would be specified in some way ...)This is most likely overparameterized/unidentifiable (if you do want a random-slopes model allowing for the variation in the effects of
xacross subjects and/or families you can userandom = ~1+x|FamID/Subjectto estimate slopes at both levels — I checked, and this does still work with thecorrelationargument. I don't know if it's possible to specify random slopes at only one level (e.g. across subjects but not families) inlme...corAR1(form = ~1|FamID/Subject)seems as though it might specify two autocorrelation parameters (at the levels of both family and subject-within-family), but according to the output (below) only one is estimated.(Note that the random effects estimated are vanishingly small because I used made-up data with no structure.)