I have a multilevel model based on data from weekly observations nested in persons. The cluster ist id. We measured fatigue several times. I expect that there may be a trend over time, i.e. persons should differ in their slopes. Hence, I specified a random intercept random slope model:
model <- lmer(fatigue ~ 1 + time + (1 + time|id),data = dataframe, na.action = na.omit) summary(model)
The coef-command does provide the estimated/calculated intercepts and slopes for each person/cluster/id. The output looks like this. Obviously the number in the first column refers to the id
> coef(model)$id (Intercept) time 2 2.730255 -0.0030445718 3 3.109098 0.0029101983 4 1.526722 -0.0219620556 5 2.662696 -0.0041064863 11 2.640430 -0.0044564646 12 3.560910 0.0100119139 13 2.698792 -0.0035391108 View(coef(model)$id[,"(Intercept)"]) View(coef(model)$id[,"time"])
Extracting either intercepts or slopes seperately as vectors works fine.
I would now like to use the individual (id-specific) intercepts and slopes from the output as Level-2-variables (e.g. as covariates or cross-level moderators) of growth in just another criterion/dependent variable. That is, I need to have a data.frame containing: 1. id 2. Intercept 3. Slope
Whenever I try to extract the contents of the output, I do not succeed capturing the information from the first column (obviously the id). Working with the Intercept and Slope vector is fine. However R doesn't treat the first column as a vector/variable. So it is not possible to match intercepts and slopes to a Level-2-dataset containing other covariates like tenure or age.
Is someone aware of ways how to manage an export of the full output including the id column? I'd appreciate any hint. Thanks in advance.