-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.Rhistory
512 lines (512 loc) · 16 KB
/
.Rhistory
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
lowerNeg <- negCI$bca[[4]]
upperNeg <- negCI$bca[[5]]
# Bootstrap the correlation between each positive rating, and the by-item average
posBoot <- boot(posData, bootCor, R=R)
rPos <- posBoot$t0
posCI <- boot.ci(posBoot, type="bca")
lowerPos <- posCI$bca[[4]]
upperPos <- posCI$bca[[5]]
return(list(list(lowerPos,upperPos,rPos), list(lowerNeg,upperNeg,rNeg)))
}
# Initialize an empty dataframe to store values
cis <- data.frame(name=character(), sign=character(), r=numeric(), lower=numeric(), upper=numeric(), stringsAsFactors=FALSE)
# Iterate over datasets
for(dataset in datasets) {
# Track the name of the current dataset
name <- dataset$task[1]
# For each dataset, apply the function corRatings described above
c(c(posLower, posUpper, posR), c(negLower, negUpper, negR)) %<-% corRatings(dataset)
# Append the results to the dataframe
cis[nrow(cis) + 1,] = list(name, 'pos', posR, posLower, posUpper)
cis[nrow(cis) + 1,] = list(name, 'neg', negR, negLower, negUpper)
}
R <- 5000
# Bootstrap function, calculating the correlation coefficient for each bootstrapped sample
bootCor <- function(data, i){
d <- data[i,]
rDf <- correlate(d %>% select(-task))
return(rDf[[2,2]])
}
# Split the data by halves of the rating scale, apply the above bootstrap function, and extract confidence intervals
corRatings <- function(data){
# Separate the data into half-scales
negData <- data %>% filter(status=="antiiconic")%>%select(-status)
posData <- data %>% filter(status=="not antiiconic")%>%select(-status)
# Bootstrap the correlation between each negative rating, and the by-item average
negBoot <- boot(negData, bootCor, R=R)
negCI <- boot.ci(negBoot, type="bca")
rNeg <- negBoot$t0
lowerNeg <- negCI$bca[[4]]
upperNeg <- negCI$bca[[5]]
# Bootstrap the correlation between each positive rating, and the by-item average
posBoot <- boot(posData, bootCor, R=R)
rPos <- posBoot$t0
posCI <- boot.ci(posBoot, type="bca")
lowerPos <- posCI$bca[[4]]
upperPos <- posCI$bca[[5]]
return(list(list(lowerPos,upperPos,rPos), list(lowerNeg,upperNeg,rNeg)))
}
# Initialize an empty dataframe to store values
cis <- data.frame(name=character(), sign=character(), r=numeric(), lower=numeric(), upper=numeric(), stringsAsFactors=FALSE)
# Iterate over datasets
for(dataset in datasets) {
# Track the name of the current dataset
name <- dataset$task[1]
# For each dataset, apply the function corRatings described above
c(c(posLower, posUpper, posR), c(negLower, negUpper, negR)) %<-% corRatings(dataset)
# Append the results to the dataframe
cis[nrow(cis) + 1,] = list(name, 'pos', posR, posLower, posUpper)
cis[nrow(cis) + 1,] = list(name, 'neg', negR, negLower, negUpper)
}
# Initialize an empty dataframe to store values
cis <- data.frame(name=character(), sign=character(), r=numeric(), lower=numeric(), upper=numeric(), stringsAsFactors=FALSE)
# Iterate over datasets
for(dataset in datasets) {
# Track the name of the current dataset
name <- dataset$task[1]
# For each dataset, apply the function corRatings described above
c(c(posLower, posUpper, posR), c(negLower, negUpper, negR)) %<% corRatings(dataset)
# Append the results to the dataframe
cis[nrow(cis) + 1,] = list(name, 'pos', posR, posLower, posUpper)
cis[nrow(cis) + 1,] = list(name, 'neg', negR, negLower, negUpper)
}
# Initialize an empty dataframe to store values
cis <- data.frame(name=character(), sign=character(), r=numeric(), lower=numeric(), upper=numeric(), stringsAsFactors=FALSE)
# Iterate over datasets
for(dataset in datasets) {
# Track the name of the current dataset
name <- dataset$task[1]
# For each dataset, apply the function corRatings described above
c(c(posLower, posUpper, posR), c(negLower, negUpper, negR)) %>% corRatings(dataset)
# Append the results to the dataframe
cis[nrow(cis) + 1,] = list(name, 'pos', posR, posLower, posUpper)
cis[nrow(cis) + 1,] = list(name, 'neg', negR, negLower, negUpper)
}
library(tidyverse)
library(corrr)
library(boot)
library(zeallot)
library(pander)
library(lme4)
library(lmerTest)
theme_set(theme_bw())
# Initialize an empty dataframe to store values
cis <- data.frame(name=character(), sign=character(), r=numeric(), lower=numeric(), upper=numeric(), stringsAsFactors=FALSE)
# Iterate over datasets
for(dataset in datasets) {
# Track the name of the current dataset
name <- dataset$task[1]
# For each dataset, apply the function corRatings described above
c(c(posLower, posUpper, posR), c(negLower, negUpper, negR)) %<-% corRatings(dataset)
# Append the results to the dataframe
cis[nrow(cis) + 1,] = list(name, 'pos', posR, posLower, posUpper)
cis[nrow(cis) + 1,] = list(name, 'neg', negR, negLower, negUpper)
}
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip()
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +xlim(0.1,0.5)
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +expand_limits(x=0)
cis %>%
ggplot(aes(x=name,
y=r,
ymin=0,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip()
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip()
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +ylim(0.1,0.5)
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +ylim(0.1,1)
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +ylim(0.1,0.6)
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +ylim(0.1,0.6)
datasets <- list(perlman)
R <- 5000
# Bootstrap function, calculating the correlation coefficient for each bootstrapped sample
bootCor <- function(data, i){
d <- data[i,]
rDf <- correlate(d %>% select(-task))
return(rDf[[2,2]])
}
# Split the data by halves of the rating scale, apply the above bootstrap function, and extract confidence intervals
corRatings <- function(data){
# Separate the data into half-scales
# negData <- data %>% filter(status=="antiiconic")%>%select(-status)
# posData <- data %>% filter(status=="not antiiconic")%>%select(-status)
negData <- data %>% filter(rating<0)
posData <- data %>% filter(rating>0)
# Bootstrap the correlation between each negative rating, and the by-item average
negBoot <- boot(negData, bootCor, R=R)
negCI <- boot.ci(negBoot, type="bca")
rNeg <- negBoot$t0
lowerNeg <- negCI$bca[[4]]
upperNeg <- negCI$bca[[5]]
# Bootstrap the correlation between each positive rating, and the by-item average
posBoot <- boot(posData, bootCor, R=R)
rPos <- posBoot$t0
posCI <- boot.ci(posBoot, type="bca")
lowerPos <- posCI$bca[[4]]
upperPos <- posCI$bca[[5]]
return(list(list(lowerPos,upperPos,rPos), list(lowerNeg,upperNeg,rNeg)))
}
# Initialize an empty dataframe to store values
cis <- data.frame(name=character(), sign=character(), r=numeric(), lower=numeric(), upper=numeric(), stringsAsFactors=FALSE)
# Iterate over datasets
for(dataset in datasets) {
# Track the name of the current dataset
name <- dataset$task[1]
# For each dataset, apply the function corRatings described above
c(c(posLower, posUpper, posR), c(negLower, negUpper, negR)) %<-% corRatings(dataset)
# Append the results to the dataframe
cis[nrow(cis) + 1,] = list(name, 'pos', posR, posLower, posUpper)
cis[nrow(cis) + 1,] = list(name, 'neg', negR, negLower, negUpper)
}
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +ylim(0.1,0.6)
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +ylim(0,0.6)
cis %>%
ggplot(aes(x=name,
y=r,
ymin=lower,
ymax=upper,
color=sign)) +
geom_point(position=position_dodge(0.1)) +
geom_errorbar(position=position_dodge(0.1),
width=0.1) +
coord_flip() +ylim(0,0.6)
View(guesses_trans)
View(guesses_words)
View(guessing_res)
guessing_res%>%
select(identifier,score)%>%
unique()->guessing_res
length(guessing_res[score<1/3])
guessing_res
which(guessing_res$score<1/3)
length(which(guessing_res$score<1/3))
knitr::opts_chunk$set(echo = TRUE)
library(plotly)
library(tidyverse)
# for guessing between translations
responses_trans <- read.csv('responses-guessingtrans.csv')
control_items <- c("pyoNpyoN","katai","hayai")
responses_trans%>%
filter(word %in% control_items)%>%
select(Prolific.ID,word,answer,time_taken,Task.Description)%>%
group_by(Prolific.ID)%>%
mutate(check_score=sum(answer=='correct')/sum(answer=='incorrect'|answer=='correct'))%>%
select(-word,-answer)%>%
unique()%>%
# also look at whether they were particularly slow or fast to do the experiment
mutate(deviation_timetaken=time_taken-mean(.$time_taken))%>%
mutate(std_deviation=sd(.$time_taken))->examine_participants
# results from the following participants were excluded
exclude_participants<-c('5b3648e7f726b2000192b3f4','5f350486d0c0764216b6745e','5c426de31ddd660001c99cdd')
guesses_trans <- responses_trans%>%
filter(!(Prolific.ID %in% exclude_participants))
# for guessing between words
guesses_words<-read.csv('responses-guessingwords.csv')
control_items <- c("pyoNpyoN","katai","hisohiso")
guesses_words%>%
filter(word %in% control_items)%>%
select(prolific_ID,word,answer,TimeTaken,TaskDesc)%>%
group_by(prolific_ID)%>%
mutate(check_score=sum(answer=='correct')/sum(answer=='incorrect'|answer=='correct'))%>%
select(-word,-answer)%>%
unique()%>%
# also look at whether they were particularly slow or fast to do the experiment
mutate(deviation_timetaken=TimeTaken-mean(.$TimeTaken))%>%
mutate(std_deviation=sd(.$TimeTaken))->examine_participants
# for ratings
ratings <- read_csv("responses-ratings.csv")
ratings%>%
filter(form=="pyoNpyoN"|form=="katai"|form=="hisohiso")%>%
select(experiment,prolificID,form,rating,taskdesc)->examine
# we can exclude raters with low person-total correlation
# calculate mean rating per word
ratings%>%
group_by(identifier)%>%
mutate(mean_rating=mean(rating))->ratings
participants <- unique(ratings$prolificID)
# get the correlation with the means for each participant
correlations <- c()
for (p in participants){
d <- subset(ratings,prolificID==p)
t <- cor.test(d$rating,d$mean_rating)
coefficient <- t$estimate
correlations <- c(correlations,coefficient)
}
names(correlations) <- participants
# exclude participants with low correlations to the mean
exclude <- names(correlations[which(correlations<=0.2)])
#ratings <- subset(ratings,!(prolificID %in% exclude))
words<-unique(guesses_trans$word_spec)
# see whether the responses differed significantly depending on the answer sentence given
n=0
doubly_tested_words <- c()
weird_words<-c()
for(w in words){
d<-subset(guesses_trans,word_spec==w)
t<-table(d$answer_sen,d$answer)
if (nrow(t)>1){
doubly_tested_words <- c(doubly_tested_words,w)
n=n+1
p_val<-fisher.test(t)$p
if (p_val<0.05){
weird_words<-c(weird_words,w)}
}
}
length(unique(weird_words))
# see whether the responses different signficantly depending on the foil sentence given
for(w in words){
d<-subset(guesses_trans,word_spec==w)
t<-table(d$foil_sen,d$answer)
if (nrow(t)>1){
doubly_tested_words <- c(doubly_tested_words,w)
n=n+1
p_val<-fisher.test(t)$p
if (p_val<0.05){
weird_words<-c(weird_words,w)}
}
}
guesses_words%>%
mutate(word_spec=paste(word,concept,sep="_"))->guesses_words
words<-unique(guesses_words$word_spec)
# see whether the responses differed significantly depending on the answer sentence given
n=0
doubly_tested_words <- c()
weird_words<-c()
for(w in words){
d<-subset(guesses_words,word_spec==w)
t<-table(d$trans,d$answer)
if (nrow(t)>1){
doubly_tested_words <- c(doubly_tested_words,w)
n=n+1
p_val<-fisher.test(t)$p
if (p_val<0.05){
weird_words<-c(weird_words,w)}
}
}
# see whether the responses different signficantly depending on the foil sentence given
for(w in words){
d<-subset(guesses_words,word_spec==w)
t<-table(d$foil,d$answer)
if (nrow(t)>1){
doubly_tested_words <- c(doubly_tested_words,w)
n=n+1
p_val<-fisher.test(t)$p
if (p_val<0.05){
weird_words<-c(weird_words,w)}
}
}
#length(unique(doubly_tested_words))
#length(unique(weird_words))
guesses_words <- subset(guesses_words,!(word_spec %in% weird_words))
guesses_words%>%
select(identifier=word_spec,answer)%>%
group_by(identifier)%>%
mutate(score=sum(answer=="correct")/sum(answer=="correct"|answer=="incorrect"))->guessing_res
guesses_words%>%
select(identifier=word_spec,answer)%>%
group_by(identifier)%>%
mutate(score=sum(answer=="correct")/sum(answer=="correct"|answer=="incorrect"))%>%
select(identifier,score)%>%
unique()->guessing_res
131-15
length(which(guessing_res$score<1/3))
length(which(guessing_res$score<=1/3))
15/116
12/116
guessing_res%>%
filter(score<1/3)->antiiconic
View(antiiconic)
antiiconic
random <- read_csv("responses-randomfoils.csv")
random <- read_csv("results-randomfoils.csv")
random
random%>%
group_by(identifier)%>%
mutate(score=sum(result=="correct")/sum(result=="correct"|result=="incorrect"))
random%>%
group_by(identifier)%>%
mutate(score=sum(result=="correct")/sum(result=="correct"|result=="incorrect"))%>%
select(identifier,score)%>%
unique()
random%>%
group_by(identifier)%>%
mutate(score=sum(result=="correct")/sum(result=="correct"|result=="incorrect"))%>%
select(identifier,score)%>%
unique()->random
random <- read_csv("results-randomfoils.csv")
random%>%
group_by(identifier)%>%
mutate(random_score=sum(result=="correct")/sum(result=="correct"|result=="incorrect"))%>%
select(identifier,score)%>%
unique()->random_res
random%>%
group_by(identifier)%>%
mutate(random_score=sum(result=="correct")/sum(result=="correct"|result=="incorrect"))%>%
select(identifier,random_score)%>%
unique()->random_res
t <- left_join(antiiconic,random_res)
t
ratings%>%
select(identifier,rating)%>%
group_by(identifier)%>%
mutate(mean_rating=mean(rating))->rating_res
View(rating_res)
ratings%>%
select(identifier,rating)%>%
group_by(identifier)%>%
mutate(mean_rating=mean(rating))%>%
select(identifier,mean_rating)%>%
unique()->rating_res
arousal <- read_csv("arousal_ratings")
arousal <- read_csv("arousal_ratings.csv")
arousal
arousal%>%
select(Word,A.Mean.Sum)
arousal%>%
select(Word,A.Mean.Sum)->arousal_ratings
rating_res
arousal%>%
select(Word,A.Mean.Sum)%>%
rename(identifier=Word)->arousal_ratings
left_join(arousal,rating_res)
arousal
inner_join(arousal_ratings,rating_res)
arousal_ratings
ratings
ratings%>%
select(trans,rating)
ratings%>%
ungroup()%>%
select(trans,rating)->test
test
ratings%>%
ungroup()%>%
select(trans,rating)%>%
mutate(identifier=str_to_lower(trans))->test
test
inner_join(arousal_ratings,rating_res)
arousal_ratings
inner_join(arousal_ratings,test)
t <- inner_join(arousal_ratings,test)
unique(t$identifier)
t
cor.test(t$rating,t$A.Mean.Sum)
plot(t$rating,t$A.Mean.Sum)
cor.test(t$rating,t$A.Mean.Sum)
guessing_words
guessing_res
hist(guessing_res$score)
hist(guessing_res$score,xlim = 0)
hist(guessing_res$score,xlim = c(0,1))
rating_res
hist(rating_res$mean_rating,xlim = c(0,7))
hist(rating_res$mean_rating,xlim = c(0,6))
guessing_res
length(which(guessing_res$score<1/3)
length(which(guessing_res$score<1/3))
length(guessing_res$score[which(guessing_res$score<1/3)])
length(guessing_res$score[which(guessing_res$score>2/3)])
25/116
length(guessing_res$score[which(guessing_res$score>=2/3)])
length(guessing_res$score[which(guessing_res$score<=2/3)])
length(guessing_res$score[which(guessing_res$score<=1/3)])
15/116
31/116
15/116
31/116
shiny::runApp('C:/Users/bonmc643/CookingBlog')
runApp('C:/Users/bonmc643/CookingBlog')
runApp('C:/Users/bonmc643/CookingBlog')