-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqs_3_intersectional.R
46 lines (39 loc) · 1.39 KB
/
qs_3_intersectional.R
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
# Fit an intersectional model using data with qualitative severity ratings only
#
# Required Files:
# * 'df_v1v2v3_harm.rds'
#
# Author: Greg Serapio-García
# load dependencies
library(brms)
library(performance)
# read in preprocessed data
df_v1v2v3_harm <- readRDS("df_v1v2v3_harm.rds")
# set model formula: harm-annotated, gender * race + demographics
formula_harm <-
"Q_Overall ~ race_detailed * (DEMO_gender + DEMO_age + degree_of_harm) + DEMO_education + (1 | rater_id) + (1 | item_id)"
# set priors for the thresholds using these cumulative proportions
prior_thresholds <- c(
prior(normal(.440, 0.5), class = Intercept, coef = 1),
prior(normal(.583, 0.5), class = Intercept, coef = 2),
prior(student_t(3, 0, 1), class = "b")
)
# fit and save model using brms
bfit <-
# **NB** degree of harm is only found in a SUBSET of the data
brm(data = df_v1v2v3_harm,
family = cumulative("probit"),
formula = formula_harm,
prior = prior_thresholds,
iter = 4000, warmup = 1000, chains = 4, cores = 4,
seed = 42,
backend = "cmdstanr", threads = threading(2),
file = "fits/bfit_qs_3_intersectional")
# compute model performance metrics
perf <-
model_performance(
model = bfit,
metrics = c(
"LOOIC", "WAIC", "R2", "R2_adj", "RMSE", "SIGMA", "LOGLOSS", "SCORE"))
# save model performance metrics
saveRDS(perf, "performance_data/perf_qs_3_intersectional.rds")