Skip to content

Commit b03aec0

Browse files
20250717 - reorganization and placeholders
1 parent dcb9cfa commit b03aec0

File tree

2 files changed

+70
-66
lines changed

2 files changed

+70
-66
lines changed

hlm.Rmd

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ The following models are models that are fit in a linear mixed modeling framewor
9595

9696
## Growth Curve Models {#gcm}
9797

98-
### Plot Observed Growth Curves
98+
### Linear Growth Curve Model {#linearGCM}
99+
100+
#### Plot Observed Growth Curves
99101

100102
```{r}
101103
ggplot(
@@ -111,7 +113,7 @@ ggplot(
111113
name = "Math Score")
112114
```
113115

114-
### `lme4`
116+
#### `lme4`
115117

116118
```{r}
117119
linearMixedModel <- lmer(
@@ -124,7 +126,7 @@ linearMixedModel <- lmer(
124126
summary(linearMixedModel)
125127
```
126128

127-
#### Protoypical Growth Curve
129+
##### Protoypical Growth Curve
128130

129131
```{r}
130132
newData <- expand.grid(
@@ -155,7 +157,7 @@ ggplot(
155157
geom_line()
156158
```
157159

158-
#### Individuals' Growth Curves
160+
##### Individuals' Growth Curves
159161

160162
```{r}
161163
mydata$predictedValue <- predict(
@@ -172,7 +174,7 @@ ggplot(
172174
geom_line()
173175
```
174176

175-
#### Individuals' Trajectories Overlaid with Prototypical Trajectory
177+
##### Individuals' Trajectories Overlaid with Prototypical Trajectory
176178

177179
```{r}
178180
ggplot(
@@ -187,13 +189,13 @@ ggplot(
187189
linewidth = 2)
188190
```
189191

190-
#### Extract Random Effects {#extractRandomEffects}
192+
##### Extract Random Effects {#extractRandomEffects}
191193

192194
```{r}
193195
ranef(linearMixedModel)
194196
```
195197

196-
### `nlme`
198+
#### `nlme`
197199

198200
```{r}
199201
linearMixedModel_nlme <- lme(
@@ -206,13 +208,17 @@ linearMixedModel_nlme <- lme(
206208
summary(linearMixedModel_nlme)
207209
```
208210

209-
## Intraclass Correlation Coefficent {#icc}
211+
#### Intraclass Correlation Coefficent {#icc}
210212

211213
```{r}
212214
icc(linearMixedModel)
213215
icc(linearMixedModel_nlme)
214216
```
215217

218+
### Quadratic Growth Curve Model {#quadraticGCM}
219+
220+
### Spline Growth Curve Model {#splineGCM}
221+
216222
# Generalized Linear Mixed Models {#generalized}
217223

218224
https://bbolker.github.io/mixedmodels-misc/glmmFAQ.html (archived at https://perma.cc/9RFS-BCE7; source code: https://github.com/bbolker/mixedmodels-misc/blob/master/glmmFAQ.rmd)

sem.Rmd

Lines changed: 56 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ ggplot(
102102

103103
# Latent Growth Curve Model {#lgcm}
104104

105-
## Model Syntax
105+
## Linear Model {#linearLGCM}
106106

107-
### Abbreviated
107+
### Model Syntax
108+
109+
#### Abbreviated
108110

109111
```{r}
110112
lgcm1_syntax <- '
@@ -124,7 +126,7 @@ lgcm1_syntax <- '
124126
'
125127
```
126128

127-
### Full
129+
#### Full
128130

129131
```{r}
130132
lgcm2_syntax <- '
@@ -154,9 +156,9 @@ lgcm2_syntax <- '
154156
'
155157
```
156158

157-
## Fit the Model
159+
### Fit the Model
158160

159-
### Abbreviated
161+
#### Abbreviated
160162

161163
```{r}
162164
lgcm1_fit <- growth(
@@ -171,7 +173,7 @@ lgcm1_fit <- growth(
171173
em.h1.iter.max = 100000)
172174
```
173175

174-
### Full
176+
#### Full
175177

176178
```{r}
177179
lgcm2_fit <- sem(
@@ -184,9 +186,9 @@ lgcm2_fit <- sem(
184186
em.h1.iter.max = 100000)
185187
```
186188

187-
## Summary Output
189+
### Summary Output
188190

189-
### Abbreviated
191+
#### Abbreviated
190192

191193
```{r}
192194
summary(
@@ -196,7 +198,7 @@ summary(
196198
rsquare = TRUE)
197199
```
198200

199-
### Full
201+
#### Full
200202

201203
```{r}
202204
summary(
@@ -206,7 +208,7 @@ summary(
206208
rsquare = TRUE)
207209
```
208210

209-
## Estimates of Model Fit
211+
### Estimates of Model Fit
210212

211213
```{r}
212214
fitMeasures(
@@ -220,29 +222,29 @@ fitMeasures(
220222
"rmsea.robust", "cfi.robust", "tli.robust"))
221223
```
222224

223-
## Residuals of Observed vs. Model-Implied Correlation Matrix
225+
### Residuals of Observed vs. Model-Implied Correlation Matrix
224226

225227
```{r}
226228
residuals(
227229
lgcm1_fit,
228230
type = "cor")
229231
```
230232

231-
## Modification Indices
233+
### Modification Indices
232234

233235
```{r}
234236
modificationindices(
235237
lgcm1_fit,
236238
sort. = TRUE)
237239
```
238240

239-
## Internal Consistency Reliability
241+
### Internal Consistency Reliability
240242

241243
```{r}
242244
compRelSEM(lgcm1_fit)
243245
```
244246

245-
## Path Diagram
247+
### Path Diagram
246248

247249
```{r}
248250
semPaths(
@@ -252,9 +254,9 @@ semPaths(
252254
edge.label.cex = 1.5)
253255
```
254256

255-
## Plot Trajectories
257+
### Plot Trajectories
256258

257-
### Protoypical Growth Curve
259+
#### Protoypical Growth Curve
258260

259261
Calculated from intercept and slope parameters:
260262

@@ -299,7 +301,7 @@ ggplot(
299301
geom_line()
300302
```
301303

302-
### Individuals' Growth Curves
304+
#### Individuals' Growth Curves
303305

304306
Calculated from intercept and slope parameters:
305307

@@ -347,7 +349,7 @@ ggplot(
347349
geom_line()
348350
```
349351

350-
### Individuals' Trajectories Overlaid with Prototypical Trajectory
352+
#### Individuals' Trajectories Overlaid with Prototypical Trajectory
351353

352354
```{r}
353355
newData <- as.data.frame(predict(lgcm1_fit))
@@ -374,11 +376,11 @@ ggplot(
374376
linewidth = 2)
375377
```
376378

377-
# Latent Basis Growth Curve Model {#lbgcm}
379+
## Latent Basis Model {#latentBasisLGCM}
378380

379-
## Model Syntax
381+
### Model Syntax
380382

381-
### Abbreviated
383+
#### Abbreviated
382384

383385
```{r}
384386
lbgcm1_syntax <- '
@@ -398,7 +400,7 @@ lbgcm1_syntax <- '
398400
'
399401
```
400402

401-
### Full
403+
#### Full
402404

403405
```{r}
404406
lbgcm2_syntax <- '
@@ -428,9 +430,9 @@ lbgcm2_syntax <- '
428430
'
429431
```
430432

431-
## Fit the Model
433+
### Fit the Model
432434

433-
### Abbreviated
435+
#### Abbreviated
434436

435437
```{r}
436438
lbgcm1_fit <- growth(
@@ -445,7 +447,7 @@ lbgcm1_fit <- growth(
445447
em.h1.iter.max = 100000)
446448
```
447449

448-
### Full
450+
#### Full
449451

450452
```{r}
451453
lbgcm2_fit <- sem(
@@ -458,9 +460,9 @@ lbgcm2_fit <- sem(
458460
em.h1.iter.max = 100000)
459461
```
460462

461-
## Summary Output
463+
### Summary Output
462464

463-
### Abbreviated
465+
#### Abbreviated
464466

465467
```{r}
466468
summary(
@@ -470,7 +472,7 @@ summary(
470472
rsquare = TRUE)
471473
```
472474

473-
### Full
475+
#### Full
474476

475477
```{r}
476478
summary(
@@ -480,7 +482,7 @@ summary(
480482
rsquare = TRUE)
481483
```
482484

483-
## Estimates of Model Fit
485+
### Estimates of Model Fit
484486

485487
```{r}
486488
fitMeasures(
@@ -494,29 +496,29 @@ fitMeasures(
494496
"rmsea.robust", "cfi.robust", "tli.robust"))
495497
```
496498

497-
## Residuals of Observed vs. Model-Implied Correlation Matrix
499+
### Residuals of Observed vs. Model-Implied Correlation Matrix
498500

499501
```{r}
500502
residuals(
501503
lbgcm1_fit,
502504
type = "cor")
503505
```
504506

505-
## Modification Indices
507+
### Modification Indices
506508

507509
```{r}
508510
modificationindices(
509511
lbgcm1_fit,
510512
sort. = TRUE)
511513
```
512514

513-
## Internal Consistency Reliability
515+
### Internal Consistency Reliability
514516

515517
```{r}
516518
compRelSEM(lbgcm1_fit)
517519
```
518520

519-
## Path Diagram
521+
### Path Diagram
520522

521523
```{r}
522524
semPaths(
@@ -526,9 +528,9 @@ semPaths(
526528
edge.label.cex = 1.5)
527529
```
528530

529-
## Plot Trajectories
531+
### Plot Trajectories
530532

531-
### Protoypical Growth Curve
533+
#### Protoypical Growth Curve
532534

533535
```{r}
534536
lbgcm1_intercept <- coef(lbgcm1_fit)["intercept~1"]
@@ -556,7 +558,7 @@ ggplot(
556558
geom_line()
557559
```
558560

559-
### Individuals' Growth Curves
561+
#### Individuals' Growth Curves
560562

561563
```{r}
562564
person_factors <- as.data.frame(predict(lbgcm1_fit))
@@ -593,30 +595,26 @@ ggplot(
593595
geom_line()
594596
```
595597

596-
### Individuals' Trajectories Overlaid with Prototypical Trajectory
597-
598-
```{r}
599-
#ggplot(
600-
# data = newData) +
601-
# xlab("Timepoint") +
602-
# ylab("Score") +
603-
# scale_x_continuous(
604-
# limits = c(0, 3),
605-
# labels = 1:4) +
606-
# scale_y_continuous(
607-
# limits = c(-10, 20)) +
608-
# geom_abline(
609-
# mapping = aes(
610-
# slope = slope,
611-
# intercept = intercept)) +
612-
# geom_abline(
613-
# mapping = aes(
614-
# slope = lgcm1_slope,
615-
# intercept = lgcm1_intercept),
616-
# color = "blue",
617-
# linewidth = 2)
598+
#### Individuals' Trajectories Overlaid with Prototypical Trajectory
599+
600+
```{r}
601+
ggplot() +
602+
geom_line( # individuals' model-implied trajectories
603+
data = individual_trajectories,
604+
aes(x = time, y = value, group = id),
605+
) +
606+
geom_line( # prototypical trajectory
607+
data = newData,
608+
aes(x = time, y = predictedValue),
609+
color = "blue",
610+
linewidth = 2
611+
)
618612
```
619613

614+
## Quadratic Model {#quadraticLGCM}
615+
616+
## Spline Model {#splineLGCM}
617+
620618
# Latent Change Score Model {#lcsm}
621619

622620
## Model Syntax

0 commit comments

Comments
 (0)