-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdescriptive_analyses.Rmd
More file actions
186 lines (147 loc) · 5.3 KB
/
descriptive_analyses.Rmd
File metadata and controls
186 lines (147 loc) · 5.3 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
180
181
182
183
184
185
---
title: "Descriptives"
author: "Pooya Razavi"
date: "last knitted: `r Sys.time()`"
output:
html_document:
theme: cosmo
highlight: textmate
toc: TRUE
toc_float: TRUE
editor_options:
chunk_output_type: console
---
This script provides a summary of the descriptive characteristics of the participants (i.e., demographics) and the event (e.g., cause of anger, ease of remembering).
```{r setup, include=FALSE, warning=FALSE}
#load libraries
package_list <- c("dplyr", "tidyr", "ggplot2")
lapply(package_list, require, character.only = TRUE)
#read in the data
df <- readxl::read_xlsx("C:/Users/pooya/Dropbox (University of Oregon)/Anger Dissertation/Prototype study analysis/ProcessedData_F21_W22_S22_F22.xlsx")
#the percentage function
percentage <- function(var, includeNA = TRUE, arran = TRUE) {
tabb <- table(var) %>% as.data.frame()
if (includeNA == TRUE) {
tabb$percentage <- (tabb$Freq * 100 / length(var))
} else {
tabb$percentage <- (tabb$Freq * 100 / sum(tabb$Freq))
}
colnames(tabb)[1] <- c("category")
if (arran == FALSE) {
knitr::kable(tabb)
} else {
tabb %>% arrange(desc(percentage)) %>% knitr::kable()
}
}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, factor-setup}
# gender
df$gender <- factor(df$gender)
levels(df$gender) <- c("female", "male" ,"nonbinary", "self-describe", "prefer not to say", NA)
# race/ethnicity
df$ethnicity <- factor(df$ethnicity)
levels(df$ethnicity) <- c(
"American Indian or Alaska Native",
"Asian",
"Black or African American",
"Hispanic, Latinx or Spanish Origin",
"Middle Eastern or North African",
"Native Hawaiian or Other Pacific Islander",
"White",
"Some other ethnicity or origin, please specify:",
"I prefer not to answer.",
"Multiracial",
NA
)
# person/entity who caused anger
df$who_caused <- factor(df$who_caused)
levels(df$who_caused) <- c(
"romantic partner",
"parent",
"sibling",
"child",
"close friend",
"coworker",
"classmate",
"acquintance",
"teacher",
"boss",
"stranger",
"public figure",
"corporation/organization",
"other",
NA
)
#we can search for the word "roommate" for people who reported "other" as cause
df <- df %>%
mutate(who_caused2 = if_else(who_caused == "other" & grepl("roommate", right_narrative), "roommate",
if_else(who_caused == "other" & grepl("roommate", nonright_narrative), "roommate",
as.character(who_caused)))
)
```
```{r, data-exclusion}
#assigning values to factor levels
df$NarrativeWritten <- as.factor(df$NarrativeWritten)
df$NarrativeRelevant <- as.factor(df$NarrativeRelevant)
df$Condition <- as.factor(df$Condition)
levels(df$NarrativeWritten) <- c("No", "Yes")
levels(df$NarrativeRelevant) <- c("No", "Yes", NA, NA)
levels(df$Condition) <- c("justified", "nonjustified", NA)
#Number of participants
table(df$NarrativeRelevant)
#drop cases following preregistration
df1 <- df %>%
filter(NarrativeWritten != "No") %>%
filter(NarrativeRelevant != "No") %>%
filter(!is.na(Condition))
```
# Demographics
```{r}
# age
psych::describe(as.numeric(df$age))
psych::describe(as.numeric(df1$age))
# gender
table(df1$gender, useNA = "ifany")
percentage(df1$gender, includeNA = FALSE)
#participants who self-described:
table(df1$gender_other)
# race-ethnicity
table(df1$ethnicity, useNA = "ifany")
percentage(df1$ethnicity, includeNA = FALSE)
#participants who self-described:
table(df1$ethnicity_other)
```
# Person/Entity who Caused Anger
```{r}
#overal
table(df1$who_caused2, useNA = "ifany")
percentage(df1$who_caused2, includeNA = FALSE)
#for each condition
cause_summary <- df1 %>%
group_by(Condition, who_caused2) %>%
summarise(n = n()) %>%
pivot_wider(names_from = Condition,
values_from = n) %>%
mutate(justified_perc = round(justified * 100 / sum(justified), 2),
unjustified_perc = round(nonjustified * 100 / sum(nonjustified, na.rm = TRUE), 2),
overl_freq = justified + nonjustified,
overall_perc = round(overl_freq * 100 / sum(overl_freq, na.rm = TRUE), 2)) %>%
arrange(desc(overl_freq))
cause_summary %>% knitr::kable()
#write.csv(cause_summary, "who_caused_anger_table.csv")
```
# Ease of remembering
```{r}
#descriptives
psych::describe(df1$ease_remember)
psych::describeBy(df1$ease_remember, group = df1$Condition)
#difference between the two conditions
t.test(ease_remember ~ Condition, data = df1)
effectsize::cohens_d(ease_remember ~ Condition, data = df1)
df1 %>%
ggplot(aes(x = ease_remember, colour = Condition, fill = Condition)) +
geom_histogram(alpha=0.4, position="dodge", binwidth = .4) +
labs(x = "How easy was it for you to remember this incident?") +
theme_minimal()
```