forked from mahagadorn/nomia_neuroplasticity
/
Nmel_Experiment1_DataAnalysis.Rmd
1174 lines (869 loc) · 37.5 KB
/
Nmel_Experiment1_DataAnalysis.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: "Nomia melanderi (Experiment 1): age- and experience-related effects on neuroplasticity"
author: "M.A. Hagadorn"
date: "`r format(Sys.time(), '%B %d, %Y')`"
output:
pdf_document:
toc: true
toc_depth: 4
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(
echo = TRUE,
warning = TRUE,
background = "#F7F7F7",
highlight = TRUE)
```
```{r packagesload, warning=FALSE, echo=FALSE, message=FALSE, include=FALSE}
#Load Required Packages
library(knitr)
library(plyr)
library(dplyr)
library(ggplot2)
library(Rmisc) #summarySE
library(car)#Anova
library(rcompanion) #plotNormalDensity
library(stats) #lm
library(nortest)
library(multcomp) #boxcox, glht
```
```{r sessioninformation, echo=FALSE}
installed.packages()[names(sessionInfo()$otherPkgs), "Version"]
```
\newpage
\section{Summary of the Data and What we Collected}
The aim of this project is to examine age- and experience-related neuroplasticity in *Nomia melanderi*. Treatment groups include *newly emerged* (zero-day old), lab-reared (10 days old), and reproductively active, nesting (age unknown) bees. To assess age-related neuroplasticity, we will compare newly emerged and lab-reared bees. To assess experience-related neuroplasticity, we will compare lab-reared to nesting bees. Brains were collected during summer 2016 in Walla Walla, WA.
See methods and ESM for rearing, dissections, and imaging specifics. Confocal stacks were traced blind to treatment grouped. Structures traced independently include: left and right lateral and medial lips, left and right lateral and medial collar, left and right lateral and medial kenyon cells, left and right mushroom body lobes (including basal rings, peduncles, and alpha, beta, gamma lobes), antennal lobes, and the centralcomplex. Whole brain measurements were used to scale structures relative to total brain size. Traces were made every slided (i.e. every 5 um).
\subsection{Treatment Groups}
In this analysis, 3 different treatment groups will be compared.
```{r txtable, echo=FALSE}
#library(knitr)
description <- c("Newly Emerged", "Lab Reared", "Nesting")
SampleSize <- c(7,7,7)
tx_table <- cbind(description, SampleSize)
colnms <- c("Description", "Sample Size")
kable(tx_table, col.names = colnms, align=c('l', 'c'), caption = "Treatment group and corresponding samples sizes.")
```
\section{Load in the Data}
The data being loaded in is the raw data renamed ```XXXX``` to avoid overwriting any of the original data. Once loaded in, these data will be converted into proportions of whole brain volumes and contains measurements for the following brain structures: ```centralcomplex, left_lateral_calyx, left_medial_calyx, left_lateral_kc, left_medial_kc, left_mblobe, left_al, right_lateral_calyx, right_medial_calyx, right_lateral_kc, right_medial_kc, right_mblobe, right_al, and wholebrain```.
```{r loadindata, echo=FALSE}
#Using setwd() you need to designate your respective file path; MAH file path excluded for privacy
setwd() #designate file path
data <- read.table("Experiment1_structurevolume.csv", header = TRUE, sep = ",", stringsAsFactors = FALSE)
data <- data[1:23, 1:22]
```
\section{Remove TX2 Samples}
Our lab-reared bees consists of two collapsed treatment groups : tx 2 and tx3. TX two were lab-reared bees that were housed with alfalfa. Tx3 bees, however, were housed without alfalfa.
TX2: sugar water + pollen + alfalfa flowers
<br />
TX3: sugar water + pollen WITHOUT alfalfa flowers.
Since alfala presence could be a confounding factor, we removed all treatment two bees.
```{r removetx2, echo=FALSE}
#removes tx2 samples
data <- data[-c(1,3),]
```
\section{Sum Specific Structures}
\subsection{Summing Across Bilateral Measurements}
Before analyzing the data we need to sum across all bilateral measurements to get one value for each structure (i.e. ```left_lateral_lip + right_lateral_lip``` to get one value for the lateral lips.)
The table below summarizes how the values were summed and their new naming code.
##Record of what data are being summed
```{r collapsedtable, echo=FALSE}
#library(knitr)
sumstructures <- c("central complex","lips", "collars", "calyces","mushroom body lobes", "antennal lobes", "kenyon cells", "neuropil")
sumstructcode <- c("cc", "lips", "collar", "calyces", "mblobes", "als", "kcs", "neuropil")
collapsed_structures <- c("central complex", "left_lateral_lips + right_lateral_lips + left_medial_lips + right_medial_lips",
"left_lateral_collar + right_lateral_collar + left_medial_collar +
right_medial_collar", "left_lateral_lips + right_lateral_lips + left_medial_lips + right_medial_lips + left_lateral_collar + right_lateral_collar + left_medial_collar +
right_medial_collar", "left_mblobes + right_mblobes", "left_al + right_al", "left_lateral_kc + right_lateral_kc
left_medial_kc + right_medial_kc", "sum all neuropil for N:K")
sum_data_table <- cbind(sumstructures, sumstructcode, collapsed_structures)
colnms <- c("Summed Structures", "Name", "Individual Structures Collapsed")
kable(sum_data_table, col.names = colnms, align=c('l', 'l', 'l'), caption = "Information for specific structures that were summed to make 'combined' structures")
```
\subsection{Summing the data}
In this section, we sum structures from the left and right side of the brain to get a value for each structure. For instance, if we want to get a measurement for the lips, we would sum across both medial and lateral lips from the left and right side of the brain (see Table 2 for details on summed structures.)
Below is an example of how these summed values were obtained in R.
```{r sumdataexample}
#Example Code
#lip <- apply(data[,c("left_lateral_lip","right_lateral_lip", "left_medial_lip",
# "right_medial_lip")], 1, sum)
```
```{r sumthedata, echo=FALSE}
#to sum the lateral and medial lips (left and right)
lip <- apply(data[,c("left_lateral_lip","right_lateral_lip", "left_medial_lip",
"right_medial_lip")], 1, sum)
#to sum the lateral and medial collar (left and right)
collar <- apply(data[,c("left_lateral_collar","right_lateral_collar", "left_medial_collar",
"right_medial_collar")], 1, sum)
#to sum the calyces (left and right lateral and medial lips and collars)
calyces <- apply(data[,c("left_lateral_lip", "left_lateral_collar", "right_lateral_lip",
"right_lateral_collar", "left_medial_lip", "left_medial_collar",
"right_medial_lip", "right_medial_collar")], 1, sum)
#to sum the mushroom body lobes (left and right)
mblobes <- apply(data[,c("left_mblobe","right_mblobe")], 1, sum)
#to sum the antennal lobes (left and right)
als <- apply(data[,c("left_al","right_al")], 1, sum)
#to sum the kenyon cells (left and right lateral and medial Kenyon cells)
kcs <- apply(data[,c("left_lateral_kc", "left_medial_kc", "right_medial_kc",
"right_lateral_kc")], 1, sum)
neuropil <- apply(data[,c("left_lateral_lip", "left_lateral_collar", "right_lateral_lip",
"right_lateral_collar", "left_medial_lip", "left_medial_collar",
"right_medial_lip", "right_medial_collar", "left_mblobe",
"right_mblobe")], 1, sum)
#bind to create new dataframe containing these columns
data_plussumdata <- cbind(data, lip, collar, calyces, mblobes, als, kcs, neuropil)
```
\section{Scale structure volumes relative to whole brain volumes}
Here we recalculate structure volumes as a proportion of the whole brain volumetric measurements.
\subsection{Make New Table: Containing Summed Structures}
```{r mk_tableonlysummedstructures}
#make a new table with only the factors and the data we want to take whole brain proportions of...
sumdata <- data_plussumdata[,-c(6:21)]
```
\subsection{Scale as whole brain proportions}
Below is example code for how structures were calculated as a proportion of the whole brain.
```{r examplecodewholebrain, echo=TRUE, eval=FALSE}
#calculate relative to wholebrain
#using mutate we can add the calculated column to our dataframe
sumdata <- mutate(sumdata, cc_relWB = centralcomplex/wholebrain) # central complex
```
```{r relativetoWB, echo=FALSE}
#calculate relative to wholebrain
#using mutate we can add the calculated column directly to our dataframe
#library(dplyr)
sumdata <- mutate(sumdata, cc_relWB = centralcomplex/wholebrain) # central complex
sumdata <- mutate(sumdata, lip_relWB = lip/wholebrain) # lips
sumdata <- mutate(sumdata, col_relWB = collar/wholebrain) # collar
sumdata <- mutate(sumdata, calyces_relWB = calyces/wholebrain) # calyces
sumdata <- mutate(sumdata, mblobes_relWB = mblobes/wholebrain) # mblobes
sumdata <- mutate(sumdata, als_relWB = als/wholebrain) # als
sumdata <- mutate(sumdata, kcs_relWB = kcs/wholebrain) # kcs
sumdata <- mutate(sumdata, neuropil_relWB = neuropil/wholebrain) # neuropil
sumdata <- mutate(sumdata, nk_relWB = neuropil_relWB/kcs_relWB) # N:K
```
```{r savepropdata, echo=FALSE}
#This file will be used when making figures
write.csv(sumdata,"Nmel_NELrRep2016_structurevolume_proportiondata.csv")
```
```{r mk_propdata, echo=FALSE}
##Make New Table: just the proportion data
#make a new table with only the factors whole brain proportion data
propdata <- sumdata[,-c(5:13)]
```
\section{Assigning factors}
```{r assign factors}
propdata$code <- factor(propdata$code, levels=c("NewEmerge", "LabReared", "Nesting"))
propdata$tracer <- factor(propdata$tracer)
propdata$bed <- factor(propdata$bed)
#All factors assigned appropriately
print(str(propdata))
```
\subsection{Relevel the factors of the dataframe to assign 'newly emerged' as the base}
Usinging ```relevel``` and ```ref``` we can make newly emerged bees the baseline for comparison.
```{r relevelfactors}
propdata <- within(propdata, code <-relevel(code, ref = "NewEmerge"))
```
\section{Whole Brain ANOVA}
\subsection{Anova}
To make sure that whole brain measurements were not significantly different between treatment groups, we used an ANOVA to compare means.
```{r wholebrain_analysis}
wholebrain_lm <- lm(data$wholebrain ~ code, data = data)
print(summary(wholebrain_lm))
#conduct anova
anova_lm_wb <- Anova(wholebrain_lm)
print(anova_lm_wb)
```
\subsection{Verify Assumptions}
```{r assumptions_wholebrain}
res.lmwb <- residuals(wholebrain_lm)
par(mfrow=c(1,2))
plotNormalDensity(res.lmwb)
qqPlot(data$wholebrain, "norm")
print(ad.test(data$wholebrain))
#Homogeneity of variance
#Ho: The distributions are the same.
#Ha: The distributions are not the same.
#aka if the p-value is <0.05 then you can conclude a lack of homogenetity of variance.
print(leveneTest(wholebrain ~ code, data = data))
```
\section{Data Anaylsis: One-Way ANOVA comparing relative volumes of brain structures between Newly Emerged, Lab Reared, and Nesting bees}
\subsection{Lips}
\subsubsection{Summary Statistics}
```{r meansum_lips, echo=FALSE}
#library(Rmisc)
ss_lip_relWB <- summarySE(propdata,
measurevar = "lip_relWB",
groupvars = c("code"))
kable(ss_lip_relWB)
```
```{r bp_lip, echo=FALSE}
#function for identifying outliers
is_outlier <- function(x){
return(x < quantile(x, 0.25)-1.5 * IQR(x) | x > quantile(x, 0.75) + 1.5 * IQR(x))
}
#Creates a seperate table that specifies the outliers unique identifier
#With ID, go back and verify that outlier isn't due to methodological issues
samples_propdata <- propdata[,-1]
rownames(samples_propdata) <- propdata[,1]
outlier_test_lip <- samples_propdata %>% tibble::rownames_to_column(var="outlier") %>% group_by(code) %>% mutate(is_outlier=ifelse(is_outlier(lip_relWB), lip_relWB, as.numeric(NA)))
outlier_test_lip$outlier[which(is.na(outlier_test_lip$is_outlier))] <- as.numeric(NA)
#Boxplot
ggplot(propdata, aes(x=code, y=lip_relWB, fill=code)) +
geom_boxplot() +
scale_fill_manual(values = c("gray","darkgoldenrod1", "cyan3")) +
ggtitle("Lips") +
annotate("text", x=1, y=0.043 ,label="A12.21", size=3) +
annotate("text", x=1, y=0.031 ,label="A12.23", size=3) +
scale_y_continuous(name = "Volume Relative to Whole Brain", limits = c(0.03,.07)) +
scale_x_discrete(name = "Treatment Group", labels = c("Newly Emerged", "Lab Reared", "Nesting")) +
theme(text = element_text(color="black",size = 15),
axis.title = element_text(color="black"),
axis.text.x = element_text(color="black", size = 15, margin = margin(t = 5, r =0, b = 20, l = 0)),
axis.text.y = element_text(color="black", size = 15, margin = margin(t = 0, r =5, b = 0, l = 20)),
axis.ticks.length = unit (.5,"cm"),
legend.position = 'none',
legend.background = element_blank(),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 1, linetype = "solid",colour = "black"),
plot.title = element_text(hjust=0.5))
```
\subsubsection{ANOVA}
```{r anova_lip}
#model
lm_lip <- lm(propdata$lip_relWB ~ code, data = propdata)
print(summary(lm_lip))
#conduct Anova
anova_lm_lip <- Anova(lm_lip)
print(anova_lm_lip)
```
\subsubsection{Verifying Assumptions}
Checking for:
<br />
1) The data are normally distributed
<br />
2) Homogeneity of Variance
```{r assumptions_lip, echo=FALSE}
res.lmlip <- residuals(lm_lip)
par(mfrow=c(1,2))
plotNormalDensity(res.lmlip)
qqPlot(propdata$lip_relWB, "norm")
#Anderson Darling test for normality
#Ho: The residuals are normally distributed
#Ha: The residuals are not normally distributed
#aka if the p-value is <0.05 then you can conclude that the data are not normally distributed
print(ad.test(propdata$lip_relWB))
#Homogeneity of variance
#Ho: The distributions are the same.
#Ha: The distributions are not the same.
#aka if the p-value is <0.05 then you can conclude a lack of homogenetity of variance.
print(leveneTest(lip_relWB~code, data = propdata))
```
Normality: Assumption Violated.
<br />
Variance: Assumption met.
\subsubsection{Assumptions Violated: Box-Cox Transformation}
```{r BoxCoxlm_lip, echo=TRUE, eval=TRUE, fig.height=3.5}
##Box-Cox Transformation
bc_lip <- boxcox(lip_relWB ~ code,
data = propdata, lambda= seq(-26, 21, length=100), plotit = TRUE)
#get lambda
lambda_lip <- bc_lip$x
#get log-likelyhood
likelyhood_lip <- bc_lip$y
bcresults_lip <- cbind(lambda_lip, likelyhood_lip)
#sort these in decending order
ord_bc_lip <-bcresults_lip[order(-likelyhood_lip),]
#pull out maximum likelyhood and corresponding lambda
max_lik_lip<- ord_bc_lip[1,]
#lambda_toab2013 likelyhood_toab2013
new.lambda_lip <- ord_bc_lip[1,1]
```
Using the ```boxcox()``` function from the package ```MASS```, we determined that $\lambda$ = `r new.lambda_lip`.
<br />
\subsubsection{Box-cox transformation model}
```{r transformed_2013glmm}
#boxcox model
box_lm_lip <- lm((((propdata$lip_relWB ^ new.lambda_lip)-1)/new.lambda_lip) ~ code,
data = propdata)
print(summary(box_lm_lip))
#conduct anova
anova_box_lip <- anova(box_lm_lip)
anova_box_lip
#get full for MS
anova_box_lip$`F value`[1]
sprintf("%.10f", anova_box_lip$`Pr(>F)`[1])
```
\subsubsection{Retest Assumptions}
```{r transformed_assumptions, echo=FALSE}
box.res.lm_lip <- residuals(box_lm_lip)
par(mfrow=c(1,2))
plotNormalDensity(box.res.lm_lip)
qqPlot((((propdata$lip_relWB ^ new.lambda_lip)-1)/new.lambda_lip), "norm")
#Anderson Darling test for normality
print(ad.test(box.res.lm_lip))
#Homogeneity of variance
print(leveneTest((((propdata$lip_relWB ^ new.lambda_lip)-1)/new.lambda_lip) ~ code,
data = propdata))
```
\subsubsection{Post-hoc test}
```{r posthoc_lip}
box_lm_lip_posthoc <- glht(box_lm_lip, mcp(code="Tukey"))
print(summary(box_lm_lip_posthoc))
##Get letters for multiple comparisons
box_lip.cld <- cld(box_lm_lip_posthoc, decreasing=FALSE)
#list them
box_lip.cld
```
\subsection{Collar}
\subsubsection{Summary Statistics
```{r meansum_cols, echo=FALSE}
#library(Rmisc)
ss_col_relWB <- summarySE(propdata,
measurevar = "col_relWB",
groupvars = c("code"))
kable(ss_col_relWB)
```
```{r bp_col, echo=FALSE}
#outlier
samples_propdata <- propdata[,-1]
rownames(samples_propdata) <- propdata[,1]
outlier_test_col <- samples_propdata %>% tibble::rownames_to_column(var="outlier") %>% group_by(code) %>% mutate(is_outlier=ifelse(is_outlier(col_relWB), col_relWB, as.numeric(NA)))
outlier_test_col$outlier[which(is.na(outlier_test_col$is_outlier))] <- as.numeric(NA)
#Boxplot
ggplot(propdata, aes(x=code, y=col_relWB, fill=code)) +
geom_boxplot() +
scale_fill_manual(values = c("gray","darkgoldenrod1", "cyan3")) +
ggtitle("Collar") +
annotate("text", x=1, y=0.0205 ,label="H32.03", size=3) +
annotate("text", x=3, y=0.033 ,label="A1009", size=3) +
scale_y_continuous(name = "Volume Relative to Whole Brain", limits = c(0.01,.05)) +
scale_x_discrete(name = "Treatment Group", labels = c("Newly Emerged", "Lab Reared", "Nesting")) +
theme(text = element_text(color="black",size = 15),
axis.title = element_text(color="black"),
axis.text.x = element_text(color="black", size = 15, margin = margin(t = 5, r =0, b = 20, l = 0)),
axis.text.y = element_text(color="black", size = 15, margin = margin(t = 0, r =5, b = 0, l = 20)),
axis.ticks.length = unit (.5,"cm"),
legend.position = 'none',
legend.background = element_blank(),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 1, linetype = "solid",colour = "black"),
plot.title = element_text(hjust=0.5))
```
\subsubsection{Outlier}
Two samples, *H32.03* and *A1009*, were identified as outlier. After looking at notes on each sample, there is no reason to think these outliers are due to abnormalities, handling issues, dissection mistakes, or other issues. So, I am proceeding with the analysis without removing these samples.
\subsubsection{ANOVA}
```{r anova_col}
#model
lm_col <- lm(propdata$col_relWB ~ code, data = propdata)
print(summary(lm_col))
#conduct Anova
anova_lm_col <- Anova(lm_col)
print(anova_lm_col)
anova_lm_col$`F value`[1]
sprintf("%.10f", anova_lm_col$`Pr(>F)`[1])
```
\subsubsection{Post-hoc test}
```{r posthoc_col}
lm_col_posthoc <- glht(lm_col, mcp(code="Tukey"))
print(summary(lm_col_posthoc))
##Get letters for multiple comparisons
col.cld <- cld(lm_col_posthoc, decreasing=FALSE)
#list them
col.cld
#plot them
opar <- par(mai=c(1,1,1.5,1))
plot(col.cld)
```
\subsubsection{Verifying Assumptions}
Checking for:
<br />
1) The data are normally distributed
<br />
2) Homogeneity of Variance
```{r assumptions_col, echo=FALSE}
res.lmcol <- residuals(lm_col)
par(mfrow=c(1,2))
plotNormalDensity(res.lmcol)
qqPlot(propdata$col_relWB, "norm")
#Anderson Darling test for normality
print(ad.test(propdata$col_relWB))
#Homogeneity of variance
print(leveneTest(col_relWB~code, data = propdata))
```
Normality: Assumption met.
<br />
Variance: Assumption met.
\subsection{Calyces}
\subsubsection{Summary Statistics}
```{r meansum_calyces, echo=FALSE}
#library(Rmisc)
ss_calyces_relWB <- summarySE(propdata,
measurevar = "calyces_relWB",
groupvars = c("code"))
kable(ss_calyces_relWB)
```
```{r bp_calyces, echo=FALSE}
##Boxplot
ggplot(propdata, aes(x=code, y=calyces_relWB, fill=code)) +
geom_boxplot() +
scale_fill_manual(values = c("gray","darkgoldenrod1", "cyan3")) +
ggtitle("Calyces") +
scale_y_continuous(name = "Volume Relative to Whole Brain", limits = c(0.05,.12)) +
scale_x_discrete(name = "Treatment Group", labels = c("Newly Emerged", "Lab Reared", "Nesting")) +
theme(text = element_text(color="black",size = 15),
axis.title = element_text(color="black"),
axis.text.x = element_text(color="black", size = 15, margin = margin(t = 5, r =0, b = 20, l = 0)),
axis.text.y = element_text(color="black", size = 15, margin = margin(t = 0, r =5, b = 0, l = 20)),
axis.ticks.length = unit (.5,"cm"),
legend.position = 'none',
legend.background = element_blank(),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 1, linetype = "solid",colour = "black"),
plot.title = element_text(hjust=0.5),
plot.subtitle = element_text(hjust=0.5))
```
\subsubsection{ANOVA}
```{r anova_calyces}
#model
lm_calyces <- lm(propdata$calyces_relWB ~ code, data = propdata)
print(summary(lm_calyces))
#conduct Anova
anova_lm_calyces <- Anova(lm_calyces)
print(anova_lm_calyces)
anova_lm_calyces$`F value`[1]
sprintf("%.10f", anova_lm_calyces$`Pr(>F)`[1])
```
\subsubsection{Post-hoc test}
```{r posthoc_calyces}
lm_calyces_posthoc <- glht(lm_calyces, mcp(code="Tukey"))
print(summary(lm_calyces_posthoc))
##Get letters for multiple comparisons
calyces.cld <- cld(lm_calyces_posthoc, decreasing=FALSE)
#list them
calyces.cld
#plot them
# opar <- par(mai=c(1,1,1.5,1))
# plot(calyces.cld)
```
\subsubsection{Verifying Assumptions}
Checking for:
<br />
1) The data are normally distributed
<br />
2) Homogeneity of Variance
```{r assumptions_calyces, echo=FALSE}
res.lmcalyces <- residuals(lm_calyces)
par(mfrow=c(1,2))
plotNormalDensity(res.lmcalyces)
qqPlot(propdata$calyces_relWB, "norm")
#Anderson Darling test for normality
print(ad.test(propdata$calyces_relWB))
#Homogeneity of variance
print(leveneTest(calyces_relWB~code, data = propdata))
```
Normality: Assumption met.
<br />
Variance: Assumption met.
\subsection{Mushroom Body Lobes}
\subsubsection{Summary Statistics}
```{r meansum_mblobes, echo=FALSE}
#library(Rmisc)
ss_mblobes_relWB <- summarySE(propdata,
measurevar = "mblobes_relWB",
groupvars = c("code"))
kable(ss_mblobes_relWB)
```
```{r bp_mblobes, echo=FALSE}
##Boxplot
ggplot(propdata, aes(x=code, y=mblobes_relWB, fill=code)) +
geom_boxplot() +
scale_fill_manual(values = c("gray","darkgoldenrod1", "cyan3")) +
ggtitle("Mushroom Body Lobes") +
scale_y_continuous(name = "Volume Relative to Whole Brain", limits = c(0.04,.08)) +
scale_x_discrete(name = "Treatment Group", labels = c("Newly Emerged", "Lab Reared", "Nesting")) +
theme(text = element_text(color="black",size = 15),
axis.title = element_text(color="black"),
axis.text.x = element_text(color="black", size = 15, margin = margin(t = 5, r =0, b = 20, l = 0)),
axis.text.y = element_text(color="black", size = 15, margin = margin(t = 0, r =5, b = 0, l = 20)),
axis.ticks.length = unit (.5,"cm"),
legend.position = 'none',
legend.background = element_blank(),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 1, linetype = "solid",colour = "black"),
plot.title = element_text(hjust=0.5))
```
\subsubsection{ANOVA}
```{r anova_mblobes}
#model
lm_mblobes <- lm(propdata$mblobes_relWB ~ code, data = propdata)
print(summary(lm_mblobes))
#conduct Anova
anova_lm_mblobes <- Anova(lm_mblobes)
print(anova_lm_mblobes)
anova_lm_mblobes$`F value`[1]
sprintf("%.10f", anova_lm_mblobes$`Pr(>F)`[1])
```
\subsubsection{Post-hoc test}
```{r posthoc_mblobes}
lm_mblobes_posthoc <- glht(lm_mblobes, mcp(code="Tukey"))
print(summary(lm_mblobes_posthoc))
##Get letters for multiple comparisons
mb.cld <- cld(lm_mblobes_posthoc, decreasing=FALSE)
#list them
mb.cld
```
\subsubsection{Verifying Assumptions}
Checking for:
<br />
1) The data are normally distributed
<br />
2) Homogeneity of Variance
```{r assumptions_mblobes, echo=FALSE}
res.lmmblobes <- residuals(lm_mblobes)
par(mfrow=c(1,2))
plotNormalDensity(res.lmmblobes)
qqPlot(propdata$mblobes_relWB, "norm")
#Anderson Darling test for normality
print(ad.test(propdata$mblobes_relWB))
#Homogeneity of variance
print(leveneTest(mblobes_relWB~code, data = propdata))
```
Normality: Assumption met.
<br />
Variance: Assumption met.
\subsection{Antennal Lobes}
\subsubsection{Summary Statistics}
```{r meansum_als, echo=FALSE}
#library(Rmisc)
ss_als_relWB <- summarySE(propdata,
measurevar = "als_relWB",
groupvars = c("code"))
kable(ss_als_relWB)
```
```{r bp_als, echo=FALSE}
#outlier
samples_propdata <- propdata[,-1]
rownames(samples_propdata) <- propdata[,1]
outlier_test_als <- samples_propdata %>% tibble::rownames_to_column(var="outlier") %>% group_by(code) %>% mutate(is_outlier=ifelse(is_outlier(als_relWB), als_relWB, as.numeric(NA)))
outlier_test_als$outlier[which(is.na(outlier_test_als$is_outlier))] <- as.numeric(NA)
##Boxplot
ggplot(propdata, aes(x=code, y=als_relWB, fill=code)) +
geom_boxplot() +
scale_fill_manual(values = c("gray","darkgoldenrod1", "cyan3")) +
ggtitle("Antennal Lobes") +
annotate("text", x=2, y=0.0425 ,label="H2.37", size=3) +
annotate("text", x=2, y=0.0325 ,label="B2.16", size=3) +
scale_y_continuous(name = "Volume Relative to Whole Brain", limits = c(0.03,.06)) +
scale_x_discrete(name = "Treatment Group", labels = c("Newly Emerged", "Lab Reared", "Nesting")) +
theme(text = element_text(color="black",size = 15),
axis.title = element_text(color="black"),
axis.text.x = element_text(color="black", size = 15, margin = margin(t = 5, r =0, b = 20, l = 0)),
axis.text.y = element_text(color="black", size = 15, margin = margin(t = 0, r =5, b = 0, l = 20)),
axis.ticks.length = unit (.5,"cm"),
legend.position = 'none',
legend.background = element_blank(),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 1, linetype = "solid",colour = "black"),
plot.title = element_text(hjust=0.5))
```
\subsubsection{Outlier}
Two samples, *H2.37* and *B2.16*, were identified as outliers. After looking at notes there is no reason to think that these are outliers are due to abnormalities.
\subsubsection{ANOVA}
```{r anova_als}
#model
lm_als <- lm(propdata$als_relWB ~ code, data = propdata)
print(summary(lm_als))
#conduct Anova
anova_lm_als <- Anova(lm_als)
print(anova_lm_als)
anova_lm_als$`F value`[1]
sprintf("%.10f", anova_lm_als$`Pr(>F)`[1])
#No need for post-hocs
```
\subsubsection{Verifying Assumptions}
Checking for:
<br />
1) The data are normally distributed
<br />
2) Homogeneity of Variance
```{r assumptions_als, echo=FALSE}
res.lmals <- residuals(lm_als)
par(mfrow=c(1,2))
plotNormalDensity(res.lmals)
qqPlot(propdata$als_relWB, "norm")
#Anderson Darling test for normality
print(ad.test(propdata$als_relWB))
#Homogeneity of variance
print(leveneTest(als_relWB~code, data = propdata))
```
Normality: Assumption met.
<br />
Variance: Assumption met.
\subsection{Neuropil}
\subsubsection{Summary Statistics}
```{r meansum_neuropil, echo=FALSE}
#library(Rmisc)
ss_neuropil_relWB <- summarySE(propdata,
measurevar = "neuropil_relWB",
groupvars = c("code"))
kable(ss_neuropil_relWB)
```
```{r bp_neuropil, echo=FALSE}
##Boxplot
ggplot(propdata, aes(x=code, y=neuropil_relWB, fill=code)) +
geom_boxplot() +
scale_fill_manual(values = c("gray","darkgoldenrod1", "cyan3")) +
ggtitle("Neuropil") +
scale_y_continuous(name = "Volume Relative to Whole Brain", limits = c(0.1,0.2)) +
scale_x_discrete(name = "Treatment Group", labels = c("Newly Emerged", "Lab Reared", "Nesting")) +
theme(text = element_text(color="black",size = 15),
axis.title = element_text(color="black"),
axis.text.x = element_text(color="black", size = 15, margin = margin(t = 5, r =0, b = 20, l = 0)),
axis.text.y = element_text(color="black", size = 15, margin = margin(t = 0, r =5, b = 0, l = 20)),
axis.ticks.length = unit (.5,"cm"),
legend.position = 'none',
legend.background = element_blank(),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 1, linetype = "solid",colour = "black"),
plot.title = element_text(hjust=0.5),
plot.subtitle = element_text(hjust=0.5))
```
\subsubsection{ANOVA}
```{r anova_neuropil}
#model
lm_neuropil <- lm(propdata$neuropil_relWB ~ code, data = propdata)
print(summary(lm_neuropil))
#conduct Anova
anova_lm_neuropil <- Anova(lm_neuropil)
print(anova_lm_neuropil)
anova_lm_neuropil$`F value`[1]
sprintf("%.10f", anova_lm_neuropil$`Pr(>F)`[1])
```
\subsubsection{Verifying Assumptions}
Checking for:
<br />
1) The data are normally distributed
<br />
2) Homogeneity of Variance
```{r assumptions_neuropil, echo=FALSE}
res.lmneuropil <- residuals(lm_neuropil)
par(mfrow=c(1,2))
plotNormalDensity(res.lmneuropil)
qqPlot(propdata$neuropil_relWB, "norm")
#Anderson Darling test for normality
print(ad.test(propdata$neuropil_relWB))
#Homogeneity of variance
print(leveneTest(neuropil_relWB~code, data = propdata))
```
Normality: Assumption met.
<br />
Variance: Assumption met.
\subsubsection{Post-hoc test}
```{r posthoc_neuropil}
lm_neuropil_posthoc <- glht(lm_neuropil, mcp(code="Tukey"))
print(summary(lm_neuropil_posthoc))
##Get letters for multiple comparisons
neuropil.cld <- cld(lm_neuropil_posthoc, decreasing=FALSE)
#list them
neuropil.cld
```
\subsection{Kenyon Cells}
\subsubsection{Summary Statistics}
```{r meansum_kcs, echo=FALSE}
#library(Rmisc)
ss_kcs_relWB <- summarySE(propdata,
measurevar = "kcs_relWB",
groupvars = c("code"))
kable(ss_kcs_relWB)
```
```{r bp_kcs, echo=FALSE}
##Boxplot
ggplot(propdata, aes(x=code, y=kcs_relWB, fill=code)) +
geom_boxplot() +
scale_fill_manual(values = c("gray","darkgoldenrod1", "cyan3")) +
ggtitle("Kenyon Cells") +
scale_y_continuous(name = "Volume Relative to Whole Brain", limits = c(0.03,.07)) +
scale_x_discrete(name = "Treatment Group", labels = c("Newly Emerged", "Lab Reared", "Nesting")) +
theme(text = element_text(color="black",size = 15),
axis.title = element_text(color="black"),
axis.text.x = element_text(color="black", size = 15, margin = margin(t = 5, r =0, b = 20, l = 0)),
axis.text.y = element_text(color="black", size = 15, margin = margin(t = 0, r =5, b = 0, l = 20)),
axis.ticks.length = unit (.5,"cm"),
legend.position = 'none',
legend.background = element_blank(),
legend.title = element_blank(),
panel.background = element_rect(fill = "white"),
panel.border = element_blank(),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
axis.line = element_line(size = 1, linetype = "solid",colour = "black"),
plot.title = element_text(hjust=0.5),
plot.subtitle = element_text(hjust=0.5))
```
\subsubsection{ANOVA}
```{r anova_kcs}
#model
lm_kcs <- lm(propdata$kcs_relWB ~ code, data = propdata)
print(summary(lm_kcs))
#conduct Anova
anova_lm_kcs <- Anova(lm_kcs)
print(anova_lm_kcs)
anova_lm_kcs$`F value`[1]
sprintf("%.10f", anova_lm_kcs$`Pr(>F)`[1])
#NO POST-HOC NEEDED
```
\subsubsection{Verifying Assumptions}
Checking for:
<br />
1) The data are normally distributed
<br />
2) Homogeneity of Variance
```{r assumptions_kcs, echo=FALSE}
res.lmkcs <- residuals(lm_kcs)
par(mfrow=c(1,2))
plotNormalDensity(res.lmkcs)
qqPlot(propdata$kcs_relWB, "norm")