# Random slope and random intercept correlation at every level of X

Lets say individuals are nested within each ID and I am trying to a predict level 1 outcome Y from a level 1 predictor X1 or X2 with random slopes and intercepts. X1 and X2 are equivalent to each other except that they have a different mean. Using the nlme package in R, I ran the following:

> library(nlme)
> set.seed(123)
> Y=rnorm(100)+seq(.01,1,.01)
> X1=rep(1:10,10)
> X2=X1-10
> ID=sort(rep(1:10,10))
> Model1=lme(method="ML",Y~X1,random=~X1|ID)
> Model2=lme(method="ML",Y~X2,random=~X2|ID)
> Model1
Linear mixed-effects model fit by maximum likelihood
Data: NULL
Log-likelihood: -136.9366
Fixed: Y ~ X1
(Intercept)          X1
0.45724997  0.02511926

Random effects:
Formula: ~X1 | ID
Structure: General positive-definite, Log-Cholesky parametrization
StdDev     Corr
(Intercept) 0.42405364 (Intr)
X1          0.01936927 -0.87
Residual    0.91060089

Number of Observations: 100
Number of Groups: 10
> Model2
Linear mixed-effects model fit by maximum likelihood
Data: NULL
Log-likelihood: -136.9366
Fixed: Y ~ X2
(Intercept)          X2
0.70844259  0.02511926

Random effects:
Formula: ~X2 | ID
Structure: General positive-definite, Log-Cholesky parametrization
StdDev     Corr
(Intercept) 0.27279076 (Intr)
X2          0.01932177 -0.645
Residual    0.91060680

Number of Observations: 100
Number of Groups: 10


As shown, the fixed effects slope for X1 and X2 are the same, but the fixed effect intercepts are different. The random slope and intercept correlation differs depending on the mean of X. The correlations are being calculated at the point were X=0.

Question: Is there a way to calculate the correlation at every point of X without running the model multiple times? Seems like it would be a useful technique.

• Maybe I'm missing something, but this one should become a non-issue if you scale and center your continuous predictors, e.g. Model1 <- lme(method = "ML", Y ~ scale(X1), random = ~scale(X1)|ID) (same with Model2). Then the models are identical, except for variable names. May 22, 2015 at 18:53
• Can you please elaborate on what you are trying to achieve? What do you mean by saying "* at every point of X*" and how does that relate to what you are showing in the attached code? May 27, 2015 at 8:46