-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMELD.R
208 lines (194 loc) · 8.54 KB
/
MELD.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
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
#Import csv file
dat = read.csv('D:\\D drive\\MELD corpus\\output\\MELD_Dyadic_ap_pairdistance.csv',sep='\t')
dat$col3= (dat$Emotion==dat$Sentiment)
table(dat['col3'])
#1362 entries have different classes when compared to 8937
library(palmerpenguins)
library(ggstatsplot)
library(tibble)
library(ggpubr)
str(dat)
dat$Emotion <- as.factor(dat$Emotion)
x <- which(names(dat) == "Emotion") # name of grouping variable
y <- which(names(dat) == "Mean.Pitch.distance" # names of variables to test
|names(dat) == "Min.Pitch.distance" |
names(dat) == "Max.Pitch.distance" |
names(dat) == "Mean.Intensity.distance" |
names(dat) == "Min.Intensity.distance" |
names(dat) == "Max.Intensity.distance" |
names(dat) == "Jitter.distance" |
names(dat) == "Shimmer.distance" |
names(dat) == "Mean.Nhr.distance" |
names(dat) == "Speechrate.distance")
method1 <- "anova" # one of "anova" or "kruskal.test"
method2 <- "t.test" # one of "wilcox.test" or "t.test"
my_comparisons <- list(c("positive-negative", "negative-positive"), c("positive-neutral", "neutral-positive"), c("neutral-negative", "negative-neutral"),c("negative-negative", "positive-positive")) # comparisons for post-hoc tests
# Edit until here
# Edit at your own risk
for (i in y) {
for (j in x) {
p <- ggboxplot(dat,
x = colnames(dat[j]), y = colnames(dat[i]),
color = colnames(dat[j]),
legend = "none",
palette = "npg",
add = "jitter"
)
print(
p + stat_compare_means(aes(label = paste0(after_stat(method), ", p-value = ", after_stat(p.format))),
method = method1, label.y = max(dat[, i], na.rm = TRUE)
)
+ stat_compare_means(comparisons = my_comparisons, method = method2, label = "p.format") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))# remove if p-value of ANOVA or Kruskal-Wallis test >= alpha
)
}
}
#######################
data = read.csv('D:\\D drive\\MELD corpus\\output\\MELD_Dyadic_ap_pairdistance1.csv')
dat <- subset(data, Emotion == "neutral-positive"|Emotion == "neutral-negative")
dat$Emotion <- factor(dat$Emotion)
str(dat)
for (i in 6:13) { # variables to compare are variables 1 to 4
boxplot(dat[, i] ~ dat$Emotion, # draw boxplots by group
ylab = names(dat[i]), # rename y-axis with variable's name
xlab = "Emotion"
)
print(t.test(dat[, i] ~ dat$Emotion)) # print results of t-test
}
x <- which(names(dat) == "Emotion") # name of grouping variable
y <- which(names(dat) == "Mean.Pitch.distance" # names of variables to test
|
names(dat) == "Max.Pitch.distance" |
names(dat) == "Mean.Intensity.distance" |
names(dat) == "Max.Intensity.distance" |
names(dat) == "Jitter.distance" |
names(dat) == "Shimmer.distance" |
names(dat) == "Mean.Nhr.distance" |
names(dat) == "Speechrate.distance")
method <- "t.test" # one of "wilcox.test" or "t.test"
paired <- FALSE # if paired make sure that in the dataframe you have first all individuals at T1, then all individuals again at T2
# Edit until here
# Edit at your own risk
for (i in y) {
for (j in x) {
ifelse(paired == TRUE,
p <- ggpaired(dat,
x = colnames(dat[j]), y = colnames(dat[i]),
color = colnames(dat[j]), line.color = "gray", line.size = 0.4,
palette = "npg",
legend = "none",
xlab = colnames(dat[j]),
ylab = colnames(dat[i]),
add = "jitter"
),
p <- ggboxplot(dat,
x = colnames(dat[j]), y = colnames(dat[i]),
color = colnames(dat[j]),
palette = "npg",
legend = "none",
add = "jitter"
)
)
# Add p-value
print(p + stat_compare_means(aes(label = paste0(after_stat(method), ", p-value = ", after_stat(p.format))),
method = method,
paired = paired,
# group.by = NULL,
ref.group = NULL
))
}
}
###########25-04
#dat = read.csv('D:\\D drive\\MELD corpus\\output\\MELD_Dyadic_ap_pairdistance.csv',sep='\t')
#dat$emotion_type <- ifelse(dat$Emotion=='positive-positive' | dat$Emotion=='neutral-neutral'| dat$Emotion=='negative-negative', "same", "different")
dat = read.csv('D:\\D drive\\MELD corpus\\output\\MELD_Dyadic_ap_pairdistance.csv',sep='\t')
dat$col3= (dat$Emotion==dat$Emotion)
table(dat['col3'])
#1362 entries have different classes when compared to 8937
library(palmerpenguins)
library(ggstatsplot)
library(tibble)
library(ggpubr)
str(dat)
dat$Emotion <- as.factor(dat$Emotion)
x <- which(names(dat) == "Emotion") # name of grouping variable
y <- which(names(dat) == "Mean.Pitch.distance" # names of variables to test
|names(dat) == "Min.Pitch.distance" |
names(dat) == "Max.Pitch.distance" |
names(dat) == "Mean.Intensity.distance" |
names(dat) == "Min.Intensity.distance" |
names(dat) == "Max.Intensity.distance" |
names(dat) == "Jitter.distance" |
names(dat) == "Shimmer.distance" |
names(dat) == "Mean.Nhr.distance" |
names(dat) == "Speechrate.distance")
method1 <- "anova" # one of "anova" or "kruskal.test"
method2 <- "t.test" # one of "wilcox.test" or "t.test"
my_comparisons <- list(c("positive-positive", "negative-negative"), c("positive-positive", "neutral-neutral"), c("negative-negative", "neutral-neutral")) # comparisons for post-hoc tests
# Edit until here
# Edit at your own risk
for (i in y) {
for (j in x) {
p <- ggboxplot(dat,
x = colnames(dat[j]), y = colnames(dat[i]),
color = colnames(dat[j]),
legend = "none",
palette = "npg",
add = "jitter"
)
print(
p + stat_compare_means(aes(label = paste0(after_stat(method), ", p-value = ", after_stat(p.format))),
method = method1, label.y = max(dat[, i], na.rm = TRUE)
)
+ stat_compare_means(comparisons = my_comparisons, method = method2, label = "p.format") + theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1))# remove if p-value of ANOVA or Kruskal-Wallis test >= alpha
)
}
}
#two.way <- aov(Emotion ~ Mean.Pitch.distance + Min.Pitch.distance, data = dat)
data = read.csv('D:\\D drive\\MELD corpus\\output\\MELD_Dyadic_ap_pairdistance.csv',sep='\t')
dat <- subset(data, Emotion == "positive-positive"|Emotion == "neutral-neutral") #|Emotion =="negative-negative"
dat$Emotion <- factor(dat$Emotion)
str(dat)
for (i in 6:15) { # variables to compare are variables 1 to 4
boxplot(dat[, i] ~ dat$Emotion, # draw boxplots by group
ylab = names(dat[i]), # rename y-axis with variable's name
xlab = "Emotion"
)
print(t.test(dat[, i] ~ dat$Emotion)) # print results of t-test
}
#Pos-pos and neg-neg no diff in means
#Pos-pos and neu-neu no diff in means
#neg-neg and neu-neu no diff in means
############
data = read.csv('D:\\D drive\\MELD corpus\\output\\MELD_Dyadic_ap_pairdistance_abs.csv',sep='\t')
dat <- subset(data, Emotion == "positive-positive"|Emotion == "neutral-neutral"|Emotion == "negative-negative")
library(palmerpenguins)
str(dat)
dat$Emotion <- as.factor(dat$Emotion)
library(ggstatsplot)
library(tibble)
x<-"Emotion"
cols <- 6:15
type <- "parametric" # given the large number of observations, we use the parametric version
paired <- FALSE
plotlist <-
purrr::pmap(
.l = list(
data = list(as_tibble(dat)),
x = x,
y = as.list(colnames(dat)[cols]),
plot.type = "box", # for boxplot
type = type, # parametric or nonparametric
pairwise.comparisons = TRUE, # to run post-hoc tests if more than 2 groups
pairwise.display = "significant", # show only significant differences
bf.message = FALSE, # remove message about Bayes Factor
centrality.plotting = FALSE # remove central measure
),
.f = ifelse(paired, # automatically use ggwithinstats if paired samples, ggbetweenstats otherwise
ggstatsplot::ggwithinstats,
ggstatsplot::ggbetweenstats
)
)
# print all plots together with statistical results
for (i in 1:length(plotlist)) {
print(plotlist[[i]])
}