-
Notifications
You must be signed in to change notification settings - Fork 0
/
Gender_project_ModelVsHumans_IAA.R
446 lines (308 loc) · 15.7 KB
/
Gender_project_ModelVsHumans_IAA.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
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
Model_vs_human_data_complete_28pp_NA_removed <- read.csv("~/Desktop/Model_vs_human_data_complete_28pp_NA_removed.csv", sep=";")
Model_vs_human_data_complete_28pp <- read.csv("/Users/nataliaresende/Dropbox/Gender_Model_project_tensorflow/Model_vs_human_data_complete_28pp.csv", sep=";")
dtNA=Model_vs_human_data_complete_28pp_NA_removed
dta=Model_vs_human_data_complete_28pp
View(dt)
library(tidyverse)
names(dt)[names(dt) == "item_pp"] <- "word_pp"
names(dtNA)[names(dt) == "item_pp"] <- "word_pp"
names(dt)
dt$simulation=as.factor(dt$simulation)
dt$item=as.factor(dt$item)
dt$word=as.factor(dt$word)
dt$label=as.numeric(dt$label)
dt$categories=as.factor(dt$categories)
dt$ending=as.factor(dt$ending)
dt$easy_diff=as.factor(dt$easy_diff)
dt$word_pp=as.factor(dt$word_pp)
dt$label_pp=as.numeric(dt$label_pp)
dt$categories_pp=as.factor(dt$categories_pp)
dt$ending_pp=as.factor(dt$ending_pp)
dt$easy_dif_pp=as.factor(dt$easy_dif_pp)
View(dt)
attach(dt)
library(irr)
library(ggplot2)
library(plyr)
library(broom)
library(tibble)
#Regular
dt$label <- as.factor(ifelse(dt$label == '1', 'Fem', ifelse(dt$label == '0', 'Masc', NA)))
View(dt$label)
dt$label_pp <- as.factor(ifelse(dt$label_pp == '1', 'Fem', ifelse(dt$label_pp == '0', 'Masc', NA)))
View(dt$label_pp)
dtNA$label <- as.factor(ifelse(dtNA$label == '1', 'Fem', ifelse(dtNA$label == '0', 'Masc', NA)))
View(dtNA$label)
dtNA$label_pp <- as.factor(ifelse(dtNA$label_pp == '1', 'Fem', ifelse(dtNA$label_pp == '0', 'Masc', NA)))
View(dtNA$label_pp)
par(mfrow=c(1,2))
attach(dt)
ggplot(dt, aes(x= ending, group=label)) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count") +
geom_text(aes( label = scales::percent(..prop..),
y= ..prop.. ), stat= "count", vjust = -.5) +
labs(y = "Percent", x='Form Categories', fill="Form categories") +
facet_grid(~label) +
scale_y_continuous(labels = scales::percent)
attach(dtNA)
ggplot(dtNA, aes(x= ending_pp, group=label_pp)) +
geom_bar(aes(y = ..prop.., fill = factor(..x..)), stat="count") +
geom_text(aes( label = scales::percent(..prop..),
y= ..prop.. ), stat= "count", vjust = -.5) +
labs(y = "Percent", x='Form Categories', fill="Form categories") +
facet_grid(~label_pp) + scale_y_continuous(labels = scales::percent)
#Model's and subjects' answers for regular nouns
Model_answers_reg=subset(dt, categories=="Reg", select=c(label))
Subj_answers_reg=subset(dt, categories_pp=="Reg", select=c(label_pp))
#table for model's and subject comparison regular nouns
Table_answers_Reg_ModelVsHumans=cbind(Model_answers_reg, Subj_answers_reg)
View(Table_answers_Reg_ModelVsHumans)
Table_answers_Reg_ModelVsHumans
#kappa
kappa2(Table_answers_Reg_ModelVsHumans, 'unweighted') #kappa= 0.00149 z = 0.312 and p-value = 0.975
kappa2(Table_answers_Reg_ModelVsHumans, 'equal') #kappa= 0.00149 z = 0.312 and p-value = 0.975
#Transp/fem
#Model's and subjects' answers for transparent feminine nouns
Model_answers_Transp_fem = subset(dt, categories == "TrFem", select=c(label))
Subj_answers_Transp_fem=subset(dt, categories_pp =="Transp/fem", select=c(label_pp))
#table for model's and subject comparison transparent feminine nouns
Table_answers_Transp_fem_ModelVsHumans=cbind(Model_answers_Transp_fem, Subj_answers_Transp_fem)
View(Table_answers_Transp_fem_ModelVsHumans)
#Kappa
kappa2(Table_answers_Transp_fem_ModelVsHumans, 'unweighted') #kappa=-0.0603 z = -1.17 p-value = 0.244
kappa2(Table_answers_Transp_fem_ModelVsHumans, 'equal') #kappa=-0.0603 z = -1.17 p-value = 0.244
#Transp/Irr
#Model's and subjects' answers for transparent feminine nouns
Model_answers_Transp_irr = subset(dt, categories=="Transp/Irr", select=c(label))
Subj_answers_Transp_irr=subset(dt, categories_pp=="Transp/Irr", select=c(label_pp))
#table for model's and subject comparison transparent feminine nouns
Table_answers_Transp_irr_ModelVsHumans=cbind(Model_answers_Transp_irr, Subj_answers_Transp_irr)
View(Table_answers_Transp_irr_ModelVsHumans)
#Kappa
kappa2(Table_answers_Transp_irr_ModelVsHumans, 'unweighted') #Kappa = -0.0959 z = -1.75 p-value = 0.0801
kappa2(Table_answers_Transp_irr_ModelVsHumans, 'equal') #Kappa = -0.0959 z = -1.75 p-value = 0.0801
#Transp/Masc
#Model's and subjects' answers for transparent feminine nouns
Model_answers_Transp_masc = subset(dt, categories=="Transp/Masc", select=c(label))
Subj_answers_Transp_masc=subset(dt, categories_pp=="Transp/Masc", select=c(label_pp))
#table for model's and subject comparison transparent feminine nouns
Table_answers_Transp_masc_ModelVsHumans=cbind(Model_answers_Transp_masc, Subj_answers_Transp_masc)
View(TTable_answers_Transp_masc_ModelVsHumans)
#Kappa
kappa2(Table_answers_Transp_masc_ModelVsHumans, 'unweighted') #Kappa = -0.026 z = -0.74 p-value = 0.459
kappa2(Table_answers_Transp_masc_ModelVsHumans, 'equal') #Kappa = -0.026 z = -0.74 p-value = 0.459
#tables
Model_answers_a=subset(dt, ending=='-a' & easy_diff=="difficult", select=c(label))
table_a=table(Model_answers_a)
table_a #56 (0) e 28(1)
prop.table(table_a)*100
Model_answers_a=subset(dt, ending=='-a' & easy_diff=='easy', select=c(label))
table_a=table(Model_answers_a)
table_a #56 (0) e 28(1)
prop.table(table_a)*100 #56 (0) e 28(1)
Model_answers_o=subset(dt, ending=='-o' & easy_diff=='easy', select=c(label))
table_o=table(Model_answers_o)
table_o #56 e 0
prop.table(table_o)*100
Model_answers_o=subset(dt, ending=='-o' & easy_diff=='difficult', select=c(label))
table_o=table(Model_answers_o)
table_o #84 e 28
prop.table(table_o)
Model_answers_agem=subset(dt, ending=='-agem' & easy_diff=='difficult', select=c(label))
table_agem=table(Model_answers_agem)
table_agem #56 28
prop.table(table_agem)*100
Model_answers_agem=subset(dt, ending=='-agem' & easy_diff=='easy', select=c(label))
table_agem=table(Model_answers_agem)
table_agem #28 e 56
prop.table(table_agem)*100
Model_answers_ade=subset(dt, ending=='-ade' & easy_diff=='difficult', select=c(label))
table_ade=table(Model_answers_ade)
table_ade #0 e 84
prop.table(table_ade)*100
Model_answers_ade=subset(dt, ending=='-ade' & easy_diff=='easy', select=c(label))
table_ade=table(Model_answers_ade)
table_ade #56 e 28
prop.table(table_ade)*100
Model_answers_ume=subset(dt, ending=='-ume' & easy_diff=='difficult', select=c(label))
table_ume=table(Model_answers_ume)
table_ume #28 e 28
prop.table(table_ume)*100
Model_answers_ume=subset(dt, ending=='-ume' & easy_diff=='easy', select=c(label))
table_ume=table(Model_answers_ume)
table_ume #0 e 112
prop.table(table_ume)*100
Model_answers_or=subset(dt, ending=='-or' & easy_diff=='difficult', select=c(label))
table_or=table(Model_answers_or)
table_or #28 e 56
prop.table(table_or)*100
Model_answers_or=subset(dt, ending=='-or' & easy_diff=='easy', select=c(label))
table_or=table(Model_answers_or)
table_or #56 e 28
prop.table(table_or)*100
Model_answers_ema=subset(dt, ending=='-ema' & easy_diff=='difficult', select=c(label))
table_ema=table(Model_answers_ema)
table_ema
prop.table(table_ema)*100
Model_answers_ema=subset(dt, ending=='-ema' & easy_diff=='easy', select=c(label))
table_ema=table(Model_answers_ema)
table_ema
prop.table(table_ema)*100
Model_answers_ao=subset(dt, ending=='-??o' & easy_diff=='easy', select=c(label))
table_ao=table(Model_answers_ao)
table_ao
prop.table(table_ao)*100
Model_answers_ao=subset(dt, ending=='-o' & easy_diff=='difficult', select=c(label))
table_ao=table(Model_answers_ao)
table_ao
prop.table(table_ao)*100
#kappa to check agreement for each noun ending
library(irr)
#Model's and subjects' answers for regular nouns
Model_answers_a=subset(dt, ending=='-a' & easy_diff=='difficult', select=c(label))
Subject_answers_a=subset(dt, ending_pp=='-a' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_a=cbind(Model_answers_a, Subject_answers_a)
agree(Table_answers_a) #39%
kappa2(Table_answers_a, 'unweighted')
Model_answers_a=subset(dt, ending=='-a' & easy_diff=='easy', select=c(label))
Subject_answers_a=subset(dt, ending_pp=='-a' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_a=cbind(Model_answers_a, Subject_answers_a)
agree(Table_answers_a) #41%
kappa2(Table_answers_a, 'unweighted')
Model_answers_o=subset(dt, ending=='-o' & easy_diff=='difficult', select=c(label))
Subject_answers_o=subset(dt, ending_pp=='-o' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_o=cbind(Model_answers_o, Subject_answers_o)
agree(Table_answers_o) #67.9
kappa2(Table_answers_o, 'unweighted')
Model_answers_o=subset(dt, ending=='-o' & easy_diff=='easy', select=c(label))
Subject_answers_o=subset(dt, ending_pp=='-o' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_o=cbind(Model_answers_o, Subject_answers_o)
agree(Table_answers_o) #98.2
kappa2(Table_answers_o, 'unweighted')
Model_answers_or=subset(dt, ending=='-or' & easy_diff=='difficult', select=c(label))
Subject_answers_or=subset(dt, ending_pp=='-or' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_or=cbind(Model_answers_or, Subject_answers_or)
agree(Table_answers_or) #40.5
kappa2(Table_answers_or, 'unweighted')
Model_answers_or=subset(dt, ending=='-or' & easy_diff=='easy', select=c(label))
Subject_answers_or=subset(dt, ending_pp=='-or' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_or=cbind(Model_answers_or, Subject_answers_or)
agree(Table_answers_or) #63.1
kappa2(Table_answers_or, 'unweighted')
summary(dt$ending)
Model_answers_ade=subset(dtNA, ending=='-ade' & easy_diff=='difficult', select=c(label))
Subject_answers_ade=subset(dtNA, ending_pp=='-ade' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_ade=cbind(Model_answers_ade, Subject_answers_ade)
agree(Table_answers_ade) #71.1
kappa2(Table_answers_ade, 'unweighted') #no answer
Model_answers_ade=subset(dt, ending=='-ade' & easy_diff=='easy', select=c(label))
Subject_answers_ade=subset(dt, ending_pp=='-ade' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_ade=cbind(Model_answers_ade, Subject_answers_ade)
agree(Table_answers_ade) #58.3
kappa2(Table_answers_ade, 'unweighted') #k=-0,0194, z=-0.184, p=0.854
Model_answers_agem=subset(dt, ending=='-agem' & easy_diff=='difficult', select=c(label))
Subject_answers_agem=subset(dt, ending_pp=='-agem' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_agem=cbind(Model_answers_agem, Subject_answers_agem)
agree(Table_answers_agem) #41.7
kappa2(Table_answers_agem, 'unweighted')
Model_answers_agem=subset(dt, ending=='-agem' & easy_diff=='easy', select=c(label))
Subject_answers_agem=subset(dt, ending_pp=='-agem' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_agem=cbind(Model_answers_agem, Subject_answers_agem)
agree(Table_answers_agem) #56%
Model_answers_ao=subset(dt, ending=='-??o' & easy_diff=='difficult', select=c(label))
Subject_answers_ao=subset(dt, ending_pp=='-??o' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_ao=cbind(Model_answers_ao, Subject_answers_ao)
agree(Table_answers_ao) #341
kappa2(Table_answers_ao, 'unweighted')
Model_answers_ao=subset(dt, ending=='-??o' & easy_diff=='easy', select=c(label))
Subject_answers_ao=subset(dt, ending_pp=='-??o' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_ao=cbind(Model_answers_ao, Subject_answers_ao)
agree(Table_answers_ao) #42.2
kappa2(Table_answers_ao, 'unweighted')
Model_answers_ema=subset(dt, ending=='-ema' & easy_diff=='difficult', select=c(label))
Subject_answers_ema=subset(dt, ending_pp=='-ema' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_ema=cbind(Model_answers_ema, Subject_answers_ema)
agree(Table_answers_ema) #48.2
kappa2(Table_answers_ema, 'unweighted')
Model_answers_ema=subset(dt, ending=='-ema' & easy_diff=='easy', select=c(label))
Subject_answers_ema=subset(dt, ending_pp=='-ema' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_ema=cbind(Model_answers_ema, Subject_answers_ema)
agree(Table_answers_ema) #61.4
kappa2(Table_answers_ema, 'unweighted')
Model_answers_ume=subset(dt, ending=='-ume' & easy_diff=='difficult', select=c(label))
Subject_answers_ume=subset(dt, ending_pp=='-ume' & easy_dif_pp=='difficult', select=c(label_pp))
Table_answers_ume=cbind(Model_answers_ume, Subject_answers_ume)
agree(Table_answers_ume) #58.9
kappa2(Table_answers_ume, 'unweighted')
Model_answers_ume=subset(dt, ending=='-ume' & easy_diff=='easy', select=c(label))
Subject_answers_ume=subset(dt, ending_pp=='-ume' & easy_dif_pp=='easy', select=c(label_pp))
Table_answers_ume=cbind(Model_answers_ume, Subject_answers_ume)
kappa2(Table_answers_ume, 'unweighted')
agree(Table_answers_ume) #21.6
kappa2(Table_answers_ume, 'unweighted')
#collapsed
Model_answers_a=subset(dtNA, ending=='-a', select=c(label))
Subject_answers_a=subset(dtNA, ending_pp=='-a', select=c(label_pp))
agree(Model_answers_a,Subject_answers_a)
Model_answers_o=subset(dtNA, ending=='-o', select=c(label))
Subject_answers_o=subset(dtNA, ending_pp=='-o', select=c(label_pp))
agree(Model_answers_o,Subject_answers_o)
Model_answers_agem=subset(dtNA, ending=='-agem', select=c(label))
Subject_answers_agem=subset(dtNA, ending_pp=='-agem', select=c(label_pp))
Table=cbind(Model_answers_agem,Subject_answers_agem)
names(Table)
agree(Model_answers_agem,Subject_answers_agem, tolerance = 0)
names(dtNA)
attach(dtNA)
library("ggpubr")
ggscatter(dt, x = "label", y = "label_pp",
add = "reg.line", conf.int = TRUE,
cor.coef = TRUE, cor.method = "pearson",
xlab = "Model choices", ylab = "Participants' choices")
#interaction plots
Gender_data_28_simulations <- read.csv("~/Desktop/Book_chapter_Gender_simulation/Gender_data_28_simulations.csv", sep=";")
dt=Gender_data_28_simulations
dt$categories=ifelse(dt$categories=='Transp/fem','Transparent',
ifelse(dt$categories=='Transp/Masc', 'Transparent',
ifelse(dt$categories=='Transp/Irr', 'Irregular',
ifelse(dt$categories=='Reg', 'Reg',
as.factor(dt$categories)))))
dt$ending_frequency=as.numeric(dt$ending_frequency)
is.numeric(dt$ending_frequency)
dt$neighborFrquency=as.numeric(dt$neighborFrquency)
is.numeric(dt$neighborFrquency)
dt$neighborDensity=as.numeric(dt$neighborDensity)
is.numeric(dt$neighborDensity)
attach(dt)
View(dt)
ggplot() +
aes(x = GenderDecision, color = categories, group = categories, y = neighborFrquency ) +
stat_summary(fun.y = mean, geom = "point") +
stat_summary(fun.y = mean, geom = "line")
ggplot() +
aes(x = GenderDecision, color = categories, group = categories, y = neighborFrquency ) +
stat_summary(fun.y = mean, geom = "point") +
stat_summary(fun.y = mean, geom = "line")
ggplot() +
aes(x = dta$, color = categories, group = categories, y = neighborFrquency ) +
stat_summary(fun.y = mean, geom = "point") +
stat_summary(fun.y = mean, geom = "line")
View(dta)
#GLMERs
library(lme4)
dataset=dt
dt$GenderDecision=ifelse(dt$GenderDecision=='yes','1',
ifelse(dt$GenderDecision=='no', '0',
as.numeric(dt$GenderDecision)))
View(dt)
dt$GenderDecision=as.numeric(dt$GenderDecision)
is.numeric(dt$GenderDecision)
dt$neighborFrquency=scale(dt$neighborFrquency, center= TRUE, scale = TRUE)
dt$neighborDensity=scale(dt$neighborDensity, center= TRUE, scale = TRUE)
dt$ending_frequency=as.numeric(dt$ending_frequency, center= TRUE, scale = TRUE)
attach(dt)
gm_all <- all_fit(gm1)
m1 <- glmer(GenderDecision ~ ending_frequency+categories+neighborDensity+(1|simulation) + (1|item),family=binomial(link = "logit"), data = dt)
summary(m1)
m1.1 <- glmer(GenderDecision ~ ending_frequency+categories+neighborDensity+(1 |simulation) + (1|item),family=binomial(link = "logit"), data = dt, control=glmerControl(optCtrl=list(maxfun=2000000)))
m2 <- glmer(GenderDecision ~ ending_frequency+categories+neighborDensity+neighborFrquency+(1 |simulation) + (1|item),family=binomial(link = "logit"), data = dt, control=glmerControl(optimizer="bobyqa",optCtrl=list(maxfun=2e5)))