-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrelational_processes.Rmd
More file actions
223 lines (176 loc) · 8.78 KB
/
relational_processes.Rmd
File metadata and controls
223 lines (176 loc) · 8.78 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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
---
title: "Analyses of the Anger Experiencers' Relational Processes"
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 represents the test of the hypotheses and research questions about the relational processes of the participants during their anger experience, and how the different aspects of these processes vary between justified and unjustified anger prototypes.
```{r setup, include=FALSE, warning=FALSE}
#load libraries
package_list <- c("dplyr", "tidyr", "ggplot2", "MetBrewer", "lmerTest")
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")
#Function to report correlation
cor_report <- function(cor_output) {
r <- cor_output[["estimate"]] %>% round(2)
df <- cor_output[["parameter"]] %>% round(1)
ci_lb <- (cor_output[["conf.int"]])[1] %>% round(2)
ci_ub <- (cor_output[["conf.int"]])[2] %>% round(2)
original_p <- cor_output[["p.value"]] %>% round(3)
p <- if_else(original_p >= .001, paste0("= ", as.character(original_p)), "< .001")
print(paste0("r(", df, ") = ", r, " [", ci_lb, ", ", ci_ub, "], p ", p))
}
#Function to report independent-samples t-test
ind_ttest_report <- function(iv, dv) {
ttest <- t.test(dv ~ iv)
effect_size <- effectsize::cohens_d(dv ~ iv, pooled_sd = FALSE)
t <- ttest[["statistic"]] %>% round(2)
df <- ttest[["parameter"]] %>% round(1)
original_p <- ttest[["p.value"]] %>% round(3)
p <- if_else(original_p >= .001, paste0("= ", as.character(original_p)), "< .001")
d <- effect_size[1,1] %>% round(2)
print(paste0("t(", df, ") = ", t, ", p ", p, ", d = ", d))
}
#Function to report paired-samples t-test
paired_ttest_report <- function(t1, t2) {
ttest <- t.test(Pair(t1, t2) ~ 1)
effect_size <- effectsize::cohens_d(Pair(t1, t2) ~ 1, pooled_sd = FALSE)
t <- ttest[["statistic"]] %>% round(2)
df <- ttest[["parameter"]] %>% round(1)
original_p <- ttest[["p.value"]] %>% round(3)
p <- if_else(original_p >= .001, paste0("= ", as.character(original_p)), "< .001")
d <- effect_size[1,1] %>% round(2)
print(paste0("t(", df, ") = ", t, ", p ", p, ", d = ", d))
}
#Function to calculate percentages for each category of a Factor variable
percentage <- function(var, includeNA = 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")
print(tabb)
}
knitr::opts_chunk$set(echo = TRUE)
```
```{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)
#drop cases following preregistration
df1 <- df %>%
filter(NarrativeWritten != "No") %>%
filter(NarrativeRelevant != "No") %>%
filter(!is.na(Condition))
```
## Perception of Target's Regret/Apology
**Research Question:** Do the perceptions of the target as regretful and apologetic vary depending on whether they consider the anger event as justified or unjustified?
```{r, regret-apol}
#Regret
df1 %>%
t.test(person_regret ~ Condition, data = .)
df1 %>%
effectsize::cohens_d(person_regret ~ Condition, data = .)
#For reporting:
ind_ttest_report(df1$Condition, df1$person_regret)
#Apology
df1 %>%
t.test(person_apologize ~ Condition, data = .)
df1 %>%
effectsize::cohens_d(person_apologize ~ Condition, data = .)
#For reporting:
ind_ttest_report(df1$Condition, df1$person_apologize)
```
## Relationship Closeness
**Hypothesis 1:** Relationship closeness deteriorates following an anger event, both “short-term” (i.e., comparing closeness before and immediately after the event) and “long-term” (i.e., comparing closeness before the event and at the time of the study).
```{r closeness1}
closeness_df <- df1 %>%
select(ResponseId, Condition, prior_closeness, immed_closeness, now_closeness)
#create a long dataframe
closeness_df_long <- closeness_df %>%
tidyr::pivot_longer(cols = c(prior_closeness, immed_closeness, now_closeness),
names_to = "time",
values_to = "closeness") %>%
mutate(time = as.factor(time)) %>%
mutate(time = forcats::fct_relevel(time, "prior_closeness", "immed_closeness", "now_closeness"))
levels(closeness_df_long$time) <- c("prior", "immediate", "now")
#setup the contrasts
contrasts(closeness_df_long$Condition) <- contr.sum
contrasts(closeness_df_long$time) <- contr.sum
#Overal model
closeness_model <- lmer(closeness ~ time * Condition + (1 | ResponseId),
data = closeness_df_long)
anova(closeness_model, type = "III")
effectsize::eta_squared(closeness_model)
#comparing closeness (a) before vs. immediately after the event
pbkrtest.limit = 4000
pairwise_mod <- emmeans::emmeans(closeness_model, pairwise ~ time, pbkrtest.limit = 4000)
pairwise_mod[["contrasts"]][1]
#For reporting the effect size
effectsize::cohens_d(Pair(closeness_df$prior_closeness, closeness_df$immed_closeness) ~ 1, pooled_sd = FALSE)
#comparing closeness (b) before vs. now
pairwise_mod[["contrasts"]][2]
#For reporting the effect size
effectsize::cohens_d(Pair(closeness_df$prior_closeness, closeness_df$now_closeness) ~ 1, pooled_sd = FALSE)
```
**Hypothesis 2:** The long-term deterioration of relationship closeness is stronger for justified (vs. unjustified) anger experiences.
```{r, closeness2}
summary(closeness_model) #The time1:Condition1 interaction demonstrates the significant interaction between time (prior vs. now) and anger type.
longterm_mod <- emmeans::emmeans(closeness_model, pairwise ~ time | Condition, pbkrtest.limit = 4000)
#justified: prior vs. now
longterm_mod[["contrasts"]][2]
#not justified: prior vs. now
longterm_mod[["contrasts"]][5]
#For the reporting of the effect sizes:
closeness_df %>%
filter(Condition == "justified") %>%
summarise(d = effectsize::cohens_d(Pair(prior_closeness, now_closeness) ~ 1, pooled_sd = FALSE, data = .))
closeness_df %>%
filter(Condition == "nonjustified") %>%
summarise(d = effectsize::cohens_d(Pair(prior_closeness, now_closeness) ~ 1, pooled_sd = FALSE, data = .))
```
Create a figure for the manuscript:
```{r, closeness-fig}
#df with descriptive summary
descripts <- psych::describeBy(closeness_df_long$closeness,
group = list(closeness_df_long$Condition, closeness_df_long$time), mat = TRUE) %>%
select(group1, group2, mean, se) %>%
transmute(Anger = as.factor(group1),
Time = as.factor(group2),
mean, se)
levels(descripts$Anger) <- c("Justified", "Unjustified")
levels(descripts$Time) <- c("Immediately After", "Now", "Prior")
descripts$Time <- relevel(descripts$Time, ref = "Prior")
#figure
closeness_p <- ggplot(
descripts,
aes(x = Time, color = Anger, group = Anger, y = mean,
ymin = mean-se, ymax = mean+se)) +
geom_line(position = position_dodge(0.1)) +
geom_errorbar(position = position_dodge(0.1), width = 0.12) +
geom_point(aes(color = Anger), position = position_dodge(0.1), size = .8) +
ylim(1, 5) +
ggtitle(" ") +
theme_bw() +
labs(y="Relationship Closeness", x = " ") +
theme(plot.title = element_text(hjust = 0.5), text = element_text(size = 12),
axis.text.x= element_text(size = 12)) +
scale_color_manual(values=met.brewer("Nizami", 2, direction=-1))
closeness_p
#code to save the figure for the manuscript
#ggsave(plot = closeness_p, width = 7, height = 3.5, dpi = 300, filename = "closeness_p.png")
```