I have a mixed-effects model and I want to drop some of my correlations in my random-effects covariance matrix to reduce my dof. To do this I think I should use pdBlocked
but can't get the correct syntax to get specifically what I want.
Example code:
library(nlme)
m3 <- lme(distance ~ age +I(age^2) + I(age^3), data = Orthodont,
random = list(Subject = pdBlocked(list(~ age,~0 + I(age^2),~0+I(age^3)))))
which gives the following covariance matrix:
getVarCov(m3)
Random effects variance covariance matrix
(Intercept) age I(age^2) I(age^3)
(Intercept) 5.2217 -0.30418 0.00000000000000 0.00000000000000000000000000
age -0.3042 0.04974 0.00000000000000 0.00000000000000000000000000
I(age^2) 0.0000 0.00000 0.00000000003593 0.00000000000000000000000000
I(age^3) 0.0000 0.00000 0.00000000000000 0.00000000000000000000002277
Standard Deviations: 2.285 0.223 0.000005994 0.000000000004772
This is close to what I want but not quite. I would like to keep the correlation between I(age^3)
and intercept
, age
zero but allow a correlation with I(age^2)
. Something like this:
getVarCov(m3)
Random effects variance covariance matrix
(Intercept) age I(age^2) I(age^3)
(Intercept) 5.2217 -0.30418 0.00000000000000 0.00000000000000000000000000
age -0.3042 0.04974 0.00000000000000 0.00000000000000000000000000
I(age^2) 0.0000 0.00000 0.00000000003593 a_value
I(age^3) 0.0000 0.00000 a_value 0.00000000000000000000002277
Standard Deviations: 2.285 0.223 0.000005994 0.000000000004772
also for this scenrio
getVarCov(m3)
Random effects variance covariance matrix
(Intercept) age I(age^2) I(age^3)
(Intercept) 5.2217 -0.30418 c_value b_value
age -0.3042 0.04974 d_value 0.00000000000000000000000000
I(age^2) c_value d_value 0.00000000003593 a_value
I(age^3) b_value 0.00000 a_value 0.00000000000000000000002277
Standard Deviations: 2.285 0.223 0.000005994 0.000000000004772
I'm just not sure how to make a flexible covariance matrix to able to pick which ones are zero. These links were very helpful but still cant figure it out exactly http://rpsychologist.com/r-guide-longitudinal-lme-lmer
Any help appreciated. Thanks