-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdata-explorations.Rmd
1082 lines (887 loc) · 42 KB
/
data-explorations.Rmd
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
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Spanish CDI explorations"
author: "Paulina & Mike"
date: "2022-10-13"
output: html_document
---
# Intro
Goal of this project is to use the five Spanish CDI datasets in Wordbank to try and investigate dialect variation in Spanish language acquisition.
Here are some potential questions:
* Do the sumscores across the intersecting items look the same at the population level (correcting for demographics)?
* Do individual common items have similar psychometric / developmental properties?
* What are the properties of items with the same unilemma but different item definitions?
* What are the properties of items that are not shared across dialects? (Could also compare Spanish (Mexican) between monolingual and bilingual populations)
```{r setup}
library(tidyverse)
library(wordbankr)
library(arm)
```
# Data loading
Start with summary scores.
```{r}
eu_ws <- get_administration_data(language = "Spanish (European)",
form = "WS",
include_demographic_info = TRUE,
include_language_exposure = TRUE) %>%
filter(language_exposures=="NULL")
mx_ws <- get_administration_data(language = "Spanish (Mexican)",
form = "WS",
include_demographic_info = TRUE,
include_language_exposure = TRUE) %>%
filter(language_exposures=="NULL")
pr_ws <- get_administration_data(language = "Spanish (Peruvian)",
form = "WS",
include_demographic_info = TRUE,
include_language_exposure = TRUE) %>%
filter(language_exposures=="NULL")
ar_ws <- get_administration_data(language = "Spanish (Argentinian)",
form = "WS",
include_demographic_info = TRUE,
include_language_exposure = TRUE) %>%
filter(language_exposures=="NULL")
sp_ws <- bind_rows(eu_ws,
mx_ws,
pr_ws,
ar_ws)
```
Make a plot!
```{r}
ggplot(sp_ws, aes(x = age, y = production)) +
geom_jitter(width = .2, alpha = .2) +
geom_smooth() +
facet_wrap(~language)
```
# Comparison on the intersection of items
QUESTION: Do the sumscores across the intersecting items look the same at the population level (correcting for demographics)?
```{r}
langs <- c("Spanish (European)", "Spanish (Mexican)", "Spanish (Peruvian)", "Spanish (Argentinian)")
d_ws <- map_df(langs, function(x) get_instrument_data(language = x,
form = "WS",
administration_info = TRUE,
item_info = TRUE,
include_language_exposure = TRUE)) %>%
filter(language_exposures == "NULL")
```
Find the overlapping unilemmas.
For now, pull those unilemmas that are 1) in all languages, 2) only once in each language.
```{r}
items <- map_df(langs, function(x) get_item_data(language = x, form = "WS"))
intersection <- items |>
group_by(uni_lemma) |>
summarise(n_langs = length(unique(language)),
n = n()) |>
filter(n_langs == 4, n == 4) |>
pull(uni_lemma)
# 224 common items
```
Filter data and replot.
```{r}
ggplot(ms_ws, aes(x = age, y = produces)) +
geom_jitter(width = .2, alpha = .2) +
geom_smooth() +
facet_wrap(~language)
```
# Comparison of developmental properties
QUESTION: Do individual common items have similar psychometric / developmental properties?
```{r}
source("scripts/fit_models.R")
wb_data <- d_ws |>
filter(uni_lemma %in% intersection) |>
group_by(uni_lemma, language, age) |>
summarise(total = n(),
num_true = sum(produces, na.rm = TRUE))
aoas <- fit_aoas(wb_data)
```
DIF
```{r}
#language <- round(runif(nrow(df.data))) |> as.factor()
#fit.2plmulti <- multipleGroup(df.data,
# model = modstr,
# itemtype = "2PL",
# group = grp,
# verbose = FALSE)
```
```{r}
ggplot(data = aoas) +
geom_histogram(aes(x = aoa))+
facet_wrap(~language)
```
Calculate correlations between languages
```{r}
cor_data <- aoas |>
pivot_wider(id_cols = uni_lemma,
names_from = language,
values_from = aoa) |>
ungroup()
correl <- cor(cor_data |> dplyr::select(-"uni_lemma"), use = "complete.obs")
```
Plot correlogram
```{r}
library(corrgram)
corrgram(correl, type = "cor", panel = panel.cor)
```
```{r}
plot_data <- cor_data |>
pivot_longer(cols = c(`Spanish (Argentinian)`, `Spanish (Mexican)`, `Spanish (Peruvian)`),
names_to = "Dialect")
ggplot(plot_data, aes(x = `Spanish (European)`, y = value, col = Dialect)) +
geom_abline(slope = 1, intercept = 0, lty = "dashed", col = "#444444") +
geom_point(alpha=.3) +
geom_smooth(method = "lm") +
theme_classic() +
theme(legend.position = "bottom") +
labs(x = "Spanish (European) AoA",
y = "Spanish (Latin American) AoA") +
coord_cartesian(xlim = c(0, 40), ylim = c(0, 40))
```
Calculate differences in age of acquisition (AoA) between all dialects for each unilemma
```{r}
clean_aoas <- aoas |>
dplyr::select(uni_lemma, language, aoa) |>
pivot_wider(names_from = language, values_from = aoa)
difference_argentinian_european <- data.frame(difference_argentinian_european = c(clean_aoas$`Spanish (Argentinian)`- clean_aoas$`Spanish (European)`))
difference_argentinian_mexican <- data.frame(difference_argentinian_mexican = c(clean_aoas$`Spanish (Argentinian)`- clean_aoas$`Spanish (Mexican)`))
difference_argentinian_peruvian <- data.frame(difference_argentinian_peruvian = c(clean_aoas$`Spanish (Argentinian)`- clean_aoas$`Spanish (Peruvian)`))
difference_european_mexican <- data.frame(difference_european_mexican = c(clean_aoas$`Spanish (European)`- clean_aoas$`Spanish (Mexican)`))
difference_european_peruvian <- data.frame(difference_european_peruvian = c(clean_aoas$`Spanish (European)`- clean_aoas$`Spanish (Peruvian)`))
difference_mexican_peruvian <- data.frame(difference_mexican_peruvian = c(clean_aoas$`Spanish (Mexican)`- clean_aoas$`Spanish (Peruvian)`))
difference_AoA <- data.frame(uni_lemma = c(clean_aoas$uni_lemma), difference_argentinian_european, difference_argentinian_mexican, difference_argentinian_peruvian, difference_european_mexican, difference_european_peruvian, difference_mexican_peruvian)
```
Comparing identical/nonidentical surface forms
```{r}
# Filter "items" data-set to "words" only, then filter again so that it contains only those uni_lemmas contained in the "aoas" data frame
items_filtered <- filter(items, items$item_kind == 'word') %>%
filter(uni_lemma %in% c((clean_aoas$uni_lemma)))
# Arrange "uni_lemma" and "language" columns to match with order of said columns in "aoas" data frame
arrange(items_filtered, uni_lemma, language)
# Trim dataframe to include only necessary columns
items_filtered <- items_filtered %>%
dplyr::select(language, item_definition, uni_lemma)
# Clean up discrepancies and match up with AoA data in a CSV file. Then read into a new data frame
uni_lemma_aoa <- read.csv("cleaned_items_aoa.csv")
# Pivot into a wider dataframe which includes language, uni_lemma, and cleaned surface forms
cleaned_uni_lemma_wider <- uni_lemma_aoa %>%
dplyr::select(language, uni_lemma, aoa, cleaned_item) %>%
pivot_wider(names_from = language, values_from = cleaned_item, uni_lemma)
# Select for just European Spanish and Mexican Spanish
Eu_Mx <- cleaned_uni_lemma_wider %>%
dplyr::select(uni_lemma, `Spanish (European)`, `Spanish (Mexican)`)
#Join in AoA data
clean_aoas_Eu_Mx <- clean_aoas %>%
dplyr::select(uni_lemma, `Spanish (European)`, `Spanish (Mexican)`) %>%
left_join(Eu_Mx, join_by(uni_lemma))
# Filter for identical surface forms and calculate correlation
Eu_Mx_Identical <- clean_aoas_Eu_Mx %>%
filter(`Spanish (European).y` == `Spanish (Mexican).y`)
# Calculate correlation of AoA values
correlation_Eu_Mx_Identical <- cor(Eu_Mx_Identical$`Spanish (European).x`, Eu_Mx_Identical$`Spanish (Mexican).x`)
# Filter for non-identical surface forms
Eu_Mx_NonIdentical <- clean_aoas_Eu_Mx %>%
filter(`Spanish (European).y` != `Spanish (Mexican).y`)
# Calculate correlation
correlation_Eu_Mx_NonIdentical <- cor(Eu_Mx_NonIdentical$`Spanish (European).x`, Eu_Mx_NonIdentical$`Spanish (Mexican).x`)
```
t-test for AoA differences
```{r}
# Generate a data frame with all AoA and uni_lemma values
uni_lemma_aoa_wider <- uni_lemma_aoa %>%
dplyr::select(language, uni_lemma, aoa, cleaned_item) %>%
pivot_wider(names_from = language, values_from = cleaned_item, uni_lemma)
uni_lemma_aoa_master <- clean_aoas %>%
left_join(uni_lemma_aoa_wider, join_by(uni_lemma))
# Filter to identical and nonidentical surface forms for all dialect pairings
Eu_Ar_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` == `Spanish (Argentinian).y`)
Eu_Ar_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` != `Spanish (Argentinian).y`)
Eu_Pr_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` == `Spanish (Peruvian).y`)
Eu_Pr_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` != `Spanish (Peruvian).y`)
Mx_Ar_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` == `Spanish (Argentinian).y`)
Mx_Ar_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` != `Spanish (Argentinian).y`)
Mx_Pr_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` == `Spanish (Peruvian).y`)
Mx_Pr_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` != `Spanish (Peruvian).y`)
Pr_Ar_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (Peruvian).y` == `Spanish (Argentinian).y`)
Pr_Ar_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (Peruvian).y` != `Spanish (Argentinian).y`)
# Generate vector of differences for each possible dialect pairing
dif_Eu_Mx_Identical <- Eu_Mx_Identical$`Spanish (European).x` - Eu_Mx_Identical$`Spanish (Mexican).x`
dif_Eu_Mx_NonIdentical <- Eu_Mx_NonIdentical$`Spanish (European).x` - Eu_Mx_NonIdentical$`Spanish (Mexican).x`
dif_Eu_Ar_Identical <- Eu_Ar_Identical$`Spanish (European).x`- Eu_Ar_Identical$`Spanish (Argentinian).x`
dif_Eu_Ar_NonIdentical <- Eu_Ar_NonIdentical$`Spanish (European).x` - Eu_Ar_NonIdentical$`Spanish (Argentinian).x`
dif_Eu_Pr_Identical <- Eu_Pr_Identical$`Spanish (European).x` - Eu_Pr_Identical$`Spanish (Peruvian).x`
dif_Eu_Pr_NonIdentical <- Eu_Pr_NonIdentical$`Spanish (European).x` - Eu_Pr_NonIdentical$`Spanish (Peruvian).x`
dif_Mx_Ar_Identical <- Mx_Ar_Identical$`Spanish (Mexican).x` - Mx_Ar_Identical$`Spanish (Argentinian).x`
dif_Mx_Ar_NonIdentical <- Mx_Ar_NonIdentical$`Spanish (Mexican).x` - Mx_Ar_NonIdentical$`Spanish (Argentinian).x`
dif_Mx_Pr_Identical <- Mx_Pr_Identical$`Spanish (Mexican).x` - Mx_Pr_Identical$`Spanish (Peruvian).x`
dif_Mx_Pr_NonIdentical <- Mx_Pr_NonIdentical$`Spanish (Mexican).x` - Mx_Pr_NonIdentical$`Spanish (Peruvian).x`
dif_Pr_Ar_Identical <- Pr_Ar_Identical$`Spanish (Peruvian).x` - Pr_Ar_Identical$`Spanish (Argentinian).x`
dif_Pr_Ar_NonIdentical <- Pr_Ar_NonIdentical$`Spanish (Peruvian).x` - Pr_Ar_NonIdentical$`Spanish (Argentinian).x`
# Perform a t-test for these differences and place p-values into a data frame
Identical_NonIdentical_p_values <- data.frame(
Eu_Mx = c(t.test(dif_Eu_Mx_Identical, dif_Eu_Mx_NonIdentical)$p.value),
Eu_Ar = c(t.test(dif_Eu_Ar_Identical, dif_Eu_Ar_NonIdentical)$p.value),
Eu_Pr = c(t.test(dif_Eu_Pr_Identical, dif_Eu_Pr_NonIdentical)$p.value),
Mx_Ar = c(t.test(dif_Mx_Ar_Identical, dif_Mx_Ar_NonIdentical)$p.value),
Mx_Pr = c(t.test(dif_Mx_Pr_Identical, dif_Mx_Pr_NonIdentical)$p.value),
Pr_Ar = c(t.test(dif_Pr_Ar_Identical, dif_Pr_Ar_NonIdentical)$p.value)
)
```
Total Identical/NonIdentical Items
```{r}
AoA_Totals <- data.frame(
Eu_Ar_I = c(nrow(Eu_Ar_Identical)),
Eu_Ar_NI = c(nrow(Eu_Ar_NonIdentical)),
Eu_Mx_I = c(nrow(Eu_Ar_Identical)),
Eu_Mx_NI = c(nrow(Eu_Ar_NonIdentical)),
Eu_Pr_I = c(nrow(Eu_Pr_Identical)),
Eu_Pr_NI = c(nrow(Eu_Pr_NonIdentical)),
Mx_Ar_I = c(nrow(Mx_Ar_Identical)),
Mx_Ar_NI = c(nrow(Mx_Ar_NonIdentical)),
Mx_Pr_I = c(nrow(Mx_Pr_Identical)),
Mx_Pr_NI = c(nrow(Mx_Pr_NonIdentical)),
Pr_Ar_I = c(nrow(Pr_Ar_Identical)),
Pr_Ar_NI = c(nrow(Pr_Ar_NonIdentical))
)
```
Permutation testing on dialect correlations
```{r}
# Function to perform permutation test
perm_test <- function(dialect1, dialect2, n_permutations = 10000) {
# Remove NA values
valid_indices <- complete.cases(dialect1, dialect2)
dialect1 <- dialect1[valid_indices]
dialect2 <- dialect2[valid_indices]
# Check for zero variance
if (var(dialect1) == 0 | var(dialect2) == 0) {
return(NA)
}
observed_correlation <- cor(dialect1, dialect2)
permuted_correlations <- numeric(n_permutations)
for (i in 1:n_permutations) {
permuted_dialect2 <- sample(dialect2)
permuted_correlations[i] <- cor(dialect1, permuted_dialect2)
}
p_value <- mean(permuted_correlations >= observed_correlation)
return(p_value)
}
# Extract the data for each dialect
argentinian <- cor_data$`Spanish (Argentinian)`
european <- cor_data$`Spanish (European)`
mexican <- cor_data$`Spanish (Mexican)`
peruvian <- cor_data$`Spanish (Peruvian)`
# Create an empty data frame to store p-values
p_values <- data.frame(
Dialect1 = character(),
Dialect2 = character(),
P_Value = numeric(),
stringsAsFactors = FALSE
)
# Perform permutation tests for each pair of dialects
dialects <- list(argentinian, european, mexican, peruvian)
dialect_names <- c("Spanish (Argentinian)", "Spanish (European)", "Spanish (Mexican)", "Spanish (Peruvian)")
for (i in 1:length(dialects)) {
for (j in i:length(dialects)) {
if (i != j) {
p_val <- perm_test(dialects[[i]], dialects[[j]])
p_values <- data.frame(rbind(p_values, data.frame(Dialect1 = dialect_names[i], Dialect2 = dialect_names[j], P_Value = p_val)))
}
}
}
```
Regression for all 4 dialects
```{r}
#Load gamlss library
library(gamlss)
#Clean sp_ws data frame to include only necessary rows
sp_ws_minimal <- dplyr::select(sp_ws, age, production, language)
#Find prop_produced for each dialect
items_filtered <- filter(items, items$item_kind == 'word')
sp_ws_left_join <- left_join(sp_ws_minimal,(items_filtered |> group_by(language) |> summarise(n = n())))
sp_ws_prop_produced <- mutate(sp_ws_left_join, prop_produced = sp_ws_left_join$production / sp_ws_left_join$n)
#Run regression
gam_mod <- gamlss(prop_produced ~ pbm(age, lambda = 10000) * as.factor(language),
sigma.formula = ~ pbm(age, lambda = 10000) * as.factor(language),
data = sp_ws_prop_produced)
summary(gam_mod)
```
Single dialect regression/visualization
```{r}
# Filter data for each dialect and add a Dialect column
sp_ws_prop_produced_Eu <- sp_ws_prop_produced %>%
filter(language == "Spanish (European)")
sp_ws_prop_produced_Ar <- sp_ws_prop_produced %>%
filter(language == "Spanish (Argentinian)")
sp_ws_prop_produced_Mx <- sp_ws_prop_produced %>%
filter(language == "Spanish (Mexican)")
sp_ws_prop_produced_Pr <- sp_ws_prop_produced %>%
filter(language == "Spanish (Peruvian)")
# Fit GAMLSS models for each dialect
gam_mod_Eu <- gamlss(prop_produced ~ pb(age, lambda = 10000),
sigma.formula = ~ pb(age, lambda = 10000),
data = sp_ws_prop_produced_Eu)
gam_mod_Ar <- gamlss(prop_produced ~ pb(age, lambda = 10000),
sigma.formula = ~ pb(age, lambda = 10000),
data = sp_ws_prop_produced_Ar)
gam_mod_Mx <- gamlss(prop_produced ~ pb(age, lambda = 10000),
sigma.formula = ~ pb(age, lambda = 10000),
data = sp_ws_prop_produced_Mx)
gam_mod_Pr <- gamlss(prop_produced ~ pb(age, lambda = 10000),
sigma.formula = ~ pb(age, lambda = 10000),
data = sp_ws_prop_produced_Pr)
# Create age range and predictions for each dialect
age_range_Eu <- seq(min(sp_ws_prop_produced_Eu$age), max(sp_ws_prop_produced_Eu$age), by = 0.1)
pred_data_Eu <- data.frame(age = age_range_Eu)
pred_data_Eu$predicted <- predict(gam_mod_Eu, newdata = pred_data_Eu, type = "response")
pred_data_Eu$language <- "Spanish (European)"
age_range_Ar <- seq(min(sp_ws_prop_produced_Ar$age), max(sp_ws_prop_produced_Ar$age), by = 0.1)
pred_data_Ar <- data.frame(age = age_range_Ar)
pred_data_Ar$predicted <- predict(gam_mod_Ar, newdata = pred_data_Ar, type = "response")
pred_data_Ar$language <- "Spanish (Argentinian)"
age_range_Mx <- seq(min(sp_ws_prop_produced_Mx$age), max(sp_ws_prop_produced_Mx$age), by = 0.1)
pred_data_Mx <- data.frame(age = age_range_Mx)
pred_data_Mx$predicted <- predict(gam_mod_Mx, newdata = pred_data_Mx, type = "response")
pred_data_Mx$language <- "Spanish (Mexican)"
age_range_Pr <- seq(min(sp_ws_prop_produced_Pr$age), max(sp_ws_prop_produced_Pr$age), by = 0.1)
pred_data_Pr <- data.frame(age = age_range_Pr)
pred_data_Pr$predicted <- predict(gam_mod_Pr, newdata = pred_data_Pr, type = "response")
pred_data_Pr$language <- "Spanish (Peruvian)"
# Combine the observed data and prediction data
combined_data <- bind_rows(
sp_ws_prop_produced_Eu,
sp_ws_prop_produced_Ar,
sp_ws_prop_produced_Mx,
sp_ws_prop_produced_Pr
)
combined_pred_data <- bind_rows(
pred_data_Eu,
pred_data_Ar,
pred_data_Mx,
pred_data_Pr
)
# Plot using ggplot2 and facet_wrap
ggplot(combined_data, aes(x = age, y = prop_produced, color = language)) +
geom_point(alpha = 0.5) +
geom_jitter(width = .5, alpha = .1) +
geom_line(data = combined_pred_data, aes(x = age, y = predicted, group = language), size = 1) +
facet_wrap(~ language) +
labs(
title = "Logistic Regression: Age vs. Proportion Produced by Dialect",
x = "Age",
y = "Proportion Produced"
) +
theme_minimal() +
scale_color_manual(values = c("blue", "green", "red", "turquoise"))
# Plot all dialects on the same chart
ggplot(combined_data, aes(x = age, y = prop_produced, color = language)) +
geom_point(alpha = 0.1) + # Observed data points
geom_line(data = combined_pred_data, aes(x = age, y = predicted, group = language, color = language), size = 1.5) + # Predicted curves
labs(
title = "Beta Regression: Age vs. Proportion Produced by Dialect",
x = "Age",
y = "Proportion Produced"
) +
theme_minimal() +
scale_color_manual(values = c("blue", "green", "red", "turquoise")) +
theme(legend.position = "bottom") # Place legend at the bottom for better readability
```
IRT
```{r}
# Download necessary libraries
library(psych) # for general functions
library(glue) # for string gluing
library(mirt) # for IRT models
library(ggrepel) # for plot labels
# devtools::install_github("masurp/ggmirt")
library(ggmirt) # extension for 'mirt'
knitr::knit_hooks$set(inline = function(x) {
x <- sprintf("%1.2f", x)
paste(x, collapse = ", ")
})
# Trim and pivot "d_ws" data frame to fit the necessary specifications for the IRT model. Do this for each of the four dialects."
d_ws_wider_Eu <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (European)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
d_ws_wider_Ar <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (Argentinian)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
d_ws_wider_Mx <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (Mexican)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
d_ws_wider_Pr <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (Peruvian)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
# Fit the 2PL models for each dialect
modstr_Eu <- glue("F = 1 - {ncol(d_ws_wider_Eu)}")
fit.2pl.Eu <- mirt(d_ws_wider_Eu,
model = modstr_Eu,
itemtype = "2PL",
verbose = FALSE)
modstr_Ar <- glue("F = 1 - {ncol(d_ws_wider_Ar)}")
fit.2pl.Ar <- mirt(d_ws_wider_Ar,
model = modstr_Ar,
itemtype = "2PL",
verbose = FALSE)
modstr_Mx <- glue("F = 1 - {ncol(d_ws_wider_Mx)}")
fit.2pl.Mx <- mirt(d_ws_wider_Mx,
model = modstr_Mx,
itemtype = "2PL",
verbose = FALSE)
modstr_Pr <- glue("F = 1 - {ncol(d_ws_wider_Pr)}")
fit.2pl.Pr <- mirt(d_ws_wider_Pr,
model = modstr_Pr,
itemtype = "2PL",
verbose = FALSE)
# model coefficients for each dialect
coef.2pl.Eu <- as_tibble(coef(fit.2pl.Eu, simplify = TRUE)$items,
rownames = "definition")
coef.2pl.Ar <- as_tibble(coef(fit.2pl.Ar, simplify = TRUE)$items,
rownames = "definition")
coef.2pl.Mx <- as_tibble(coef(fit.2pl.Mx, simplify = TRUE)$items,
rownames = "definition")
coef.2pl.Pr <- as_tibble(coef(fit.2pl.Pr, simplify = TRUE)$items,
rownames = "definition")
```
Comparing identical/nonidentical surface forms
```{r}
# Filter "items" data-set to "words" only, then filter again so that it contains only those uni_lemmas contained in the "aoas" data frame
items_filtered <- filter(items, items$item_kind == 'word') %>%
filter(uni_lemma %in% c((clean_aoas$uni_lemma)))
# Arrange "uni_lemma" and "language" columns to match with order of said columns in "aoas" data frame
arrange(items_filtered, uni_lemma, language)
# Trim dataframe to include only necessary columns
items_filtered <- items_filtered %>%
dplyr::select(language, item_definition, uni_lemma)
# Clean up discrepancies and match up with AoA data in a CSV file. Then read into a new data frame
uni_lemma_aoa <- read.csv("cleaned_items_aoa.csv")
# Pivot into a wider dataframe which includes language, uni_lemma, and cleaned surface forms
cleaned_uni_lemma_wider <- uni_lemma_aoa %>%
dplyr::select(language, uni_lemma, aoa, cleaned_item) %>%
pivot_wider(names_from = language, values_from = cleaned_item, uni_lemma)
# Select for just European Spanish and Mexican Spanish
Eu_Mx <- cleaned_uni_lemma_wider %>%
dplyr::select(uni_lemma, `Spanish (European)`, `Spanish (Mexican)`)
#Join in AoA data
clean_aoas_Eu_Mx <- clean_aoas %>%
dplyr::select(uni_lemma, `Spanish (European)`, `Spanish (Mexican)`) %>%
left_join(Eu_Mx, join_by(uni_lemma))
# Filter for identical surface forms and calculate correlation
Eu_Mx_Identical <- clean_aoas_Eu_Mx %>%
filter(`Spanish (European).y` == `Spanish (Mexican).y`)
# Calculate correlation of AoA values
correlation_Eu_Mx_Identical <- cor(Eu_Mx_Identical$`Spanish (European).x`, Eu_Mx_Identical$`Spanish (Mexican).x`)
# Filter for non-identical surface forms
Eu_Mx_NonIdentical <- clean_aoas_Eu_Mx %>%
filter(`Spanish (European).y` != `Spanish (Mexican).y`)
# Calculate correlation
correlation_Eu_Mx_NonIdentical <- cor(Eu_Mx_NonIdentical$`Spanish (European).x`, Eu_Mx_NonIdentical$`Spanish (Mexican).x`)
```
ANOVA Tests for Lexical Categories, Pairwise t.tests, Density Curves
```{r}
source("scripts/fit_models.R")
# Make a new "wb_data" that includes all uni_lemmas and fit new AoA data
wb_data_full <- d_ws |>
group_by(uni_lemma, language, age) |>
summarise(total = n(),
num_true = sum(produces, na.rm = TRUE))
aoas_full <- fit_aoas(wb_data_full)
# Wrangle data to fit proper form for ANOVA test
lexical_categories <- d_ws %>%
distinct(uni_lemma, .keep_all=TRUE) %>%
dplyr::select(uni_lemma, lexical_category) %>%
arrange(uni_lemma)
aoas_full_wider <- aoas_full %>%
dplyr::select(uni_lemma, language, aoa) %>%
pivot_wider(names_from = language, values_from = aoa) %>%
left_join(lexical_categories, by = "uni_lemma")
# Perform ANOVA test for 6 possible dialect combinations
aoas_Eu_Mx <- aoas_full_wider %>%
dplyr::select(uni_lemma,"Spanish (European)", "Spanish (Mexican)", lexical_category) %>%
na.omit() %>%
mutate(diff_aoa = `Spanish (European)` - `Spanish (Mexican)`)
aov_aoas_Eu_Mx <- aov(diff_aoa ~ lexical_category, data = aoas_Eu_Mx)
summary(aov_aoas_Eu_Mx)
aoas_Eu_Ar <- aoas_full_wider %>%
dplyr::select(uni_lemma,"Spanish (European)", "Spanish (Argentinian)", lexical_category) %>%
na.omit() %>%
mutate(diff_aoa = `Spanish (European)` - `Spanish (Argentinian)`)
aov_aoas_Eu_Ar <- aov(diff_aoa ~ lexical_category, data = aoas_Eu_Ar)
summary(aov_aoas_Eu_Ar)
aoas_Eu_Pr <- aoas_full_wider %>%
dplyr::select(uni_lemma,"Spanish (European)", "Spanish (Peruvian)", lexical_category) %>%
na.omit() %>%
mutate(diff_aoa = `Spanish (European)` - `Spanish (Peruvian)`)
aov_aoas_Eu_Pr <- aov(diff_aoa ~ lexical_category, data = aoas_Eu_Pr)
summary(aov_aoas_Eu_Pr)
aoas_Ar_Mx <- aoas_full_wider %>%
dplyr::select(uni_lemma,"Spanish (Argentinian)", "Spanish (Mexican)", lexical_category) %>%
na.omit() %>%
mutate(diff_aoa = `Spanish (Argentinian)` - `Spanish (Mexican)`)
aov_aoas_Ar_Mx <- aov(diff_aoa ~ lexical_category, data = aoas_Ar_Mx)
summary(aov_aoas_Ar_Mx)
aoas_Ar_Pr <- aoas_full_wider %>%
dplyr::select(uni_lemma,"Spanish (Argentinian)", "Spanish (Peruvian)", lexical_category) %>%
na.omit() %>%
mutate(diff_aoa = `Spanish (Argentinian)` - `Spanish (Peruvian)`)
aov_aoas_Ar_Pr <- aov(diff_aoa ~ lexical_category, data = aoas_Ar_Pr)
summary(aov_aoas_Ar_Pr)
aoas_Mx_Pr <- aoas_full_wider %>%
dplyr::select(uni_lemma,"Spanish (Mexican)", "Spanish (Peruvian)", lexical_category) %>%
na.omit() %>%
mutate(diff_aoa = `Spanish (Mexican)` - `Spanish (Peruvian)`)
aov_aoas_Mx_Pr <- aov(diff_aoa ~ lexical_category, data = aoas_Mx_Pr)
summary(aov_aoas_Mx_Pr)
# Run pairwise t.tests for each of the possible dialect combinations
pairwise_ttest_Eu_Ar <- pairwise.t.test(aoas_Eu_Ar$diff_aoa, aoas_Eu_Ar$lexical_category, p.adjust.method = "bonferroni")
print(pairwise_ttest_Eu_Ar)
pairwise_ttest_Ar_Mx <- pairwise.t.test(aoas_Ar_Mx$diff_aoa, aoas_Ar_Mx$lexical_category, p.adjust.method = "bonferroni")
print(pairwise_ttest_Ar_Mx)
pairwise_ttest_Ar_Pr <- pairwise.t.test(aoas_Ar_Pr$diff_aoa, aoas_Ar_Pr$lexical_category, p.adjust.method = "bonferroni")
print(pairwise_ttest_Ar_Pr)
pairwise_ttest_Eu_Mx <- pairwise.t.test(aoas_Eu_Mx$diff_aoa, aoas_Eu_Mx$lexical_category, p.adjust.method = "bonferroni")
print(pairwise_ttest_Eu_Mx)
pairwise_ttest_Eu_Pr <- pairwise.t.test(aoas_Eu_Pr$diff_aoa, aoas_Eu_Pr$lexical_category, p.adjust.method = "bonferroni")
print(pairwise_ttest_Eu_Pr)
pairwise_ttest_Mx_Pr <- pairwise.t.test(aoas_Mx_Pr$diff_aoa, aoas_Mx_Pr$lexical_category, p.adjust.method = "bonferroni")
print(pairwise_ttest_Mx_Pr)
# Visualize AoA as density curves
library(reshape2)
# Reshape the data into a long format
aoa_density_curves <- clean_aoas %>%
reshape2::melt(id.vars = NULL,
measure.vars = c("Spanish (Argentinian)", "Spanish (Mexican)", "Spanish (European)", "Spanish (Peruvian)"),
variable.name = "Dialect",
value.name = "Value")
# Create the density plot
ggplot(aoa_density_curves, aes(x = Value, fill = Dialect, color = Dialect)) +
geom_density(alpha = 0.5) +
labs(title = "Age of Acquisition Density Curves for Different Dialects",
x = "Age of Acquisition (Months)",
y = "Density") +
scale_x_continuous(limits = c(8, 42)) + # Adjust x-axis limits
scale_y_continuous(expand = expansion(mult = c(0, .2))) + # Adjust y-axis scaling for more vertical space
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
# Create boxplots for each dialect combination
# Create a new column for each data frame containing absolute values
aoas_Ar_Mx$abs_diff_aoa <- abs(aoas_Ar_Mx$diff_aoa)
aoas_Ar_Pr$abs_diff_aoa <- abs(aoas_Ar_Pr$diff_aoa)
aoas_Eu_Ar$abs_diff_aoa <- abs(aoas_Eu_Ar$diff_aoa)
aoas_Eu_Mx$abs_diff_aoa <- abs(aoas_Eu_Mx$diff_aoa)
aoas_Eu_Pr$abs_diff_aoa <- abs(aoas_Eu_Pr$diff_aoa)
aoas_Mx_Pr$abs_diff_aoa <- abs(aoas_Mx_Pr$diff_aoa)
# Create boxplots
ggplot(aoas_Ar_Mx, aes(x = lexical_category, y = abs_diff_aoa, fill = lexical_category)) +
geom_boxplot() +
labs(title = "Lexical Categories: Spanish (Argentinian) vs Spanish (Mexican)",
x = "Lexical Category",
y = "Diff AoA Ar_Mx") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplot(aoas_Ar_Pr, aes(x = lexical_category, y = abs_diff_aoa, fill = lexical_category)) +
geom_boxplot() +
labs(title = "Lexical Categories: Spanish (Argentinian) vs Spanish (Peruvian)",
x = "Lexical Category",
y = "Diff AoA Ar_Pr") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplot(aoas_Eu_Ar, aes(x = lexical_category, y = abs_diff_aoa, fill = lexical_category)) +
geom_boxplot() +
labs(title = "Lexical Categories: Spanish (European) vs Spanish (Argentinian)",
x = "Lexical Category",
y = "Diff AoA Eu_Ar") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplot(aoas_Eu_Mx, aes(x = lexical_category, y = abs_diff_aoa, fill = lexical_category)) +
geom_boxplot() +
labs(title = "Lexical Categories: Spanish (European) vs Spanish (Mexican)",
x = "Lexical Category",
y = "Diff AoA Eu_Mx") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplot(aoas_Eu_Pr, aes(x = lexical_category, y = abs_diff_aoa, fill = lexical_category)) +
geom_boxplot() +
labs(title = "Lexical Categories: Spanish (European) vs Spanish (Peruvian)",
x = "Lexical Category",
y = "Diff AoA Eu_Pr") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
ggplot(aoas_Mx_Pr, aes(x = lexical_category, y = abs_diff_aoa, fill = lexical_category)) +
geom_boxplot() +
labs(title = "Lexical Categories: Spanish (Mexican) vs Spanish (Peruvian)",
x = "Lexical Category",
y = "Diff AoA Mx_Pr") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5))
```
IRT
```{r}
# Download necessary libraries
library(psych) # for general functions
library(glue) # for string gluing
library(mirt) # for IRT models
library(ggrepel) # for plot labels
# devtools::install_github("masurp/ggmirt")
library(ggmirt) # extension for 'mirt'
knitr::knit_hooks$set(inline = function(x) {
x <- sprintf("%1.2f", x)
paste(x, collapse = ", ")
})
# Trim and pivot "d_ws" data frame to fit the necessary specifications for the IRT model. Do this for each of the four dialects."
d_ws_wider_Eu <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (European)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
d_ws_wider_Ar <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (Argentinian)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
d_ws_wider_Mx <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (Mexican)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
d_ws_wider_Pr <- d_ws %>%
filter(item_kind == "word") %>%
filter(language == "Spanish (Peruvian)") %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
# Fit the 2PL models for each dialect
modstr_Eu <- glue("F = 1 - {ncol(d_ws_wider_Eu)}")
fit.2pl.Eu <- mirt(d_ws_wider_Eu,
model = modstr_Eu,
itemtype = "2PL",
verbose = FALSE)
modstr_Ar <- glue("F = 1 - {ncol(d_ws_wider_Ar)}")
fit.2pl.Ar <- mirt(d_ws_wider_Ar,
model = modstr_Ar,
itemtype = "2PL",
verbose = FALSE)
modstr_Mx <- glue("F = 1 - {ncol(d_ws_wider_Mx)}")
fit.2pl.Mx <- mirt(d_ws_wider_Mx,
model = modstr_Mx,
itemtype = "2PL",
verbose = FALSE)
modstr_Pr <- glue("F = 1 - {ncol(d_ws_wider_Pr)}")
fit.2pl.Pr <- mirt(d_ws_wider_Pr,
model = modstr_Pr,
itemtype = "2PL",
verbose = FALSE)
# model coefficients for each dialect
coef.2pl.Eu <- as_tibble(coef(fit.2pl.Eu, simplify = TRUE)$items,
rownames = "definition")
coef.2pl.Ar <- as_tibble(coef(fit.2pl.Ar, simplify = TRUE)$items,
rownames = "definition")
coef.2pl.Mx <- as_tibble(coef(fit.2pl.Mx, simplify = TRUE)$items,
rownames = "definition")
coef.2pl.Pr <- as_tibble(coef(fit.2pl.Pr, simplify = TRUE)$items,
rownames = "definition")
```
Plot
```{r}
testInfoPlot(fit.2pl.Ar) + scale_color_manual(values=rep("black", 1000))
```
``` {r}
# Trim and pivot "d_ws" data frame to fit the necessary specifications for the IRT model"
d_ws_wider <- d_ws %>%
dplyr::select(data_id, item_id, produces) %>%
pivot_wider(names_from = item_id, values_from = produces) %>%
dplyr::select(-data_id) %>%
mutate_all(as.integer)
```
DIF
``` {r}
# Load necessary
library(psych) # for general functions
library(glue) # for string gluing
library(mirt) # for IRT models
library(ggrepel) # for plot labels
d_ws_DIF_Eu_Mx <- d_ws %>%
filter(uni_lemma %in% intersection) %>%
dplyr::select(data_id, uni_lemma, language, produces) %>%
pivot_wider(names_from = uni_lemma, values_from = produces) %>%
filter(language == c("Spanish (European)", "Spanish (Mexican)")) %>%
dplyr::select(-data_id) %>%
mutate_at(vars(-language), ~ as.numeric(.))
DIF_language <- d_ws_DIF_Eu_Mx %>%
dplyr::pull(language) %>%
as.factor()
d_ws_DIF_Eu_Mx <- d_ws_DIF_Eu_Mx %>%
dplyr::select(-language)
# Perform DIF Analysis
modstr <- glue("F = 1 - {ncol(d_ws_DIF_Eu_Mx)}")
fit_2plmulti <- multipleGroup(d_ws_DIF_Eu_Mx,
model = modstr,
method = "MHRM",
itemtype = "2PL",
group = DIF_language,
verbose = FALSE)
# Likelihood ratio test
dif_2plmulti <- DIF(fit_2plmulti,
which.par = c("a1", "d"),
method = "MHRM",
technical = list("NCYCLES" = 1000),
items2test = c(1:ncol(d_ws_DIF_Eu_Mx)),
p.adjust = "BH")
```
t-test for AoA differences
```{r}
# Generate a data frame with all AoA and uni_lemma values
uni_lemma_aoa_wider <- uni_lemma_aoa %>%
dplyr::select(language, uni_lemma, aoa, cleaned_item) %>%
pivot_wider(names_from = language, values_from = cleaned_item, uni_lemma)
uni_lemma_aoa_master <- clean_aoas %>%
left_join(uni_lemma_aoa_wider, join_by(uni_lemma))
# Filter to identical and nonidentical surface forms for all dialect pairings
Eu_Ar_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` == `Spanish (Argentinian).y`)
Eu_Ar_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` != `Spanish (Argentinian).y`)
Eu_Pr_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` == `Spanish (Peruvian).y`)
Eu_Pr_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (European).y` != `Spanish (Peruvian).y`)
Mx_Ar_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` == `Spanish (Argentinian).y`)
Mx_Ar_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` != `Spanish (Argentinian).y`)
Mx_Pr_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` == `Spanish (Peruvian).y`)
Mx_Pr_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (Mexican).y` != `Spanish (Peruvian).y`)
Pr_Ar_Identical <- uni_lemma_aoa_master %>%
filter(`Spanish (Peruvian).y` == `Spanish (Argentinian).y`)
Pr_Ar_NonIdentical <- uni_lemma_aoa_master %>%
filter(`Spanish (Peruvian).y` != `Spanish (Argentinian).y`)
# Generate vector of differences for each possible dialect pairing
dif_Eu_Mx_Identical <- Eu_Mx_Identical$`Spanish (European).x` - Eu_Mx_Identical$`Spanish (Mexican).x`
dif_Eu_Mx_NonIdentical <- Eu_Mx_NonIdentical$`Spanish (European).x` - Eu_Mx_NonIdentical$`Spanish (Mexican).x`
dif_Eu_Ar_Identical <- Eu_Ar_Identical$`Spanish (European).x`- Eu_Ar_Identical$`Spanish (Argentinian).x`
dif_Eu_Ar_NonIdentical <- Eu_Ar_NonIdentical$`Spanish (European).x` - Eu_Ar_NonIdentical$`Spanish (Argentinian).x`
dif_Eu_Pr_Identical <- Eu_Pr_Identical$`Spanish (European).x` - Eu_Pr_Identical$`Spanish (Peruvian).x`
dif_Eu_Pr_NonIdentical <- Eu_Pr_NonIdentical$`Spanish (European).x` - Eu_Pr_NonIdentical$`Spanish (Peruvian).x`
dif_Mx_Ar_Identical <- Mx_Ar_Identical$`Spanish (Mexican).x` - Mx_Ar_Identical$`Spanish (Argentinian).x`
dif_Mx_Ar_NonIdentical <- Mx_Ar_NonIdentical$`Spanish (Mexican).x` - Mx_Ar_NonIdentical$`Spanish (Argentinian).x`
dif_Mx_Pr_Identical <- Mx_Pr_Identical$`Spanish (Mexican).x` - Mx_Pr_Identical$`Spanish (Peruvian).x`
dif_Mx_Pr_NonIdentical <- Mx_Pr_NonIdentical$`Spanish (Mexican).x` - Mx_Pr_NonIdentical$`Spanish (Peruvian).x`
dif_Pr_Ar_Identical <- Pr_Ar_Identical$`Spanish (Peruvian).x` - Pr_Ar_Identical$`Spanish (Argentinian).x`
dif_Pr_Ar_NonIdentical <- Pr_Ar_NonIdentical$`Spanish (Peruvian).x` - Pr_Ar_NonIdentical$`Spanish (Argentinian).x`
# Combine the data into a single data frame for easier plotting
differences <- data.frame(
Group = c(rep("Identical", length(dif_Eu_Mx_Identical)), rep("NonIdentical", length(dif_Eu_Mx_NonIdentical))),
Difference = c(dif_Eu_Mx_Identical, dif_Eu_Mx_NonIdentical)
)
# Create the boxplots
library(ggplot2)
ggplot(differences, aes(x = Group, y = Difference, fill = Group)) +
geom_boxplot() +
labs(title = "Comparing Identical vs Non-Identical Surface Forms (European vs Mexican)",
x = "Group",
y = "Diff AoA") +
theme_minimal()
# Perform a t-test for these differences and place p-values into a data frame
Identical_NonIdentical_p_values <- data.frame(
Eu_Mx = c(t.test(dif_Eu_Mx_Identical, dif_Eu_Mx_NonIdentical)$p.value),
Eu_Ar = c(t.test(dif_Eu_Ar_Identical, dif_Eu_Ar_NonIdentical)$p.value),
Eu_Pr = c(t.test(dif_Eu_Pr_Identical, dif_Eu_Pr_NonIdentical)$p.value),
Mx_Ar = c(t.test(dif_Mx_Ar_Identical, dif_Mx_Ar_NonIdentical)$p.value),
Mx_Pr = c(t.test(dif_Mx_Pr_Identical, dif_Mx_Pr_NonIdentical)$p.value),
Pr_Ar = c(t.test(dif_Pr_Ar_Identical, dif_Pr_Ar_NonIdentical)$p.value)
)
```
Dendrogram