-
Notifications
You must be signed in to change notification settings - Fork 0
/
README.qmd
1277 lines (1120 loc) · 50.7 KB
/
README.qmd
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
---
format: gfm
editor: visual
prefer-html: true
---
# Replication code for "Crossing the Linguistic Causeway: Ethno-national Differences on Soundscape Attributes in Bahasa Melayu"
## Setup Environment
```{r setup}
#| message: false
#| echo: false
#session
library(pander)
#data
library(dataverse)
library(tidyverse)
library(janitor)
library(plyr)
library(reshape2)
library(readxl)
library(ggfortify)
#stats
library(psych)
library(rstatix)
library(conover.test)
library(fmsb)
library(muStat)
#plots/tables
library(ggsignif)
library(ggbrace)
library(kableExtra)
library(factoextra)
library(ggforce)
library(ggExtra)
library(ggthemes)
#circumplex
library(RTHORR)
library(circumplex)
library(CircE)
source("helper.R") #load helper functions
#Set dataverse server
Sys.setenv("DATAVERSE_SERVER" = "https://researchdata.ntu.edu.sg")
```
```{r session}
#| echo: false
pander(sessionInfo())
```
## Data Loading and Preparation
The survey data was collected via a [Matlab GUI](https://github.com/kenowr/satp-gui "Link to GitHub"). The survey and demographic data are stored in a public data repository at <https://doi.org/10.21979/N9/9AZ21T>.
Load supplementary data for analysis
1. SATP zsm Stage 1: <https://doi.org/10.21979/N9/0NE37R>
2. ARAUS dataset: <https://doi.org/10.21979/N9/9OTEVX>
### SATP zsm Stage 1 & 2 dataverse datasets
```{r dataloader_zsm12}
#| message: false
#Dataverse dataset doi links
data.satp.zsm2.name = "10.21979/N9/9AZ21T" #dataset linked to this paper
data.satp.zsm1.name = "10.21979/N9/0NE37R" #satp stage 1 dataset
data.araus.name = "10.21979/N9/9OTEVX" #araus dataset
# Loading SATP Stage 2 dataset
## Define a list of data frame names and associated dataset file names
data.names <- data.frame(
df.name=c("data.subj.zsm2", "data.demo.zsm2", #zsm2
"data.main.zsm1","data.der.zsm1" #zsm1
),
filename=c("SATP_Stage2_zsm_questionnaire.tab",#zsm2 demographic
"SATP_Stage2_zsm_demographics.tab", #zsm2 demographic
"SATP_Stage1_zsm_main.tab", #zsm1 main-axis attributes
"SATP_Stage1_zsm_derived.tab" #zsm1 derived-axis attributes
))
## Load datasets into a list
data.satp.zsm2.l <- datavLoader(data.names[1:2,], data.satp.zsm2.name)
# Loading SATP Stage 1 dataset
data.satp.zsm1.l <- datavLoader(data.names[3:4,], data.satp.zsm1.name)
```
### ARAUS Dataset
```{r dataloader_araus}
#| message: false
data.araus.filename <- "data.zip" #filename of araus data
#download data.zip
data.araus.bin<-dataverse::get_file_by_name(filename = data.araus.filename,
dataset = data.araus.name)
#write the binary file to zip
writeBin(data.araus.bin, paste0("./data/",data.araus.filename))
#unzip and retrieve only responses.csv and participants.csv
unzip(data.araus.filename,
files=c("data/responses.csv","data/participants.csv"))
```
### ARAUS: cleaning and preparation
```{r clean_araus}
#| message: false
#araus participant data
data.araus.participant <- read_csv("./data/participants.csv") %>%
dplyr::filter(ethnic==2 & residence_length==1) %>% #ethnic malays
dplyr::select(participant)
#subjective test data
data.araus<-read_csv("./data/responses.csv") %>%
#only local resident + ethnic malays
dplyr::filter(participant %in% data.araus.participant$participant) %>%
#only soundscapes; no augmentation
dplyr::filter(grepl("silence",masker)) %>%
#remove test and calibration folds
dplyr::filter(!fold_r %in% c(0,-1)) %>%
#compute ISOPL and ISOEV
dplyr::mutate(ISOPL=((pleasant-annoying)+
cospi(0.25)*(calm-chaotic)+
cospi(0.25)*(vibrant-monotonous))/
(4+sqrt(32))) %>%
dplyr::mutate(ISOEV=((eventful-uneventful)+
cospi(0.25)*(chaotic-calm)+
cospi(0.25)*(vibrant-monotonous))/
(4+sqrt(32))) %>%
#select only relevant columns
dplyr::select(c(participant,soundscape,
eventful,vibrant,pleasant,calm,
uneventful, monotonous, annoying, chaotic,
ISOPL, ISOEV))
```
## Demographic Analysis
```{r demographic}
#| message: false
#no of participants
n.participsnts.SG <- length(
unique(data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(ETHNICITY=="SG") %>%
.$participantID))
n.participsnts.MY.M <- length(
unique(data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(ETHNICITY=="MY:M") %>%
.$participantID))
n.participsnts.MY.O <- length(
unique(data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(ETHNICITY=="MY:O") %>%
.$participantID))
#summarise language fluency count by groups
data.demo.merged.gender.fluency <- data.satp.zsm2.l$data.demo.zsm2 %>%
dplyr::mutate(fluency=ifelse(
set=="UPM", #fluent in oral zsm >6
ifelse(as.numeric(as.character(fluency))>6,"Yes","No"),
"Yes")) %>%
group_by(group,fluency) %>%
dplyr::summarise(count=n()) %>%
pivot_wider(names_from = group,values_from = c(count)) %>%
column_to_rownames(var = "fluency") %>%
mutate_all(~replace(., is.na(.), 0)) %>%
rbind(data.satp.zsm2.l$data.demo.zsm2 %>%
group_by(group,gender) %>%
dplyr::summarise(count=n()) %>%
pivot_wider(names_from = group,values_from = c(count)) %>%
column_to_rownames(var = "gender"))
#demos stats for age, written & spoken fluency scores
data.demo.merged.numeric <- data.satp.zsm2.l$data.demo.zsm2 %>%
dplyr::mutate(fluency=ifelse(
fluency=="Yes",NA,as.numeric(as.character(fluency)))) %>%
dplyr::group_by(group) %>%
dplyr::summarise(across(c("age","written","fluency"),
list(mean=mean,sd=sd))) %>%
dplyr::mutate(Age=paste0(format(round(age_mean,2),nsmall=2),
" (",
format(round(age_sd,2),nsmall=2),") "),
`Written Fluency`=paste0(
format(round(written_mean,2),nsmall=2),
" (",
format(round(written_sd,2),nsmall=2),
") "),
`Spoken Fluency`=paste0(
format(round(fluency_mean,2),nsmall=2),
" (",
format(round(fluency_sd,2),nsmall=2),
") "),
`Spoken Fluency`=ifelse(
group=="SG","",`Spoken Fluency`)) %>%
dplyr::select(!c(age_mean,age_sd,written_mean,written_sd,
fluency_mean,fluency_sd))
#summarise in a table
data.demo.merged.table<- as.data.frame(t(data.demo.merged.numeric)) %>%
row_to_names(row_number = 1) %>% #convert 1st row to colname
`rownames<-`(c("Age","Written Fluency","Summary")) %>%
#update `Spoken Fluency` for grouped rows
dplyr::mutate(SG=ifelse(SG=="","-",SG)) %>%
rbind(data.demo.merged.gender.fluency) %>%
kableExtra::kbl(booktabs = T, linesep = "",
#format = "latex",
format = "html",
label = "demo",
caption = "Summary of demographic information")%>%
pack_rows("Spoken Fluency", 3, 5) %>%
pack_rows("Gender", 6, 7) %>%
row_spec(3, hline_after = T) %>%
#kable_styling(latex_table_env = "tabularx") %>%
kable_styling(protect_latex = TRUE) %>%
kable_paper(full_width = T) #%>%
#save_kable(paste0(getwd(),"/Table tex files/demo.tex"))
data.demo.merged.table
```
## Exploratory analysis
### Summary statistics
```{r sumStats}
#| message: false
#summary of median values
data.merged.median<-data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::group_by(stimuliID,set) %>%
dplyr::summarise(across(pleasant:monotonous,
median,na.rm=TRUE)) %>%
pivot_longer(cols=-c(1:2),names_to = "PAQ",values_to = "median")
#pivot to long table
data.merged.long<-data.satp.zsm2.l$data.subj.zsm2 %>%
pivot_longer(names_to = "PAQ",
values_to = "Score",
cols = c("pleasant":"monotonous"))
#ISOPL and ISOEV
data.ISOPLEV.median <- data.satp.zsm2.l$data.subj.zsm2 %>%
group_by(stimuliID,ETHNICITY) %>%
dplyr::summarise(across(c(ISOPL,ISOEV),
median,na.rm=TRUE))
#Median contour plot with median points of ISOPL and ISOEV
p.ISOPLEV.contour.facetedStimuli<-ggplot(data=data.satp.zsm2.l$data.subj.zsm2,
aes(x = ISOPL, y = ISOEV)) +
facet_wrap(~stimuliID, ncol = 9) +
# stat_density_2d(bins=3,contour_var = "ndensity",breaks=c(0.5),
# aes(color=ETHNICITY)) +
stat_density_2d(bins=3,contour_var = "ndensity",breaks=c(0.5),
geom = "density_2d",
aes(color=ETHNICITY)) +
geom_point(data = data.ISOPLEV.median,
aes(x = ISOPL, y = ISOEV, color=ETHNICITY)) +
ylim(c(-1,1)) + xlim(c(-1,1)) +
ggthemes::scale_colour_few() +
ylim(c(-1.1,1.1)) + xlim(c(-1.1,1.1))
p.ISOPLEV.contour.facetedStimuli
```
```{r kdecontour}
#KDE contour of all points
p.ISOPLEV.contour.all<-ggplot(data=data.satp.zsm2.l$data.subj.zsm2,
aes(x = ISOPL, y = ISOEV)) +
#facet_wrap(~stimuliID, ncol = 9) +
stat_density_2d(data=data.satp.zsm2.l$data.subj.zsm2,
geom = "density_2d",
alpha=0.7,
contour_var = "ndensity",
breaks=c(0.2),
aes(color=ETHNICITY,
fill=ETHNICITY,
alpha = stat(level))) +
stat_density_2d(data=data.araus,
geom = "density_2d",
alpha=0.5,
n=100,
contour_var = "ndensity",
breaks=c(0.2),
contour = TRUE,
color="#F17CB0",
linetype = "dashed") +
#geom_path(aes(x, y), data=contour_95) +
geom_point(data = data.ISOPLEV.median, alpha=0.3,
aes(x = ISOPL, y = ISOEV, color=ETHNICITY)) +
# geom_circle(aes(x0 = 0, y0 = 0, r = 1),
# fill = NA, color = "grey",
# linetype = "twodash") + # Add circles
#scale_colour_brewer(palette = "Set1") +
ggthemes::scale_colour_few() +
ylim(c(-1.2,1.2)) + xlim(c(-1.2,1.2)) +
theme(legend.position="bottom")
#theme(legend.position="none")
p.ISOPLEV.contour.all.marg<-ggMarginal(p.ISOPLEV.contour.all,
groupColour = T,
groupFill = T,
alpha=0.15)
p.ISOPLEV.contour.all.marg
ggsave(paste0("./outputs/allcontour.pdf"),
plot = p.ISOPLEV.contour.all.marg,
width = 2300, height = 2350, units = "px",scale = 0.7)
```
## Statistical Analysis
### Order effects analysis
Due to a bug in the MATLAB GUI program, the same randomized participant order was presented to the participants whenever the MATLAB GUI program was restarted. Here, the NTU set is evaluated for order effects since some of the participants had the same randomized order but some were truly randomized.
```{r ksOrder}
#| message: false
#extract stimuli order from NTU group
NTUorder.df <- data.satp.zsm2.l$data.subj.zsm2 %>%
filter(set=="NTU") %>%
dplyr::select(participantID,stimuliID) %>%
pivot_wider(names_from = participantID, values_from = stimuliID)
# Create a reference column (assuming it is the first column)
reference_column <- NTUorder.df$"8"[[1]]
# Initialize a list to store equivalent columns
equivalent_columns <- list()
# Loop through each column starting from the second column
for (i in 1:ncol(NTUorder.df)) {
# Compare each column to the reference column
if (all(reference_column == NTUorder.df[1, i][[1]][[1]])) {
equivalent_columns[[
length(equivalent_columns) + 1
]] <- as.numeric(colnames(NTUorder.df[1, i]))
}
}
# Extract the equivalent columns from the dataframe
same.order.pid <- unlist(equivalent_columns)
# Print the equivalent columns
cat("Participant IDs with the same order:\n")
print(same.order.pid)
#create new column to store
ks.order.df <- data.merged.long %>%
dplyr::filter(set=="NTU") %>%
dplyr::mutate(group=ifelse(
participantID %in% same.order.pid, "same", "random"),
across(c(stimuliID,PAQ),.fns = as.factor)) %>%
dplyr::group_by(PAQ,stimuliID) %>%
dplyr::summarize(
ks_test = list(ks.test(Score[group == "same"],
Score[group == "random"],
exact = NULL,
alternative = "two.sided")),
stat = ks_test[[1]]$statistic,
ks.pvalue = ks_test[[1]]$p.value,
ks.signif = ks.pvalue<0.05,
n.same = length(Score[group == "same"]),
n.rand = length(Score[group == "random"])) %>%
dplyr::ungroup() %>%
dplyr::mutate(ks.padj = p.adjust(ks.pvalue, method="BH"),
ks.adjsignif = ks.padj<0.05) %>%
dplyr::select(!ks_test)
cat("Number of KS comparisons p <0.05: ",
sum(ks.order.df$ks.signif),"/",
length(ks.order.df$ks.signif), "\n")
cat("Number of KS comparisons with p.adj <0.05: ",
sum(ks.order.df$ks.adjsignif),"/",
length(ks.order.df$ks.adjsignif))
```
Hence, there were no order effects present.
### Difference in PAQ scores across groups
Kruskal-Wallis Test
```{r kwt}
#| message: false
#initialise data frame
data.kwt<-data.frame(stimuliID=numeric(),
PAQ=character(),
pvalue=numeric(),
effect=numeric())
list.PAQ<-c("eventful","vibrant","pleasant","calm",
"uneventful","monotonous","annoying","chaotic",
"ISOPL","ISOEV")
#for each stimuli
for(s.ID in 1:length(unique(data.satp.zsm2.l$data.subj.zsm2$stimuliID))){
#for each PAQ attribute
for (paq in list.PAQ){
df=data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(stimuliID==s.ID)
kwt<-kruskal.test(
as.formula(paste(paq,"~ETHNICITY")),
data=df)
kwteff<-kruskal_effsize(
formula = as.formula(paste(paq,"~ETHNICITY")),
data=df)
data.kwt<-rbind(
data.kwt,
c(stimuliID=s.ID,
PAQ=paq,
pvalue=kwt$p.value,
effect=kwteff$effsize))
}
}
colnames(data.kwt)<-c("stimuliID","PAQ","pvalue","effect")
#cases with significant differences
data.kwt.sig<-data.kwt %>%
dplyr::filter(as.numeric(pvalue)<0.05 & as.numeric(effect)>=0.01)
#export to csv
write.csv(x=data.kwt.sig,
file = "./outputs/SATP_Stage2_zsm_sigKWT.csv",
row.names = FALSE)
```
Posthoc Conover-Iman Tests
```{r cit}
#| message: false
#initialise data frame
data.cit<-data.frame(stimuliID=numeric(),
PAQ=character(),
stat=numeric(),
set=character(),
pvalue=numeric(),
adjpval=numeric())
#Perform CIT for significant cases in KWT
for(idx in 1:length(data.kwt.sig$stimuliID)){
paq<-data.kwt.sig$PAQ[idx]
x.ID<-data.kwt.sig$stimuliID[idx]
#select only kwt significant
df<-data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(stimuliID==x.ID)
cit<-conover.test(x=df[,paq],
g=df$ETHNICITY,
kw=FALSE,
method='bonferroni',
altp=TRUE)
data.cit<-rbind(
data.cit,
cbind(data.frame(stimuliID=x.ID,PAQ=paq),
as.data.frame(cit) %>%
dplyr::select(c("T",comparisons,
altP,altP.adjusted))))
}
#export significant cases
data.cit.sig<-data.cit %>%
filter(as.numeric(altP.adjusted)<0.05) %>%
dplyr::mutate(altP.adjusted=round(altP.adjusted,digits = 4))
write.csv(x=data.cit.sig,
file = "./outputs/SATP_Stage2_zsm_sigCIT.csv",
row.names = FALSE)
```
### Table of KWT and CIT results
```{r kwtcitTable}
#| message: false
#kruskal-wallis table of p-vales and effect sizes
kwtTable<-data.kwt %>%
pivot_longer(cols = c("pvalue","effect"),
names_to = "Stat",values_to = "Value") %>%
dplyr::mutate(Value=round(as.numeric(Value),4),
Value=case_when(Stat=="pvalue" & Value<0.0001~
paste0("****",formatC(Value,
format="f",
digits=4)),
Stat=="pvalue" & Value<0.001~
paste0("***",formatC(Value,
format="f",
digits=4)),
Stat=="pvalue" & Value<0.01~
paste0("**",formatC(Value,
format="f",
digits=4)),
Stat=="pvalue" & Value<0.05~
paste0("*",formatC(Value,
format="f",
digits=4)),
Stat=="effect" & abs(Value)>=0.01 & Value<0.06~
paste0("(S)",formatC(Value,
format="f",
digits=4)),
Stat=="effect" & abs(Value)>=0.06 & Value<0.14~
paste0("(M)",formatC(Value,
format="f",
digits=4)),
Stat=="effect" & abs(Value)>=0.14~
paste0("(L)",formatC(Value,
format="f",
digits=4)),
TRUE~formatC(Value,format="f",digits=4))) %>%
pivot_wider(names_from = "PAQ", values_from = "Value") %>%
kableExtra::kbl(booktabs = T, linesep = "",
#format = "latex",
format = "html",
label = "kwt",
caption = "Summary of Kruskal-Wallis Test")%>%
collapse_rows(columns = 1, valign = "top") %>%
#kable_styling(latex_table_env = "tabularx") %>%
kable_styling(protect_latex = TRUE) %>%
kable_paper(full_width = T) #%>%
#save_kable(paste0(getwd(),"/Table tex files/kwtTable.tex"))
kwtTable
#posthoc conover-iman table of p-vales
citTable <- data.cit %>%
dplyr::mutate(PAQ=factor(PAQ, level=list.PAQ),
comparisons=gsub(" - ","--",comparisons)) %>%
dplyr::select(!altP) %>%
dplyr::mutate(altP.adjusted=round(as.numeric(altP.adjusted),4),
altP.adjusted=case_when(altP.adjusted <0.0001~
paste0("****",formatC(altP.adjusted,
format="f",digits=4)),
altP.adjusted <0.001~
paste0("***",formatC(altP.adjusted,
format="f",digits=4)),
altP.adjusted <0.01~
paste0("**",formatC(altP.adjusted,
format="f",digits=4)),
altP.adjusted <0.05~
paste0("*",formatC(altP.adjusted,
format="f",digits=4)),
TRUE~formatC(altP.adjusted,format="f",digits=4))) %>%
pivot_wider(values_from = altP.adjusted, names_from = comparisons) %>%
kableExtra::kbl(booktabs = T, linesep = "",
#format = "latex",
format = "html",
label = "kwt",
caption = "Summary of Kruskal-Wallis Test")%>%
collapse_rows(columns = 1, valign = "top") %>%
#kable_styling(latex_table_env = "tabularx") %>%
kable_styling(protect_latex = TRUE) %>%
kable_paper(full_width = T) #%>%
#save_kable(paste0(getwd(),"/Table tex files/citTable.tex"))
citTable
```
## Plotting posthoc paired comparison results
### Box plot of all PAQ across all stimuli
```{r PAQboxplot}
#box plots PAQ vs stimuli
#generate pairs and signif annotations for ggsnif plotting
boxplot.xtolerance<-0.25
signifbar.height.mym.myo<-110
signifbar.height.mym.sg<-135
signifbar.height.myo.sg<-110
#prepare dataframe for plotting significance brace
PAQ.combined.signif <- data.cit.sig %>%
dplyr::filter(!PAQ %in% c("ISOPL","ISOEV")) %>%
dplyr::mutate(stimuliID=as.numeric(stimuliID),
PAQ=case_when(PAQ == "eventful"~"e",
PAQ == "vibrant"~"v",
PAQ == "pleasant"~"p",
PAQ == "calm"~"ca",
PAQ == "uneventful"~"u",
PAQ == "monotonous"~"m",
PAQ == "annoying"~"a",
PAQ == "chaotic"~"ch"),
PAQ=factor(PAQ, level=c("e","v",
"p","ca","u",
"m","a",
"ch")),
#factor order for x-axis location
#PAQfctorder=as.numeric(PAQ),
PAQfctorder=as.numeric(stimuliID),
#MY:M is left most boxplot in group; MY:O is the middle
#x is the left edge of the signif bar
x=ifelse(grepl("MY:M \\-",comparisons),
PAQfctorder-boxplot.xtolerance,
PAQfctorder),
#xend is the right edge of the signif bar
xend=ifelse(grepl("- MY:O",comparisons),
PAQfctorder,PAQfctorder+boxplot.xtolerance),
y=ifelse(grepl("MY:M \\-",comparisons),
ifelse(grepl("- MY:O",comparisons),
signifbar.height.mym.myo,
signifbar.height.mym.sg),
signifbar.height.myo.sg),
#yend=y-5,
ann.labels=ifelse(
altP.adjusted<0.0001,
"****",
ifelse(altP.adjusted<0.001,
"***",
ifelse(altP.adjusted<0.01,
"**",
ifelse(altP.adjusted<0.05,
"*","ns")))),
stimuliID=factor(stimuliID,levels=c(1:27)))
#str(PAQ.combined.signif)
groupingFactor<-1
plotGroup<-1
totalStimuli<-length(unique(data.merged.long$stimuliID))
uniqueStimuli<-unique(data.merged.long$stimuliID)
stimuliGrps<-split(sort(uniqueStimuli),
ceiling(seq_along(uniqueStimuli)/
(totalStimuli/groupingFactor)))
p.8PAQ.box<-ggplot(data = data.merged.long %>%
mutate(stimuliID=as.factor(stimuliID),
PAQ=case_when(PAQ == "eventful"~"e",
PAQ == "vibrant"~"v",
PAQ == "pleasant"~"p",
PAQ == "calm"~"ca",
PAQ == "uneventful"~"u",
PAQ == "monotonous"~"m",
PAQ == "annoying"~"a",
PAQ == "chaotic"~"ch"),
PAQ=factor(PAQ, level=c("e","v",
"p","ca","u",
"m","a",
"ch"))) %>%
dplyr::filter(
stimuliID %in% stimuliGrps[[plotGroup]]),
aes(x = stimuliID, y = Score)) +
geom_boxplot(aes(fill=ETHNICITY)) +
geom_signif(data=PAQ.combined.signif %>%
dplyr::filter(grepl("MY:M -",comparisons)) %>%
dplyr::filter(
stimuliID %in% stimuliGrps[[plotGroup]] &
grepl("MY:M -",comparisons)),
inherit.aes = F,
mapping=aes(xmin=x,xmax=xend,y_position=y,
annotations=ann.labels,group=stimuliID),
textsize = 4 ,color="black",vjust = 0.4,
tip_length = 0.05, manual=T) +
geom_signif(data=PAQ.combined.signif %>%
dplyr::filter(grepl("MY:O -",comparisons)) %>%
dplyr::filter(
stimuliID %in% stimuliGrps[[plotGroup]] &
grepl("MY:O -",comparisons)),
inherit.aes = F,
mapping=aes(xmin=x, xmax=xend, y_position=y,
annotations=ann.labels,group=stimuliID),
textsize = 4 ,color="black",vjust = 0.4,
tip_length = 0.05, manual=T) +
ylim(c(0,140)) + xlab("Stimuli") +
facet_wrap(facets = ~PAQ, ncol = 1, strip.position="right") +
theme(legend.position="bottom")
p.8PAQ.box
#ggsave(paste0("boxplots.pdf"),plot = p.8PAQ.box, width = 1700,
# height = 2300, units = "px",scale = 1.4)
ggsave(paste0("./outputs/boxplots.pdf"),
plot = p.8PAQ.box, width = 2300,
height = 2300, units = "px",scale = 1.4)
```
### Median contour plot for ISOPL and ISOEV across all stimuli
```{r PAQContourplot}
#Plot ISOPL and ISOEV contour plot
ISOPL.signif <- data.cit.sig %>%
dplyr::filter(PAQ %in% c("ISOPL","ISOEV")) %>%
dplyr::mutate(stimuliID=as.numeric(stimuliID))
ISOPLEV.combined.signif <- data.cit.sig %>%
#only ISOPL and ISOEV for plotting signif in contours
dplyr::filter(PAQ %in% c("ISOPL","ISOEV")) %>%
#extract comparison pair
dplyr::mutate(stimuliID=as.numeric(stimuliID),
#left comparison pair
ETHNICITY=ifelse(grepl("SG \\-",comparisons),"SG",
ifelse(grepl("MY:O -",comparisons),
"MY:O","MY:M"))) %>%
#retrieve ISOPL and ISOEV median values of 1st comparison pair
left_join(data.ISOPLEV.median,by=c("stimuliID","ETHNICITY")) %>%
#update colname to reflect PAIR1
dplyr::mutate(PAIR1.ETHNICITY=ETHNICITY,
PAIR1.ISOPL=ISOPL,
PAIR1.ISOEV=ISOEV,
#right comparison pair
ETHNICITY=ifelse(grepl("- SG",comparisons),"SG",
ifelse(grepl("- MY:O",comparisons),
"MY:O","MY:M")), .keep="unused") %>%
#retrieve ISOPL and ISOEV median values of 2nd comparison pair
left_join(data.ISOPLEV.median,by=c("stimuliID","ETHNICITY")) %>%
#update colname to reflect PAIR2
dplyr::mutate(PAIR2.ETHNICITY=ETHNICITY,
PAIR2.ISOPL=ISOPL,
PAIR2.ISOEV=ISOEV,
.keep="unused") %>%
#generate significance labels
dplyr::mutate(ann.labels=ifelse(
altP.adjusted<0.0001,
"****",
ifelse(altP.adjusted<0.001,
"***",
ifelse(altP.adjusted<0.01,
"**",
ifelse(altP.adjusted<0.05,"*","ns")))))
#create dataframe for ISOEV signif brace plotting
temp.df<-ISOPLEV.combined.signif %>% filter(PAQ=="ISOEV") %>%
pivot_longer(cols = c("PAIR1.ISOEV","PAIR2.ISOEV"),
values_to = c("ISOEV")) %>%
dplyr::select(c(ISOEV))
brace.df<-ISOPLEV.combined.signif %>% filter(PAQ=="ISOEV") %>%
pivot_longer(cols = c("PAIR1.ISOPL","PAIR2.ISOPL"),
values_to = c("ISOPL")) %>%
cbind(.,temp.df)
p.ISOPLEV.contour.signif<-p.ISOPLEV.contour.facetedStimuli +
#draw signif braces for ISOPL
geom_signif(data = ISOPLEV.combined.signif %>% filter(PAQ=="ISOPL"),
inherit.aes = F,
aes(y_position=c(0.5,0.9,0.2,0.4,0.8,0.6,0.2,0.3),
xmin=PAIR1.ISOPL,
xmax=PAIR2.ISOPL,
annotations = ann.labels),
manual = T) +
#draw signif braces for ISOEV
#right side brace: stimuli 4
stat_brace(data = brace.df %>% filter(stimuliID %in% c(4,20)),
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 90, labelrotate = 90, labelsize = 5,
distance = 0.2,width = 0.2,bending=0.01) +
#left side brace: stimuli 15
stat_brace(data = brace.df %>% filter(stimuliID == 15),
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 270, labelrotate = 270, labelsize = 5,
labeldistance = 0.3,
distance = 0.5,width = 0.2,bending=0.01) +
#right side brace: stimuli 7
stat_brace(data = brace.df %>% filter(stimuliID == 7) %>% .[1:2,],
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 90, labelrotate = 90, labelsize = 5,
labeldistance = 0.1,
distance = 0.05,width = 0.2,bending=0.01)+
#left side brace: stimuli 7
stat_brace(data = brace.df %>% filter(stimuliID == 7) %>% .[3:4,],
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 270, labelrotate = 270, labelsize = 5,
labeldistance = 0.3,
distance = 0.4,width = 0.2,bending=0.01) +
#right side brace: stimuli 12
stat_brace(data = brace.df %>% filter(stimuliID == 12) %>% .[1:2,],
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 90, labelrotate = 90, labelsize = 5,
labeldistance = 0.1,
distance = 0.2,width = 0.2,bending=0.01) +
#left side brace: stimuli 12
stat_brace(data = brace.df %>% filter(stimuliID == 12) %>% .[3:4,],
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 270, labelrotate = 270, labelsize = 5,
labeldistance = 0.2,
distance = 0.4,width = 0.2,bending=0.01) +
#right side brace: stimuli 22
stat_brace(data = brace.df %>% filter(stimuliID == 22) %>% .[1:2,],
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 90, labelrotate = 90, labelsize = 5,
distance = 0.1,width = 0.2,bending=0.01) +
#left side brace: stimuli 22
stat_brace(data = brace.df %>% filter(stimuliID == 22) %>% .[3:4,],
mapping=aes(x=ISOPL,y=ISOEV,
label=ann.labels),
inherit.aes = F,
rotate = 270, labelrotate = 270, labelsize = 5,
labeldistance = 0.2,
distance = 0.25,width = 0.2,bending=0.01) +
theme(legend.position = "bottom",
axis.text.x=element_text(angle = 90, vjust = 0.5, hjust=1))
p.ISOPLEV.contour.signif
ggsave("./outputs/ISOPLEVMedianContourNew.pdf",
plot = p.ISOPLEV.contour.signif,
width = 2500, height = 1150, units = "px",scale = 1.4)
```
## PCA
### Correlation matrix
```{r corr}
#perform PCA on 8 attributes
#my:m group
data.merged.mym<-data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(ETHNICITY=="MY:M") %>%
dplyr::select(c(eventful,vibrant,
pleasant,calm,
uneventful,monotonous,
annoying,chaotic))
data.merged.mym.cor<-cor(data.merged.mym)
#my:o group
data.merged.myo<-data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(ETHNICITY=="MY:O") %>%
dplyr::select(c(eventful,vibrant,
pleasant,calm,
uneventful,monotonous,
annoying,chaotic))
data.merged.myo.cor<-cor(data.merged.myo)
#sg group
data.merged.sg<-data.satp.zsm2.l$data.subj.zsm2 %>%
dplyr::filter(ETHNICITY=="SG") %>%
dplyr::select(c(eventful,vibrant,
pleasant,calm,
uneventful,monotonous,
annoying,chaotic))
data.merged.sg.cor<-cor(data.merged.sg)
#araus dataset
data.araus.cor<-cor(
data.araus %>%
dplyr::select(c(eventful,vibrant,
pleasant,calm,
uneventful,monotonous,
annoying,chaotic)))
```
### KMO and Bartlett's Test of Sphericity
```{r kmospher}
#KMO test
kmo<-rbind(KMO(data.merged.mym.cor)$MSA %>% as.data.frame() %>%
mutate(ETHNICITY="MY:M"),
KMO(data.merged.myo.cor)$MSA %>% as.data.frame() %>%
mutate(ETHNICITY="MY:O"),
KMO(data.merged.sg.cor)$MSA %>% as.data.frame() %>%
mutate(ETHNICITY="SG"),
KMO(data.araus.cor)$MSA %>% as.data.frame() %>%
mutate(ETHNICITY="ARAUS")) %>%
`colnames<-`(c("MSA","ETHNICITY"))
kmo
#Bartlett's Test of Sphericity
spher<-rbind(cortest.bartlett(data.merged.mym.cor,
n = nrow(data.merged.mym))$p.value %>%
as.data.frame() %>%
dplyr::mutate(ETHNICITY="MY:M"),
cortest.bartlett(data.merged.myo.cor,
n = nrow(data.merged.myo))$p.value %>%
as.data.frame() %>%
dplyr::mutate(ETHNICITY="MY:O"),
cortest.bartlett(data.merged.sg.cor,
n = nrow(data.merged.sg))$p.value %>%
as.data.frame() %>%
dplyr::mutate(ETHNICITY="SG"),
cortest.bartlett(data.araus.cor,
n = nrow(data.araus))$p.value %>%
as.data.frame() %>%
dplyr::mutate(ETHNICITY="ARAUS")) %>%
`colnames<-`(c("p-value","ETHNICITY"))
spher
```
### PCA
```{r pcamym}
#PCA of 8 paq for MY:M
paq.pca.MYM <- data.merged.mym %>%
prcomp(center = TRUE,scale. = TRUE,retx = TRUE)
#reflect y-axis
paq.pca.MYM$rotation[,2]<-paq.pca.MYM$rotation[,2]*-1
#plot PCA variables
paq.pca.MYM.p<-fviz_pca_var(paq.pca.MYM,
col.var = "darkred",
repel = TRUE # Avoid text overlapping
)
paq.pca.MYM.p
```
```{r pcamyo}
#PCA of 8 paq for MY:O
paq.pca.MYO <- data.merged.myo %>%
prcomp(center = TRUE,scale. = TRUE,retx = TRUE)
#plot PCA variables
paq.pca.MYO.p<-fviz_pca_var(paq.pca.MYO, col.var = "steelblue",
repel = TRUE # Avoid text overlapping
)
paq.pca.MYO.p
```
```{r pcasg}
#PCA of 8 paq for SG
paq.pca.SG <- data.merged.sg %>%
prcomp(center = TRUE,scale. = TRUE,retx = TRUE)
# #reflect x-axis and y-axis i.e. rotate 180deg
# paq.pca.SG$rotation[,1]<-paq.pca.SG$rotation[,1]*-1
# paq.pca.SG$rotation[,2]<-paq.pca.SG$rotation[,2]*-1
#plot PCA variables
paq.pca.SG.p<-fviz_pca_var(paq.pca.SG, col.var = "forestgreen",
repel = TRUE # Avoid text overlapping
)
paq.pca.SG.p
```
```{r pcaaraus}
#PCA of 8 paq for SG
paq.pca.ARAUS <- data.araus %>%
dplyr::select(c(eventful,vibrant,
pleasant,calm,
uneventful,monotonous,
annoying,chaotic)) %>%
prcomp(center = TRUE,scale. = TRUE,retx = TRUE)
#plot PCA variables
paq.pca.ARAUS.p<-fviz_pca_var(paq.pca.ARAUS, col.var = "maroon",
repel = TRUE # Avoid text overlapping
)
paq.pca.ARAUS.p
```
```{r pcaplot}
#summarise PCA data for plotting
pca.paq<-rbind(facto_summarize(paq.pca.SG, "var", axes = 1:2)[,-1] %>%
rownames_to_column(var = "PAQ") %>%
dplyr::mutate(ETHNICITY="SG",
#reflect x-axis and y-axis i.e. rotate 180deg
Dim.1=Dim.1*-1),
#Dim.2=Dim.2*-1),
facto_summarize(paq.pca.MYO, "var", axes = 1:2)[,-1] %>%
rownames_to_column(var = "PAQ") %>%
dplyr::mutate(ETHNICITY="MY:O"),
facto_summarize(paq.pca.MYM, "var", axes = 1:2)[,-1] %>%
rownames_to_column(var = "PAQ") %>%
dplyr::mutate(ETHNICITY="MY:M",
Dim.1=Dim.1*-1),
facto_summarize(paq.pca.ARAUS, "var", axes = 1:2)[,-1] %>%
rownames_to_column(var = "PAQ") %>%
dplyr::mutate(ETHNICITY="ARAUS",
Dim.1=Dim.1*-1))
#create rotation matrix for MY:M based on pleasantness at 90 deg
# Rotation angle in radians
rotation.angle.mym <- -atan(
pca.paq[pca.paq$ETHNICITY=="MY:M" &
pca.paq$PAQ=="pleasant","Dim.2"]/