# [R-sig-ME] Latent variable regression in lme4 as in HLM

Uanhoro, James u@nhoro@1 @end|ng |rom buckeyem@||@o@u@edu
Wed May 27 01:12:01 CEST 2020

```Hello Simon,

I'm not sure what HLM does. However: if your question is about using
the random intercepts (individuals' starting points) to predict the
random slopes (their linear growth rate), then the model you need is:

summary(m2 <- lmer(y ~ year + (1 + year | stid), dat))

whcih returns the random intercept and a random slope on time.

The correlation between both random effects is the regression
coefficient from regressing the slope on the intercept (or vice-versa)
when both variables are standardized.

More generally, you can always obtain regression coefficients from a
correlation/covariance matrix of random effects. With a two-by-two
correlation matrix, the single correlation is the coefficient (in both
directions). In a larger matrix of random effects, you can use the
solve() function in R to obtain coefficients from the matrix. See here:
https://stackoverflow.com/questions/40762865/how-do-i-get-regression-
coefficients-from-a-variance-covariance-matrix-in-r

I tried your exact example, and m2 above will not fit because some of
your participants have under 2 time points while the maximum number of
time points is 3, resulting in a situation where the software is
attempting to compute more random effect values than there are rows in
the data - the software complains. Also, it is a good idea to rescale
that y variable prior to data analysis. I was able to get the model to
run by limiting the data to cases with more than 1 recorded time point:

summary(m3 <- lmer(y.s ~ year + (1 + year | stid), data = t.dat, subset
= n > 1))

I arrived at a correlation/coefficient of -0.06.

Hope this helps, -James.

Sent from Outlook Mobile

From: R-sig-mixed-models <r-sig-mixed-models-bounces using r-project.org> on
behalf of Simon Harmel <sim.harmel using gmail.com>
Sent: Tuesday, May 26, 2020, 18:27
To: r-sig-mixed-models
Subject: [R-sig-ME] Latent variable regression in lme4 as in HLM

Dear All,

I know that in the HLM software, it is possible to use "intercept"
(e.g.,
initial place of students at year "0") as the *predictor *of "slope"
(e.g.,
fixed rate of change in years) under the *Latent Variable Regression
*tab.

I was wondering if this is also possible in "lme4" or any other
mixed-modeling packages in R?  *Thanks, Simon*

*## Here is an example dataset for demonstration:*
library(lme4)
https://urldefense.com/v3/__https://raw.githubusercontent.com/hkil/m/master/z.csv__;!!KGKeukY!gjIgidLro6PaJJUHZOY1gk9IW8FfrzGWzo9IEaCRgFwkorvpE1tkLXqn3ujcsmy6OvxsB2xlUIM\$
')
m1 <- lmer(y ~ year + (1|stid), data = dat)      #### 'stid' = student
id

[[alternative HTML version deleted]]

_______________________________________________
R-sig-mixed-models using r-project.org mailing list

https://urldefense.com/v3/__https://stat.ethz.ch/mailman/listinfo/r-sig-mixed-models__;!!KGKeukY!gjIgidLro6PaJJUHZOY1gk9IW8FfrzGWzo9IEaCRgFwkorvpE1tkLXqn3ujcsmy6Ovxs517Hn00\$

```