# How to obtain individual slope coefficients for a growth curve model

I am trying to obtain individual slope coefficients in a growth curve model I am running on RStudio.

I'm using the lme4 package.

base <- lmer(X1 ~ Week + (Week | id),
data=Data)

beta <- coef(base)\$id
summary(beta)

When I run this code, instead of extracting individual slopes the 'beta' variable shows:
Length = 0, Class = Null, Mode = Null.

What am I doing incorrectly to not get the individual slope coefficients?

Is this what you are trying to do?
(just in case, I'm using iris dataset as example data)

``````library(lme4)
base <- lmer(Sepal.Length ~ Sepal.Width + (Sepal.Width | Species),
data=iris)
#> singular fit
summary(base)
#> Linear mixed model fit by REML ['lmerMod']
#> Formula: Sepal.Length ~ Sepal.Width + (Sepal.Width | Species)
#>    Data: iris
#>
#> REML criterion at convergence: 193.7
#>
#> Scaled residuals:
#>     Min      1Q  Median      3Q     Max
#> -2.8728 -0.5932 -0.0753  0.4327  3.3306
#>
#> Random effects:
#>  Groups   Name        Variance Std.Dev. Corr
#>  Species  (Intercept) 0.39789  0.6308
#>           Sepal.Width 0.01394  0.1181   1.00
#>  Residual             0.19074  0.4367
#> Number of obs: 150, groups:  Species, 3
#>
#> Fixed effects:
#>             Estimate Std. Error t value
#> (Intercept)   3.3805     0.4891   6.912
#> Sepal.Width   0.8129     0.1264   6.431
#>
#> Correlation of Fixed Effects:
#>             (Intr)
#> Sepal.Width -0.157
#> convergence code: 0
#> singular fit
base@beta
#> [1] 3.3804685 0.8129194
``````

Created on 2019-01-28 by the reprex package (v0.2.1)

Well yes and no. The first part of my code works well. I get the fixed and random effect coefficients for the group but I'm unable to get slope values for each individual participant in the sample.

It's hard to help you any further if you don't provide a reproducible example, we have no way to know the structure of your real data.

``````library(foreign)
library(dplyr)
#>
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#>
#>     filter, lag
#> The following objects are masked from 'package:base':
#>
#>     intersect, setdiff, setequal, union
library (lme4)
use.value.labels = TRUE, to.data.frame = TRUE, sep = "\t", dec = ".")
colSums (is.na(CBMY))
#>       sid      Time TestScore
#>         0         0        66
CBM <- na.omit(CBMY)
base <- lmer(CBM\$TestScore ~ 1 + CBM\$Time + (1 + CBM\$Time | CBM\$sid),
data=CBM, REML=FALSE)
#> singular fit
summary(base)
#> Linear mixed model fit by maximum likelihood  ['lmerMod']
#> Formula: CBM\$TestScore ~ 1 + CBM\$Time + (1 + CBM\$Time | CBM\$sid)
#>    Data: CBM
#>
#>      AIC      BIC   logLik deviance df.resid
#>   1317.9   1343.6   -652.9   1305.9      537
#>
#> Scaled residuals:
#>      Min       1Q   Median       3Q      Max
#> -3.07945 -0.61070 -0.01133  0.55039  2.83987
#>
#> Random effects:
#>  Groups   Name        Variance  Std.Dev. Corr
#>  CBM\$sid  (Intercept) 0.3029561 0.55041
#>           CBM\$Time    0.0004888 0.02211  1.00
#>  Residual             0.4911642 0.70083
#> Number of obs: 543, groups:  CBM\$sid, 80
#>
#> Fixed effects:
#>             Estimate Std. Error t value
#> (Intercept) -0.59942    0.09085  -6.598
#> CBM\$Time     0.15074    0.01542   9.776
#>
#> Correlation of Fixed Effects:
#>          (Intr)
#> CBM\$Time -0.538
#> convergence code: 0
#> singular fit
beta <- coef(base)\$sid
summary(beta)
#> Length  Class   Mode
#>      0   NULL   NULL
``````

Yes, here is a minimal example solution with just the first 20 rows of your data.

``````library(lme4)

CBM <- data.frame(
sid = c(210103, 210103, 210103, 210103, 210103, 210103, 210103,
210105, 210105, 210105, 210105, 210105, 210105, 210105,
210202, 210202, 210202, 210202, 210202, 210202),
Time = c(1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4, 5, 6),
TestScore = c(-1.45496720585195, -0.260188842483168, -1.45496720585195,
-1.75366179669414, -1.45496720585195, -0.857578024167559,
-1.45496720585195, -1.75366179669414, 0.337200339201222,
-0.857578024167559, -1.15627261500975, -0.558883433325363,
0.0385057483590271, -0.857578024167559, -0.857578024167559, 1.23328411172781,
-1.15627261500975, -1.45496720585195, -1.15627261500975,
0.635894930043418)
)
base <- lmer(CBM\$TestScore ~ 1 + CBM\$Time + (1 + CBM\$Time | CBM\$sid),
#> singular fit
coef(base)\$`CBM\$sid`\$`(Intercept)`
#> [1] -0.8681693 -0.8129559 -0.8007325
coef(base)\$`CBM\$sid`\$`CBM\$Time`
#> [1] -0.004295916  0.007774753  0.010447016
``````

Created on 2019-02-02 by the reprex package (v0.2.1)

Thank you so much for helping me fix this problem. I was able to obtain individual participants intercepts and slopes. For future reference, can you tell me why my initial individual slope output was "NULL"? Was it because I did not add `(Intercept)` and `CBM\$Time` to my code?

Yes, because those are the column names of the output

``````coef(base)
#> \$`CBM\$sid`
#>        (Intercept)     CBM\$Time
#> 210103  -0.8681693 -0.004295916
#> 210105  -0.8129559  0.007774753
#> 210202  -0.8007325  0.010447016
#>
#> attr(,"class")
#> [1] "coef.mer"
``````
1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.