-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdv_supplements_between.Rmd
171 lines (138 loc) · 6.86 KB
/
dv_supplements_between.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
---
title: "Iterative Supplements by DV"
output: html_document
params:
btw_dep_var: "QuestionQuality"
---
```{r setup, warning = FALSE, message = FALSE, error = FALSE}
# load libraries
library(brms)
library(tidyverse)
library(ggplot2)
library(tidybayes)
library(dotwhisker)
library(bayesplot)
library(patchwork)
library(broom)
# load data
long_data <- read_csv(here::here('cleaned_numeric_data_long.csv'), col_types = cols(article_type = col_factor(),
Field = col_factor(),
Match = col_factor(),
Order = col_factor(),
keyword_batch_comp = col_factor())) %>%
mutate(question = case_when(article_type == 'RR' ~ str_sub(question, 3),
article_type == 'nonRR' ~ str_sub(question, 4))) %>%
mutate(article_type = fct_relevel(article_type, c('nonRR', 'RR')))
wide_data <- read_csv(here::here('cleaned_numeric_data_wide.csv'), col_types = cols(Field = col_factor(),
Match = col_factor(),
Order = col_factor(),
keyword_batch_comp = col_factor()))
contrasts(wide_data$Field) <- contr.sum(3)
contrasts(wide_data$keyword_batch_comp) <- contr.sum(2)
contrasts(wide_data$Order) <- contr.sum(2)
contrasts(wide_data$Match) <- contr.sum(2)
contrasts(long_data$article_type) <- contr.treatment(2)
contrasts(long_data$Field) <- contr.sum(3)
contrasts(long_data$keyword_batch_comp) <- contr.sum(2)
contrasts(long_data$Order) <- contr.sum(2)
contrasts(long_data$Match) <- contr.sum(2)
```
## Distribution of Outcome Variable for 1st Article
The bars are to the left of the number they go with (e.g. the tallest bar, which is to the left of the 0 tick mark, is the count for 0 response). Difference scores are calculated as the rating for the Registered Reports article minus the Matched article.
```{r warning = FALSE, error = FALSE, message = FALSE}
ggplot(long_data %>% filter(question == as.character(params$btw_dep_var)) %>% filter((Order == 'RRFirst' & article_type == 'RR') | (Order == 'RRSecond' & article_type == 'nonRR')),
aes(x = response)) +
geom_histogram(breaks=seq(-4, 4, by = 1), col = 'blue', fill = 'grey') +
scale_x_continuous(breaks=seq(-4, 4, by = 1)) +
labs(title = stringr::str_glue("Distribution of scores for first article on question: {params$btw_dep_var}"))
```
# Deciding between pooled vs. seperate models by recruitment batch:
```{r warning = FALSE, message = FALSE, error = FALSE, results = 'hide'}
priors <- c(set_prior("normal(0,2)", "b"),
set_prior("normal(0, 2.5)", "sd"))
```
## Between-Subjects Score Models by 'keyword batch'
### First Batch
```{r warning = FALSE, message = FALSE, error = FALSE, results = 'hide'}
# between subjects model for batch 1
between_keywords1 <- brm(response ~ Field + article_type + Match + article_type*Match +
(article_type|RR),
data = long_data %>%
filter(keyword_batch_comp == 1) %>%
filter(grepl(as.character(params$btw_dep_var), question)) %>%
filter((Order == 'RRFirst' & article_type == 'RR') | (Order == 'RRSecond' & article_type == 'nonRR')),
prior = priors,
family = 'gaussian',
chains = 4,
seed = 15)
```
```{r warning = FALSE, message = FALSE,error = FALSE}
summary(between_keywords1)
pp_check(between_keywords1)
WAIC(between_keywords1)
loo(between_keywords1)
```
### Batches 2 + 3
``` {r warning = FALSE, message = FALSE, error = FALSE, results = 'hide'}
between_keywords2 <- brm(response ~ Field + article_type + Match + article_type*Match +
(article_type|RR),
data = long_data %>%
filter(keyword_batch_comp == 2) %>%
filter(grepl(as.character(params$btw_dep_var), question)) %>%
filter((Order == 'RRFirst' & article_type == 'RR') | (Order == 'RRSecond' & article_type == 'nonRR')),
prior = priors,
family = 'gaussian',
chains = 4,
seed = 16)
```
```{r warning = FALSE, message = FALSE,error = FALSE}
summary(between_keywords2)
pp_check(between_keywords2)
WAIC(between_keywords2)
loo(between_keywords2)
```
### graphs of posterior samples
```{r warning = FALSE, message = FALSE,error = FALSE}
posteriors_keywords2 <- suppressMessages(
mcmc_areas(posterior_samples(between_keywords2),
regex_pars = "b_",
prob=.9) +
xlim(-2, 2) +
labs(title = stringr::str_glue('Batch 2 of {params$btw_dep_var}'))
)
posteriors_keywords1 <- suppressMessages(
mcmc_areas(posterior_samples(between_keywords1),
regex_pars = "b_",
prob=.9) +
xlim(-2, 2) +
labs(title = stringr::str_glue('Batch 1 of {params$btw_dep_var}'))
)
posteriors_keywords1 / posteriors_keywords2
```
## Between Subjects Model (with covariate for batch)
```{r, warning = FALSE, message = FALSE, error = FALSE, results = 'hide'}
# difference score model
between_model <- brm(response ~ Field + keyword_batch_comp + article_type + Match + article_type*Match +
(article_type|RR),
data = long_data %>% filter(grepl(as.character(params$btw_dep_var), question)) %>% filter((Order == 'RRFirst' & article_type == 'RR') | (Order == 'RRSecond' & article_type == 'nonRR')),
prior = priors,
family = 'gaussian',
chains = 4,
seed = 17)
```
```{r warning = FALSE, message = FALSE,error = FALSE}
summary(between_model)
pp_check(between_model)
pp_check(between_model, type = "stat", stat = 'median')
WAIC(between_model)
loo(between_model)
```
## graph comparing estimates and 95% intervals for all 3 models
```{r}
bind_rows(tidy(between_model) %>% mutate(model = 'between_pooled'),
tidy(between_keywords1) %>% mutate(model = 'batch1'),
tidy(between_keywords2) %>% mutate(model = 'batch2')) %>%
filter(grepl('b_', term)) %>%
dotwhisker::dwplot() +
ggtitle(stringr::str_glue('All between models for {params$btw_dep_var}'))
```