-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
169 lines (117 loc) · 3.73 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
---
output: github_document
bibliography: "inst/ma.bib"
csl: "inst/apa.csl"
---
```{r setup, include = FALSE, warning = FALSE, comment = FALSE}
#library(poLCAExtra)
devtools::load_all()
set.seed(42)
```
# poLCAExtra : New and convenient functions to improve workflow of `poLCA`
The package `poLCAExtra` offers convenient functions to improve the workflow of [`poLCA`](https://github.com/dlinzer/poLCA)[@poLCA]
```{r github, echo = TRUE, eval = FALSE}
# Current development version
remotes::install_github(repo = "quantmeth/poLCAExtra")
```
# Comparing many latent class models
Either by using many latent class models like
```{r LCA, warning = FALSE, comment = FALSE, message = FALSE, results = FALSE}
# poLCAExtra has two data sets examples
jd <- ex1.poLCA
# Formula
f1 <- as.formula(cbind(V1, V2, V3, V4, V5, V6) ~ 1)
# Four latent classes analysis of increasing classes
LCA1 <- poLCA(f1, data = jd, nclass = 1, verbose = FALSE)
LCA2 <- poLCA(f1, data = jd, nclass = 2, verbose = FALSE)
LCA3 <- poLCA(f1, data = jd, nclass = 3, verbose = FALSE)
LCA4 <- poLCA(f1, data = jd, nclass = 4, maxiter = 1000, nrep = 10, verbose = FALSE)
```
which can then be compared with
```{r CompareLCA}
anova(LCA1, LCA2, LCA3, LCA4)
```
The function readily gathers some relevant statitics to choose the number of classes.
This new version of `poLCA` can also handle many number of classes and yield the same output.
```{r, warning = FALSE, comment = FALSE, message = FALSE, results = FALSE}
LCAE <- poLCA(f1, data = jd, nclass = 1:4)
LCAE
```
Both previous tables can be easily exported.
The original `plot()` (from `poLCA`) function has been updated to account for the multiple LCA.
```{r plotLCA}
plot(LCAE, nclass = 3)
```
There is also a new plot that works with a single LCA output.
```{r}
poLCA.plot(LCA3)
```
Or all the LCA output, which may help to compare diffent number of classes.
```{r}
poLCA.plot(LCAE)
# If only a subset is required
# poLCA.plot(LCAE, nclass = 2:3)
# poLCA.plot(LCA2, LCA3)
```
# New features
## New indices
The `SABIC`, `CAIC`, and `AIC3` statistics have been added to `poLCA`.
```{r sabic}
LCA3$sabic
LCA3$caic
LCA3$aic3
```
The relative entropy, which is more often requested than the entropy, has been added.
```{r re}
poLCA.relentropy(LCA3)
```
The Lo-Mendell-Rubin adjusted likelihood ratio test and the Vuong-Lo-Mendell-Rubin likelihood ratio test have been added.
```{r lrt}
poLCA.lrt(LCA3)
```
The bootstrapped Vuong-Lo-Mendell-Rubin likelihood ratio test which is more generally recommended is also added. Note that the bootstrapped tests are quite time-consuming.
```{r tech14, cache = TRUE}
poLCA.blrt(LCAE)
# poLCA.blrt(LCA3)
```
# New functions
## A `predict()` function
Predicted probabilities and classes
```{r predict}
head(round(predict(LCA3), 3))
# head(round(predict(LCAE, nclass = 3),3))
```
## Two functions to verify LCA assumptions
Analysis of residual (also known as Tech10 in Mplus) to investigate local independence.
```{r tech10}
poLCA.residual.pattern(LCAE, nclass = 3)
# poLCA.tech10(LCA3)
```
Another one to inspect the covariance matrice.
```{r rescov}
poLCA.cov(LCAE, nclass = 3)
# poLCA.cov(LCA3)
```
<!-- ## A summary -->
## Bootstrap 3-step approach
The 3-step approaches will be improved.
Here are two examples that can be readily be implemented.
```{r 3step, cache = TRUE}
d3 <- d3step("categorical", LCAE, nclass = 3)
# d3step("categorical", LCA3)
d3
r3 <- r3step("continuous", LCAE, nclass = 3)
# r3step("continuous", LCA3)
r3
```
d3step plot
```{r d3stepplot}
plot(d3, ci = c(.05,.95))
```
r3step plot
```{r r3stepplot}
plot(r3, ci = c(.05, .95))
```
# How to cite
Caron, P.-O. (2024). *poLCAExtra : New and Convenient Functions for the Package 'poLCA'*. https://github.com/quantmeth/poLCAExtra
# References