-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path04-lca-plots.Rmd
More file actions
179 lines (130 loc) · 6.72 KB
/
Copy path04-lca-plots.Rmd
File metadata and controls
179 lines (130 loc) · 6.72 KB
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
170
171
172
173
174
175
176
177
178
179
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE,
warning = FALSE,
message = FALSE) #Here, I have made it so that when you knit your .rmd, warnings and messages will not show up in the html markdown.
```
# Item Probability Plots
------------------------------------------------------------------------
Example: Bullying in Schools
------------------------------------------------------------------------
To demonstrate mixture modeling in the training program and online resource components of the IES grant we utilize the *Civil Rights Data Collection (CRDC)*[@usdoe2014] data repository.
The CRDC is a federally mandated school-level data collection effort that occurs every other year.
This public data is currently available for selected latent class indicators across 4 years (2011, 2013, 2015, 2017) and all US states.
In this example, we use the Arizona state sample.
We utilize six focal indicators which constitute the latent class model in our example; three variables which report on harassment/bullying in schools based on disability, race, or sex, and three variables on full-time equivalent school staff hires (counselor, psychologist, law enforcement).
This data source also includes covariates on a variety of subjects and distal outcomes reported in 2018 such as math/reading assessments and graduation rates.
------------------------------------------------------------------------
Load packages
```{r, cache = FALSE}
library(tidyverse)
library(haven)
library(glue)
library(MplusAutomation)
library(here)
library(janitor)
library(gt)
library(cowplot)
library(DiagrammeR)
```
## Variable Description
```{r, echo=FALSE, eval=TRUE}
tribble(
~"Name", ~"Label", ~"Values",
#--------------|--------------------------------|-----|,
"leaid", "District Identification Code", "",
"ncessch", "School Identification Code", "",
"report_dis", "Number of students harassed or bullied on the basis of disability", "0 = No reported incidents, 1 = At least one reported incident",
"report_race", "Number of students harassed or bullied on the basis of race, color, or national origin", "0 = No reported incidents, 1 = At least one reported incident",
"report_sex", "Number of students harassed or bullied on the basis of sex", "0 = No reported incidents, 1 = At least one reported incident",
"counselors_fte", "Number of full time equivalent counselors hired as school staff", "0 = No staff present, 1 = At least one staff present",
"psych_fte", "Number of full time equivalent psychologists hired as school staff", "0 = No staff present, 1 = At least one staff present",
"law_fte", "Number of full time equivalent law enforcement officers hired as school staff", "0 = No staff present, 1 = At least one staff present") %>%
gt() %>%
tab_header(
title = "LCA indicators" # Add a title
) %>%
tab_options(
table.width = pct(75)
) %>%
tab_footnote(
footnote = "Civil Rights Data Collection (CRDC)",
location = cells_title())
```
------------------------------------------------------------------------
**Variables have been transformed to be dichotomous indicators using the following coding strategy**
Harassment and bullying count variables are recoded `1` if the school reported at least one incident of harassment (`0` indicates no reported incidents).
On the original scale reported by the CDRC staff variables for full time equivalent employees (FTE) are represented as `1` and part time employees are represented by values between `1` and `0`.
Schools with greater than one staff of the designated type are represented by values greater than 1.
All values greater than zero were recorded as `1s` (e.g., `.5`, `1`,`3`) indicating that the school has a staff present on campus at least part time.
Schools with no staff of the designated type are indicated as `0` for the dichotomous variable.
------------------------------------------------------------------------
```{r, echo=FALSE, eval=TRUE, fig.align='center'}
grViz(" digraph cfa_model {
# The `graph` statement - No editing needed
graph [layout = dot, overlap = true]
# Two `node` statements
# One for measured variables (box)
node [shape=box]
report_dis report_race report_sex counselors_fte psych_fte law_fte;
# One for latent variables (circle)
node [shape=circle]
bully [label=<Bullying <br/>C<sub>k</sub>>];
# `edge` statements
edge [minlen = 2]
bully -> {report_dis report_race report_sex counselors_fte psych_fte law_fte}
}")
```
------------------------------------------------------------------------
## Prepare Data
```{r, eval=TRUE}
df_bully <- read_csv(here("data", "crdc_lca_data.csv")) %>%
clean_names() %>%
dplyr::select(report_dis, report_race, report_sex, counselors_fte, psych_fte, law_fte)
```
------------------------------------------------------------------------
## Descriptive Statistics
```{r}
dframe <- df_bully %>%
pivot_longer(
c(report_dis, report_race, report_sex, counselors_fte, psych_fte, law_fte),
names_to = "Variable"
) %>%
group_by(Variable) %>%
summarise(
Count = sum(value == 1, na.rm = TRUE),
Total = n(),
.groups = "drop"
) %>%
mutate(`Proportion Endorsed` = round(Count / Total, 3)) %>%
select(Variable, `Proportion Endorsed`, Count)
gt(dframe) %>%
tab_header(
title = md("**LCA Indicator Endorsement**"),
subtitle = md(" ")
) %>%
tab_options(
column_labels.font.weight = "bold",
row_group.font.weight = "bold"
)
```
Save as image
```{r, eval = FALSE}
gtsave(prop_table, here("figures", "prop_table.png"))
```
------------------------------------------------------------------------
## 3-Class Probability Plot
Continuing the example from the bookdown, use the `plot_lca` function provided in the folder to plot the item probability plot. This function requires one argument:
- `model_name`: The name of the Mplus `readModels` object (e.g., `output_enum$c3_bully.out`)
```{r, height=5, width=8}
source(here("functions", "plot_lca.R"))
# Extract outputs from the enumeration folder
output_enum <- readModels(here("enum"), filefilter = "bully", quiet = TRUE)
plot_lca(model_name = output_enum$c3_bully.out)
```
------------------------------------------------------------------------
Save figure:
```{r, eval = FALSE}
ggsave(here("figures", "C3_bully_LCA_Plot.png"), dpi="retina", height=5, width=7, units="in")
```
------------------------------------------------------------------------
<div style="text-align: center;"><img src="images/ucsb_logo.png" width="75%" /></div>