diff --git a/RAnalysis/Scripts/Growth.Rmd b/RAnalysis/Scripts/Growth.Rmd index 2b90d62..c563058 100644 --- a/RAnalysis/Scripts/Growth.Rmd +++ b/RAnalysis/Scripts/Growth.Rmd @@ -956,13 +956,24 @@ cld(lsm_Exp2.all.AgeXOA, Letters=letters) library(lsmeans) library(emmeans) library(multcomp) -lsm_Exp2.LMM.Age <- lsmeans(Exp2_LMM.lme4,list(pairwise~Age),adjust="tukey") +lsm_Exp2.LMM.Age <- lsmeans(Exp2_LMM.nlme,list(pairwise~Age),adjust="tukey") # does the Tukey Kramer cld(lsm_Exp2.LMM.Age, Letters=letters) - # Age lsmean SE df lower.CL upper.CL .group - # 2 86.4 2.77 38.5 80.8 92 a - # 4 95.4 2.77 38.5 89.8 101 a - # 8 140.1 2.57 36.1 134.8 145 b - # 10 152.2 2.57 36.1 147.0 157 c + # Age lsmean SE df lower.CL upper.CL .group + # 2 86.4 2.76 12 80.4 92.4 a + # 4 95.4 2.76 12 89.4 101.4 a + # 8 140.1 2.57 12 134.5 145.7 b + # 10 152.2 2.57 12 146.6 157.8 c + +emm_Exp2.LMM.Age <- emmeans(Exp2_LMM.nlme, + pairwise ~ "Age", + adjust = "tukey") # does the Tukey Kramer +cld(emm_Exp2.LMM.Age, Letters=letters) + # Age emmean SE df lower.CL upper.CL .group + # 2 86.4 2.76 12 80.4 92.4 a + # 4 95.4 2.76 12 89.4 101.4 a + # 8 140.1 2.57 12 134.5 145.7 b + # 10 152.2 2.57 12 146.6 157.8 c + lsm_Exp2.LMM.OA <- lsmeans(Exp2_LMM.lme4,list(pairwise~Larvae_pCO2),adjust="tukey") cld(lsm_Exp2.LMM.OA, Letters=letters) # Larvae_pCO2 lsmean SE df lower.CL upper.CL .group @@ -1230,18 +1241,19 @@ capture.output(cld(lsm_Exp2.LowMod.Age, Letters=letters),file="Output/1_Survival * all treatment low moderate and high * moderate v. low -```{r ANOVA end length; F1 Experiment #2 all and low v mod} -# (2) Size at metamorphosis +```{r ANOVA and T-test metamorphosis; F1 Experiment #2 all and low v mod} +# Size at metamorphosis +# NOTE: one way test using three groups in the 2.1 ANOVA IS CORRECT +# Note: one way test using two groups the t test is more approporate - 2.2 T TEST IS CORRECT -# (2.1) All treatment Low, moderate, and high -Exp2_Anova <- Exp2 %>% +Exp2_metamorphosis <- Exp2 %>% dplyr::filter(Age %in% 10) %>% dplyr::select(ID, Larvae_pCO2, Age,Length) %>% convert_as_factor(ID, Age, Larvae_pCO2) %>% na.omit() # prGR is normmalized to the inital measurement, these are NAs, omit them -Exp2endsize_summ <- summarySE(Exp2_Anova, measurevar="Length", groupvars=c("Age", "Larvae_pCO2")) +Exp2endsize_summ <- summarySE(Exp2_metamorphosis, measurevar="Length", groupvars=c("Age", "Larvae_pCO2")) # 10 Low pCO2 5 182.320 7.215404 3.226827 8.959107 # 10 Moderate pCO2 5 169.334 8.812167 3.940921 10.941750 @@ -1250,8 +1262,12 @@ Exp2endsize_summ <- summarySE(Exp2_Anova, measurevar="Length", groupvars=c("Age" ((182.320 - 169.334)/ 182.320) *100 # 7.122642 % larger under + + +# (2.1) All treatment Low, moderate, and high + # * run one way anova -Exp2_AOV_res.mod <- lm(Length~Larvae_pCO2,data=Exp2_Anova) +Exp2_AOV_res.mod <- lm(Length~Larvae_pCO2,data=Exp2_metamorphosis) # * check model assumptions shapiro.test(resid(Exp2_AOV_res.mod)) # 0.9314 @@ -1283,18 +1299,18 @@ capture.output(Exp2_AOV_res.means, # (2.2) Trancate data to just Low and Moderate -Exp2_Anova <- Exp2 %>% - dplyr::filter(Age %in% 10) %>% - dplyr::filter(!Larvae_pCO2 %in% 'High pCO2') %>% # omit high run for low vs. mod - dplyr::select(ID, Larvae_pCO2, Age,Length) %>% - convert_as_factor(ID, Age, Larvae_pCO2) %>% - na.omit() # prGR is normmalized to the inital measurement, these are NAs, omit them - -write.csv(Exp2_Anova, +Exp2_metamorphosis_LvM <- Exp2 %>% + dplyr::filter(Age %in% 10) %>% + dplyr::filter(!Larvae_pCO2 %in% 'High pCO2') %>% # omit high run for low vs. mod + dplyr::select(ID, Larvae_pCO2, Age,Length) %>% + convert_as_factor(ID, Age, Larvae_pCO2) %>% + na.omit() # prGR is normmalized to the inital measurement, these are NAs, omit them + +write.csv(Exp2_metamorphosis_LvM, file="Output/1_Survival_Growth/size_growth/Experiment2/Experiment2_MeanLength_metamorphosisLowvMod.csv") # * run one way anova -Exp2_AOV_res.mod <- lm(Length~Larvae_pCO2,data=Exp2_Anova) +Exp2_AOV_res.mod <- lm(Length~Larvae_pCO2,data=Exp2_metamorphosis_LvM) # * check model assumptions shapiro.test(resid(Exp2_AOV_res.mod)) # 0.8102 @@ -1323,16 +1339,35 @@ capture.output(Exp2_AOV_res.means, file="Output/1_Survival_Growth/size_growth/Experiment2/Experiment2_Length_metamorphosis_posthoc_LowvMod.doc") +# T test +# asusmptions , data is normal, model variance is equal + +# data are norm dist ? YES +shapiro.test(Exp2_metamorphosis_LvM$Length)[[2]] # 0.8834981 + +# equal variance ? YES +var.test(Exp2_metamorphosis_LvM$Length~ + as.numeric(as.factor(Exp2_metamorphosis_LvM$Larvae_pCO2)))[[3]] # 0.7078991 + +# run the model +Exp2_Ttest_mod <- t.test( as.numeric(as.factor(Exp2_metamorphosis_LvM$Larvae_pCO2)) , + Exp2_metamorphosis_LvM$Length, + var.equal = TRUE) # because of tests above +# output important data +library(purrr) +purrr::map_df(list(Exp2_Ttest_mod), tidy)[4:6] # Tstatistic, p vaue, DF +# -53.85676 2.401214e-21 18 + ``` ### Experiment 4 (F2s) -```{r ANOVA end length; F2 Experiment #4} -# (2) Size at metamorphosis - +```{r ANOVA and T-test metamorphosis; F2 Experiment #4} +# Size at metamorphosis +# NOTE: one way test using two groups, the t test is more approporate here # All treatment Low and moderate -Exp4_Anova <- Exp4 %>% +Exp4_metamorphosis <- Exp4 %>% dplyr::filter(Age %in% 10) %>% dplyr::select(ID, Larvae_pCO2, Age,Length) %>% convert_as_factor(ID, Age, Larvae_pCO2) %>% @@ -1342,9 +1377,8 @@ write.csv(Exp4_Anova, file="Output/1_Survival_Growth/size_growth/Experiment4/Experiment4_MeanLength_metamorphosisLowvMod.csv") - # * run one way anova -Exp4_AOV_res.mod <- lm(Length~Larvae_pCO2,data=Exp4_Anova) +Exp4_AOV_res.mod <- lm(Length~Larvae_pCO2,data=Exp4_metamorphosis) # * check model assumptions shapiro.test(resid(Exp4_AOV_res.mod)) # 0.2569 @@ -1360,6 +1394,28 @@ capture.output(summary(aov(Exp4_AOV_res.mod)), file="Output/1_Survival_Growth/size_growth/Experiment4_Length_metamorphosis_anova.doc") +# T test +# asusmptions , data is normal, model variance is equal + +# data are norm dist ? YES +shapiro.test(Exp4_metamorphosis$Length)[[2]] # 0.1992734 + +# equal variance ? YES +var.test(Exp4_metamorphosis$Length~ + as.numeric(as.factor(Exp4_metamorphosis$Larvae_pCO2)))[[3]] # 0.4875707 + +# run the model +Exp4_Ttest_mod <- t.test( as.numeric(as.factor(Exp4_metamorphosis$Larvae_pCO2)) , + Exp4_metamorphosis$Length, + var.equal = TRUE) # because of tests above +# output important data +library(purrr) +purrr::map_df(list(Exp4_Ttest_mod), tidy)[4:6] # Tstatistic, p vaue, DF +# -43.55171 9.785468e-13 10 + + +Rmisc::summarySE(Exp4_metamorphosis, measurevar="Length", groupvars="Larvae_pCO2") +((170.6000 - 162.0333) / 170.6000)*100 # 5.021512 ``` diff --git a/RAnalysis/Scripts/Survival_embryo_metamorphosis.Rmd b/RAnalysis/Scripts/Survival_embryo_metamorphosis.Rmd index 598a4be..4b81e99 100644 --- a/RAnalysis/Scripts/Survival_embryo_metamorphosis.Rmd +++ b/RAnalysis/Scripts/Survival_embryo_metamorphosis.Rmd @@ -1257,10 +1257,9 @@ Exp2Exp4_PrePost.master$Generation <- factor(Exp2Exp4_PrePost.master$Generation) TwoWay.Pre <- aov(lm(abs.delta.perc ~ Larvae_pCO2 * Generation, data = (Exp2Exp4_PrePost.master %>% dplyr::filter(type %in% 'pre')) )) -shapiro.test(resid(TwoWay.Pre)) # 0.05353 - pass -leveneTest(TwoWay.Pre) # 0.7313 - pass -summary(TwoWay.Pre) - +shapiro.test(resid(TwoWay.Pre)) # 0.2471 - pass +leveneTest(TwoWay.Pre) # 0.5528 - pass +summary(TwoWay.Pre) # NO EFFECT # Df Sum Sq Mean Sq F value Pr(>F) # Larvae_pCO2 1 0.001225 0.001225 0.644 0.438 # Generation 1 0.002470 0.002470 1.298 0.277 @@ -1269,25 +1268,46 @@ summary(TwoWay.Pre) + + + + + # delta post - test the effects of larvae pCO2 and generation TwoWay.Post <- aov(lm(abs.delta.perc ~ Larvae_pCO2 * Generation, data = (Exp2Exp4_PrePost.master %>% dplyr::filter(type %in% 'post')) )) -shapiro.test(resid(TwoWay.Post)) # 0.007293 - non-normal -leveneTest(TwoWay.Post) # 0.6631 - pass +shapiro.test(resid(TwoWay.Post)) # 0.05633 - pass +leveneTest(TwoWay.Post) # 0.2409 - pass +summary(TwoWay.Post) +# Df Sum Sq Mean Sq F value Pr(>F) +# Larvae_pCO2 1 0.009120 0.009120 13.583 0.00312 ** +# Generation 1 0.003840 0.003840 5.719 0.03405 * +# Larvae_pCO2:Generation 1 0.009300 0.009300 13.851 0.00292 ** +# Residuals 12 0.008058 0.000671 # * run non-parametric -SRH.Post <- scheirerRayHare(abs.delta.perc ~ Larvae_pCO2 * Generation, - data = (Exp2Exp4_PrePost.master %>% dplyr::filter(type %in% 'post'))) -# Df Sum Sq H p.value -# Larvae_pCO2 1 132.250 5.8346 0.015714 -# Generation 1 26.667 1.1765 0.278076 -# Larvae_pCO2:Generation 1 36.817 1.6243 0.202498 -# Residuals 12 144.267 + +# tukey-Kramer +TwoWay.Post.emmeans.pCO2 <- emmeans(TwoWay.Post, list(pairwise ~ Larvae_pCO2), adjust = "tukey") +TwoWay.Post.emmeans.pCO2.letters <- multcomp::cld(object = TwoWay.Post.emmeans.pCO2$emmeans, + Letters = letters) + # Larvae_pCO2 emmean SE df lower.CL upper.CL .group + # Low pCO2 0.0519 0.00946 12 0.0313 0.0725 a + # Moderate pCO2 0.1121 0.00946 12 0.0915 0.1327 b +TwoWay.Post.emmeans.pCO2.Gen <- emmeans(TwoWay.Post, list(pairwise ~ Larvae_pCO2:Generation), adjust = "tukey") +TwoWay.Post.emmeans.pCO2.Gen.letters <- multcomp::cld(object = TwoWay.Post.emmeans.pCO2.Gen$emmeans, + Letters = letters) + # Larvae_pCO2 Generation emmean SE df lower.CL upper.CL .group + # Low pCO2 2 0.0430 0.0150 12 0.0104 0.0756 a + # Low pCO2 1 0.0608 0.0116 12 0.0356 0.0860 a + # Moderate pCO2 1 0.0712 0.0116 12 0.0460 0.0964 a + # Moderate pCO2 2 0.1530 0.0150 12 0.1204 0.1856 b ``` ```{r Plots for Pre and Post} + Exp2Exp4_PrePost.summ <- Exp2Exp4_PrePost.master %>% dplyr::select(Generation,type,Larvae_pCO2,abs.delta.perc) %>% na.omit() %>%