-
Notifications
You must be signed in to change notification settings - Fork 0
/
Analyses.qmd
1026 lines (711 loc) · 27.6 KB
/
Analyses.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
---
title: "Pig Personality"
author: "Noah Stetson"
date: "`r Sys.Date()`"
format: html
editor: visual
editor_options:
chunk_output_type: inline
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE) #to be honest I have no idea what this does
```
# Personality In Pigs: Data Analysis
#### This is the data analysis for my undergraduate thesis on personality in pigs 🐷
### Goals:
1. Load library and datasets
- Load datasets from GitHub so people can look at them without having to download a billion CSV files
2. Clean data so it can be analyzed in a variety of ways
3. Look at survey data, how it varies, how pigs are scoring, etc.
- Internal reliability
- Inter-item correlation: Do certain test items correlate with each other? Do the test items correlate as expected?
- Inter-total correlation: Do certain personality scores correlate with each other?
- Inter-rater correlation: See how the 2 raters (D and T) correlate with how they scores the pigs
4. Look at behavioral data, how it varies, what pigs are doing, etc.
5. Compare survey data to behavioral data. Do certain behaviors correlate with certain survey scores?
6. Compare pig demographics to their behaviors and personality survey ratings/scores. Do certain demographics (like sex and background) correlate with any behaviors or personality survey results?
------------------------------------------------------------------------
## Loading library
#### Make sure to download these if you don't already have them
```{r}
library(tidyverse)
library(dplyr)
library(ggplot2)
library(psych)
library(readr)
library(corrplot)
library(irr)
library(lares)
```
## Loading datasets
#### Pulled from GitHub so **you don't need to change these or download the CSV files**!!
```{r}
obs <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/behavior_data/Obs_Clean.csv", show_col_types = FALSE) # behavior observations
behavior_counts <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/behavior_data/behavior_counts.csv", show_col_types = FALSE) # behavior observations but tidyer
behavior_cat_counts <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/behavior_data/behavior_cat_counts.csv", show_col_types = FALSE) # behavior observations but tidyer
svy <-read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/survey_data/Survey_Nov7_Clean.csv", show_col_types = FALSE) # survey data
svy_by_rater <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/survey_data/svy_with_averages.csv", show_col_types = FALSE) # survey data (but with scores split between raters)
D_svy <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/survey_data/svy_D.csv", show_col_types = FALSE) # survey data from rater D
T_svy <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/survey_data/svy_T.csv", show_col_types = FALSE) # survey data from rater T
Avg_svy <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/survey_data/svy_Avg.csv", show_col_types = FALSE) # survey data from averages of raters
meta <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/PigSample.csv", show_col_types = FALSE) # meta data (pig demographics)
```
## Cleaning Data
Put meta data into df based on pig id number
```{r}
svy_m <- inner_join(meta, svy, by = "PigID")
obs_m <- inner_join(meta, obs, by = "PigName")
svy_avg_m <- inner_join(meta, svy_by_rater, by = "PigID")
```
### Survey data
Test items only version
```{r}
svy_items <- svy_avg_m %>% select(1:14,'Time.Known.D','Time.Known.T','Time.Known.Avg','D1.D':'D35.D','D1.T':'D35.T','D1.Avg':'D35.Avg')
```
Facet scores only version
```{r}
svy_f <- svy_avg_m %>% select(1:14,'Time.Known.D','Time.Known.T','Time.Known.Avg','F1.D':'F4.D','F1.T':'F4.T','F1.Avg':'F4.Avg')
```
Sub-facet scores only version
```{r}
svy_sf <- svy_avg_m %>% select(1:14,'Time.Known.D','Time.Known.T','Time.Known.Avg','SC1.D':'SC12.D','SC1.T':'SC12.T','SC1.Avg':'SC12.Avg') # All of them
```
### Make tidy version of survey results
Items
```{r}
items_tidy <-svy_items %>%
pivot_longer(cols = 'Time.Known.D':'Time.Known.Avg', names_to = "Time.Known", values_to = 'Time.Known.Value')
items_tidy <-items_tidy %>%
pivot_longer(cols = 'D1.D':'D35.D', names_to = "item.D", values_to = 'item.D.value')
items_tidy <-items_tidy %>%
pivot_longer(cols = 'D1.T':'D35.T', names_to = "item.T", values_to = 'item.T.value')
items_tidy <-items_tidy %>%
pivot_longer(cols = 'D1.Avg':'D35.Avg', names_to = "item.Avg", values_to = 'item.Avg.value')
```
Facet scores
```{r}
facets_tidy <-svy_f %>%
pivot_longer(cols = 'Time.Known.D':'Time.Known.Avg', names_to = "Time.Known", values_to = 'Time.Known.Value')
facets_tidy <-facets_tidy %>%
pivot_longer(cols = 'F1.D':'F4.D', names_to = "facet.D", values_to = 'facet.D.value')
facets_tidy <-facets_tidy %>%
pivot_longer(cols = 'F1.T':'F4.T', names_to = "facet.T", values_to = 'facet.T.value')
facets_tidy <-facets_tidy %>%
pivot_longer(cols = 'F1.Avg':'F4.Avg', names_to = "facet.Avg", values_to = 'facet.Avg.value')
```
Sub-facet scores
```{r}
subfacets_tidy <-svy_sf %>%
pivot_longer(cols = 'Time.Known.D':'Time.Known.Avg', names_to = "Time.Known", values_to = 'Time.Known.Value')
subfacets_tidy <-subfacets_tidy %>%
pivot_longer(cols = 'SC1.D':'SC12.D', names_to = "subfacet.D", values_to = 'subfacet.D.value')
subfacets_tidy <-subfacets_tidy %>%
pivot_longer(cols = 'SC1.T':'SC12.T', names_to = "subfacet.T", values_to = 'subfacet.T.value')
subfacets_tidy <-subfacets_tidy %>%
pivot_longer(cols = 'SC1.Avg':'SC12.Avg', names_to = "subfacet.Avg", values_to = 'subfacet.Avg.value')
```
### Behavior Observations
```{r}
# Make wide version
behavior_counts_wide <-behavior_counts %>%
pivot_longer(cols = 2:21 , names_to = "Behavior", values_to = 'Count')
# Also make version with meta data
behavior_m <- inner_join(behavior_counts, meta, by = "PigName")
```
```{r}
# Make wide version
behavior_cat_counts_wide <-behavior_cat_counts %>%
pivot_longer(cols = 2:8 , names_to = "Behavior.Cat", values_to = 'Count')
# Also make version with meta data
behavior_cat_m <- inner_join(behavior_cat_counts, meta, by = "PigName")
```
okay done with that phew
------------------------------------------------------------------------
# Preliminary Analyses
## Overview of Personality Survey Scores
Item ratings
```{r}
all_items <- svy_items %>% select(16:120)
describe(all_items)
```
Sub-facet scores
```{r}
all_sf <- svy_sf %>% select(16:51)
describe(all_sf)
```
### As a graph
### Sort by main facet
```{r}
facets_tidy$facet.Avg <- factor(facets_tidy$facet.Avg, levels=rev(unique(facets_tidy$facet.Avg)))
ggplot(facets_tidy, aes(x= facet.Avg, y= facet.Avg.value)) +
geom_boxplot(color = "darkgoldenrod", fill='lightgoldenrod1') +
theme_classic() +
xlab("Personality Facet") +
ylab("Score") +
coord_flip() +
ggtitle("Variation in Personality Scores Across 20 Pigs")
```
### Graph of sub-facets
```{r}
subfacets_tidy$subfacet.Avg <- factor(subfacets_tidy$subfacet.Avg, levels=rev(unique(subfacets_tidy$subfacet.Avg)))
ggplot(subfacets_tidy, aes(x= subfacet.Avg, y= subfacet.Avg.value)) +
geom_boxplot(color = "darkgoldenrod", fill='lightgoldenrod1') +
theme_classic() +
xlab("Personality Sub-Facet") +
ylab("Score") +
coord_flip() +
ggtitle("Variation in Personality Scores Across 20 Pigs")
```
## Internal Reliability
### Inter-item correlation
(correlations between each pig's average raw item scores)
### Overall
UGLY !!!!
but good to look at the patterns or whatever
This shows how test item scores correlate across all the pigs
```{r}
item_matrix_table <- cor(svy_by_rater[,c(3:37)]) #3:37 is the test items
corrplot(item_matrix_table, addCoef.col = 1,
number.cex = 0.3, tl.cex = 0.5)
```
```{r}
avg_items <- Avg_svy %>% select(3:37)
inter_item <- avg_items %>% correlate() %>% select(-term)
inter <- colMeans(inter_item, na.rm = TRUE)
mean(inter)
# 0.00679244
inter
# this shows the item correlations as a table
```
### By facet
#### Fearfulness
This looks at all the test items that go with the "fearfulness" facet to see how well they correlate with each other
You would think that if all these test items are looking for the same thing, then they would mostly correlate with each other
```{r}
avg_f1 <- Avg_svy %>% select(D1.Avg, D5.Avg, D23.Avg, D3.Avg, D8.Avg, D19.Avg, D10.Avg, D18.Avg, D33.Avg, D13.Avg, D28.Avg, D34.Avg)
inter_f1 <- avg_f1 %>% correlate() %>% select(-term)
inter_f1 <- colMeans(inter_f1, na.rm = TRUE)
mean(inter_f1)
# 0.08263553 (low)
psych::alpha(avg_f1) # alpha value
# 0.47 (unacceptable)
```
#### Aggression Towards Humans
```{r}
avg_f2 <- Avg_svy %>% select(D6.Avg, D15.Avg, D31.Avg, D21.Avg, D25.Avg, D29.Avg)
inter_f2 <- avg_f2 %>% correlate() %>% select(-term)
inter_f2 <- colMeans(inter_f2, na.rm = TRUE)
mean(inter_f2)
# 0.3979195 (low)
psych::alpha(avg_f2)
# alpha: 0.75 (questionable)
```
#### Activity/Excitability
```{r}
avg_f3 <- Avg_svy %>% select(D12.Avg, D26.Avg, D32.Avg, D7.Avg, D14.Avg, D4.Avg, D11.Avg, D20.Avg, D17.Avg, D22.Avg, D30.Avg)
inter_f3 <- avg_f3 %>% correlate() %>% select(-term)
inter_f3 <- colMeans(inter_f3, na.rm = TRUE)
mean(inter_f3)
# 0.06783288 (low)
psych::alpha(avg_f3)
# 0.55 (poor)
```
#### Aggression/Dominance towards Pigs
```{r}
avg_f4 <- Avg_svy %>% select(D2.Avg, D16.Avg, D27.Avg, D9.Avg, D24.Avg, D35.Avg)
inter_f4 <- avg_f4 %>% correlate() %>% select(-term)
inter_f4 <- colMeans(inter_f4, na.rm = TRUE)
mean(inter_f4)
#0.1235088 (low)
psych::alpha(avg_f4)
# 0.56 (poor)
```
Hmm so it looks like the items that are supposed to be for the same construct actually correlate pretty low
### Inter-total correlation
(correlations between calculated personality sub-facet scores)
This could help me see how well different personality traits correlate with each other
For example, maybe fear of humans (SC4) and companionability (SC10) have a negative correlation idk
```{r}
svy_matrix_table <- cor(svy_by_rater[,c(38:49)]) #38:39 is the sub-facets
corrplot(svy_matrix_table, addCoef.col = 1,
number.cex = 0.6, tl.cex = 0.7)
```
#### Strongish correlations I am noticing:
- 1 and 10 (-.78) (fear of humans negatively correlated with companionability)
- 3 and 12 (-.73) (fear of pigs negatively correlated with dominance over other pigs)
- 4 and 10 (-.75) (fear of handling negatively correlated with companionability)
- 6 and 12 (.79) (situational aggression positively correlated with dominance over other pigs)
#### Same thing but as a table
```{r}
avg_sf <- Avg_svy %>% select(38:49)
inter_total_sf <- avg_sf %>% correlate() %>% select(-term)
inter_total_sf_no_na <- colMeans(inter_total_sf, na.rm = TRUE)
```
## Inter-rater Reliability
Do rater 1 and rater 2 score each pig in a similar way
Make a new df because my brain is so smooth I literally cannot figure out how else to do it
```{r}
svy_wide <-svy_m %>%
pivot_longer(cols = 18:52, names_to = "item", values_to = 'item.value')
svy_wide <- svy_wide %>%
pivot_longer(cols = 18:29, names_to = "sub.facet", values_to ='subfacet.value')
svy_wide <- svy_wide %>%
pivot_longer(cols = 18:21, names_to = "facet", values_to = 'facet.value')
```
### See how rater D and T compare in how they overall scored the pigs
(between different personality sub-facets)
```{r}
svy_wide$sub.facet <- factor(svy_wide$sub.facet, levels=rev(unique(svy_wide$sub.facet)))
#this reorders the tick marks so it's not out of order
# why didn't it do it
ggplot(svy_wide, aes(x= sub.facet, y= subfacet.value, fill = Rater)) +
geom_boxplot() +
theme_classic() +
scale_fill_manual(values = c("powderblue", "goldenrod1")) + #change colors and add outline
xlab("Personality Sub-Facet") +
ylab("Score") +
ggtitle("Variation in Personality Scores Across 20 Pigs")
```
Overall, rater D appears to have more variation in their ratings than rater T
### Cohen's Kappa
I generated all these data frames by hand because I am stupid and dumb
#### How to interpret based on what Cohen said:
0 or less: No agreement
0.01-0.20: None to slight
0.21-0.40: Fair
0.41-0.60: Moderate
0.61-0.80: Substantial
0.81-1.00: Almost perfect
#### SC1 (Fear of Humans)
Kappa = 0.27
```{r}
irr_sc1 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc1.csv", show_col_types = FALSE)
kappa2(irr_sc1[,c(1,2)], "equal")
```
#### SC2 (Nonsocial Fear)
Kappa = 0.167
```{r}
irr_sc2 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc2.csv", show_col_types = FALSE)
kappa2(irr_sc2[,c(1,2)], "equal")
```
#### SC3 (Fear of Pigs)
Kappa = 0.0832
```{r}
irr_sc3 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc3.csv", show_col_types = FALSE)
kappa2(irr_sc3[,c(1,2)], "equal")
```
#### SC4 (Fear of Handling)
Kappa = 0.27
```{r}
irr_sc4 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc4.csv", show_col_types = FALSE)
kappa2(irr_sc4[,c(1,2)], "equal")
```
#### SC5 (General Aggression)
Kappa = 0.202
```{r}
irr_sc5 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc5.csv", show_col_types = FALSE)
kappa2(irr_sc5[,c(1,2)], "equal")
```
#### SC6 (Situational Aggression)
Kappa = -0.0165
```{r}
irr_sc6 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc6.csv", show_col_types = FALSE)
kappa2(irr_sc6[,c(1,2)], "equal")
```
#### SC7 (Excitability)
Kappa = -0.132
```{r}
irr_sc7 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc7.csv", show_col_types = FALSE)
kappa2(irr_sc7[,c(1,2)], "equal")
```
#### SC8 (Playfulness)
Kappa = 0.0446
```{r}
irr_sc8 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc8.csv", show_col_types = FALSE)
kappa2(irr_sc8[,c(1,2)], "equal")
```
#### SC9 (Active Engagement)
Kappa = 0.199
```{r}
irr_sc9 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc9.csv", show_col_types = FALSE)
kappa2(irr_sc9[,c(1,2)], "equal")
```
#### SC10 (Companionability)
Kappa = 0.13
```{r}
irr_sc10 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc10.csv", show_col_types = FALSE)
kappa2(irr_sc10[,c(1,2)], "equal")
```
#### SC11 (Aggression Towards Pigs)
Kappa = 0.101
```{r}
irr_sc11 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc11.csv", show_col_types = FALSE)
kappa2(irr_sc11[,c(1,2)], "equal")
```
#### SC12 (Dominance Over Other Pigs)
Kappa = 0.269
```{r}
irr_sc12 <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/irr_dfs/irr_sc12.csv", show_col_types = FALSE)
kappa2(irr_sc12[,c(1,2)], "equal")
```
Overall it looks like the raters don't really agree on their assessments, though it does vary between personality sub-facets
### Graph comparing Kappa scores between sub-facets
Line shows where there is "fair" inter-observer reliability
```{r}
irr_results <- read_csv("https://raw.githubusercontent.com/nwstetson/PigPersonality/main/survey_data/irr_dfs/irr_results.csv", show_col_types = FALSE)
ggplot(irr_results, aes(x = Sub.facet, y = Kappa) ) +
geom_col(color = "navy", fill='lightsteelblue1') +
theme_classic() +
xlab("Personality Sub-Facet") +
ylab("Kappa") +
ggtitle("Inter-Rater Reliability Across Personality Scores") +
geom_hline(yintercept=0.21, linetype="dashed", color = "red")
```
Mean IRR (not high)
```{r}
mean(irr_results$Kappa)
```
So that's not great but I will compare the pigs scores by using their average score between the 2 raters
## Overview of Behaviors
Yes I recorded everything in counts instead of times big mistake I don't want to talk about it 😍
### As a graph
they nudge the ground and sleep
```{r}
ggplot(behavior_counts_wide, aes(x= Behavior, y= Count)) +
geom_boxplot(color = "navy", fill='lightsteelblue1') +
theme_classic() +
xlab("Behavior") +
ylab("Counts") +
ggtitle("Differences in Behavior Between Pigs")
```
Categories version
```{r}
ggplot(behavior_cat_counts_wide, aes(x= Behavior.Cat, y= Count)) +
geom_boxplot(color = "navy", fill='lightsteelblue1') +
theme_classic() +
xlab("Behavior") +
ylab("Counts") +
ggtitle("Differences in Behavior Between Pigs")
```
------------------------------------------------------------------------
# Primary Analyses
### Do personality scores correlate with observable behaviors?
Make DF with behaviors and scores
```{r}
behavior_and_scores <- inner_join(behavior_m, Avg_svy, by = "PigID")
behavior_cat_and_scores <- inner_join(behavior_cat_m, Avg_svy, by = "PigID")
```
## Top correlations overview
AHH IT'S TERRIFYING
```{r}
svy_behav_matrix_table <- cor(behavior_and_scores[,c(2:21, 37:87)]) #takes out demographics
describe(svy_behav_matrix_table) # overview of correlations
corrplot(svy_behav_matrix_table, addCoef.col = 1,
number.cex = 0.6, tl.cex = 0.7) # all the correlations
corrplot(svy_behav_matrix_table, addCoef.col = 1,
number.cex = 0.4, tl.cex = 0.5, order="hclust", type="upper") # top correlations
```
Looking closer at top correlations
```{r}
svy_behav <- behavior_and_scores %>% select(2:21, 37:84)
corr_cross(svy_behav, # dataset
max_pvalue = 0.05, # show only sig. correlations at selected level
top = 25)# display top 10 correlations, any couples of variables
```
### Fearfulness
```{r}
ggplot(behavior_cat_and_scores, aes(x=Anxious, y=F1.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Number of Fearful Behaviors") +
ylab("Fearfulness Score") +
ggtitle("Fearfulness Score Versus Fearful Behaviors")
# Pearson's correlation
cor.test(behavior_cat_and_scores$Anxious, behavior_cat_and_scores$F1.Avg)
# cor = -0.1384581 (very weak negative correlation)
# p-value = 0.5605
```
### Activity/Excitability
```{r}
ggplot(behavior_cat_and_scores, aes(x=Anxious, y=F3.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Number of Active Behaviors") +
ylab("Activity/Excitability Score") +
ggtitle("Activity/Excitability Score Versus Active Behaviors")
# Pearson's correlation
cor.test(behavior_cat_and_scores$Activity, behavior_cat_and_scores$F3.Avg)
# cor = 0.3857312 (moderate positive correlation)
# p-value = 0.09302
```
### Aggression Towards other Pigs
```{r}
ggplot(behavior_cat_and_scores, aes(x=G.agg, y=F2.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Number of Aggressive Behaviors") +
ylab("Aggression/Dominance Towards Pig Score") +
ggtitle("Aggression/Dominance towards Pigs Score Versus Agressive Behaviors")
# Pearson's correlation
cor.test(behavior_cat_and_scores$G.agg, behavior_cat_and_scores$F2.Avg)
# cor = -0.1326601 (very weak negative correlation)
# p-value = 0.5772
```
```{r}
ggplot(behavior_and_scores, aes(x=Attempt.disp, y=SC11.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Times Displaced") +
ylab("Aggression Score") +
ggtitle("Displacements vs Aggression Score")
# Pearson's correlation
cor.test(behavior_and_scores$Attempt.disp, behavior_and_scores$SC11.Avg)
# cor = 0.285504 (weak positive correlation)
# p-value = 0.2224
```
```{r}
ggplot(behavior_and_scores, aes(x=Get.disp, y=SC11.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Times Displaced") +
ylab("Aggression Score") +
ggtitle("Do Pigs that Score Higher on Aggression Get Displaced Less?")
# Pearson's correlation
cor.test(behavior_and_scores$Get.disp, behavior_and_scores$SC11.Avg)
# cor = -0.397797 (moderate negative correlation)
# p-value = 0.08239
```
------------------------------------------------------------------------
## Behaviors (but not in categories this time) vs personality results
#### Get.disp vs SC12 (dominance over pigs)
```{r}
ggplot(behavior_and_scores, aes(x=Get.disp, y=SC12.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Times Displaced") +
ylab("Dominance Score") +
ggtitle("Do Pigs that Score Higher on Dominance Get Displaced Less?")
# Pearson's correlation
cor.test(behavior_and_scores$Get.disp, behavior_and_scores$SC12.Avg)
# -0.2143021 (weak negative correlation)
```
#### Attempt.disp vs SC12 (dominance over pigs)
```{r}
# Correlation between pig's SC12 vs # of times they attempted to displace another pig
ggplot(behavior_and_scores, aes(x=Attempt.disp, y=SC12)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Times Attempt Displace") +
ylab("Dominance Score") +
ggtitle("Do Pigs that Score Higher on Dominance Displace Pigs More?")
# Pearson's correlation
cor.test(behavior_and_scores$Attempt.disp, behavior_and_scores$SC12)
# 0.1807212 #also weak
```
#### Attempt.disp vs SC8 (playfulness)
```{r}
ggplot(behavior_and_scores, aes(x=Attempt.disp, y=SC8.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Times Attempt Displace") +
ylab("Playfulness Score") +
ggtitle("Pigs that Displace Pigs More Score Lower in Playfulness")
# Pearson's correlation
cor.test(behavior_and_scores$Attempt.disp, behavior_and_scores$SC8.Avg)
# cor = -0.4235986
```
### Travel vs SC9 (active engagement)
```{r}
ggplot(behavior_and_scores, aes(x=Travel, y=SC9.Avg)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Times Traveling") +
ylab("Active Engagement Score") +
ggtitle("Do Pigs that Score High on Active Engagement Travel More?")
# Pearson's correlation
cor.test(behavior_and_scores$Travel, behavior_and_scores$SC9)
#0.3479849
```
### Resting in proximity vs fear of humans
```{r}
cor.test(behavior_and_scores$Rest.proxim, behavior_and_scores$SC1.Avg)
#SC1 = -0.2909014
```
### Getting displaced vs companionability
```{r}
# Pearson's correlation
cor.test(behavior_and_scores$SC10.Avg, behavior_and_scores$Get.disp)
# 0.461596
ggplot(behavior_and_scores, aes(x=SC10.Avg, y=Get.disp)) +
geom_point() +
stat_smooth(method = "lm") +
xlab("Times Pig Gets Displaced") +
ylab("Companionability Score") +
ggtitle("Pigs that Score Higher in Companionability Get Displaced More")
```
so I don't think behaviors really correlate with the personality scores but maybe it's because I had to change my survey last-minute and my ethogram no longer matched up with it like it was supposed to 😥
------------------------------------------------------------------------
# Additional Analyses
### Are there any sex differences in behavior?
Oh hmm not really
```{r}
corr_var(behavior_m, # dataset
Sex_num, # name of variable to focus on
top = 10) # display top 10 correlations
```
### Is there a sex difference in personality scores?
Maybe a little bit for aggression, but weak
```{r}
corr_var(svy_avg_m, # dataset
Sex_num, # name of variable to focus on
top = 10) # display top 10 correlations
```
### What about fearfulness?
Cor = -0.2600817
p = 0.2681
t= -1.1428
```{r}
cor.test(svy_avg_m$Sex_num, svy_avg_m$F1.Avg)
```
Sex vs aggression towards humans
Cor = -0.5578186
t = -2.8515
p= 0.0106
```{r}
cor.test(svy_avg_m$Sex_num, svy_avg_m$F2.Avg)
# Significant for F2. Here's what the mean scores are:
aggregate(svy_avg_m$F2.Avg, list(svy_avg_m$Sex), FUN=mean)
```
Activity/Excitablity
cor = 0.3940262
t = 1.8189
p = 0.08561
```{r}
cor.test(svy_avg_m$Sex_num, svy_avg_m$F3.Avg)
```
Aggression/Dominance Towards Pigs
t = -0.13546
cor = -0.03191228
p = 0.8938
```{r}
cor.test(svy_avg_m$Sex_num, svy_avg_m$F4.Avg)
```
Dominance?
Cor = 0.3450894
also very small
```{r}
cor.test(svy_avg_m$Sex_num, svy_m$F3)
```
### Overview of sex differences in personality scores
In SC1 it looks like males have greater variation than females
```{r}
ggplot(svy_wide, aes(x= sub.facet, y= subfacet.value, fill = Sex)) +
geom_boxplot() +
theme_classic() +
scale_fill_manual(values = c("powderblue", "goldenrod1")) +
xlab("Personality Sub-Facet") +
ylab("Score") +
ggtitle("Sex Differences in Personality Scores Across 20 Pigs")
```
Same thing but in big main facets instead of sub-facets
I mean it looks like there's kind of a difference but the correlations are small, I guess because the sample size is so small too
```{r}
ggplot(svy_wide, aes(x= facet, y= facet.value, fill = Sex)) +
geom_boxplot() +
theme_classic() +
scale_fill_manual(values = c("powderblue", "goldenrod1")) +
xlab("Personality Facet") +
ylab("Score") +
ggtitle("Sex Differences in Personality Scores Across 20 Pigs")
```
### Sex differences in getting displaced???
```{r}
ggplot(behavior_m, aes(x=Get.disp, fill = Sex)) +
theme_classic() +
xlab("Times Getting Displaced") +
ylab("umm math i think") +
ggtitle("Do Male Pigs Get Displaced Less Than Female Pigs?") +
geom_density(alpha = 0.4) +
theme_minimal() +
scale_fill_manual(values = c("goldenrod1", "darkorchid4"))
ggplot(behavior_m, aes(x=Get.disp, fill = Sex)) +
theme_classic() +
xlab("Times Getting Displaced") +
ylab("umm math i think") +
ggtitle("Do Male Pigs Get Displaced Less Than Female Pigs?") +
geom_hist() +
theme_minimal() +
scale_fill_manual(values = c("goldenrod1", "darkorchid4"))
```
### Background differences maybe?
#### Behaviors
umm please just look at behaviors R stop doing that
anyway it looks like it doesn't really correlate with anything
```{r}
corr_var(behavior_m, # dataset
Background_num, # name of variable to focus on
top = 25) # display top 10 correlations
```
### Background
```{r}
cor.test(svy_avg_m$Background_num, svy_avg_m$F1.Avg)
cor.test(svy_avg_m$Background_num, svy_avg_m$F2.Avg)
cor.test(svy_avg_m$Background_num, svy_avg_m$F3.Avg)
cor.test(svy_avg_m$Background_num, svy_avg_m$F4.Avg)
# Significant for F2. Here's what the mean scores are:
aggregate(svy_avg_m$F2.Avg, list(svy_avg_m$Background), FUN=mean)
```
### Group
```{r}
cor.test(svy_avg_m$Group_num, svy_avg_m$F1.Avg)
cor.test(svy_avg_m$Group_num, svy_avg_m$F2.Avg)
cor.test(svy_avg_m$Group_num, svy_avg_m$F3.Avg)
cor.test(svy_avg_m$Group_num, svy_avg_m$F4.Avg)
```
### Time Informant has Known Pig
```{r}
cor.test(svy_avg_m$Time.Known.Avg, svy_avg_m$F1.Avg)
cor.test(svy_avg_m$Time.Known.Avg, svy_avg_m$F2.Avg)
cor.test(svy_avg_m$Time.Known.Avg, svy_avg_m$F3.Avg)
cor.test(svy_avg_m$Time.Known.Avg, svy_avg_m$F4.Avg)
```
```{r}
ggplot(svy_avg_m, aes(y= F4.Avg, x= Time.Known.Avg)) +
geom_point() +
theme_classic() +
stat_smooth(method = "lm") +
scale_fill_manual(values = c("powderblue", "goldenrod1")) +
xlab("Months Informant Has Known Pig For") +
ylab("Aggression/Dominance Towards Pigs Score") +
ggtitle("Months Known vs Aggression/Dominance Towards Pigs Score")
```
#### Survey results vs background
lol again it's just showing it correlates more with other demographics than survey items/scores
nothing over .5 so it doesn't look like it matters
```{r}
corr_var(svy_avg_m, # dataset
Background_num, # name of variable to focus on
top = 10) # display top 10 correlations
```