library("dplyr") library("lme4") library("car") library("emmeans") library("multcompView") #Get Session Info sessionInfo() #set working directory setwd("~/Desktop/Ant-Aphid Interaction/aai_data_sheets") # load dataset aai <- read.table("ant_aphid_data_analysis_stem_leaf_comparisons_samples_15_to_30_by_host_plant_year_fv.txt", sep = "\t", header = TRUE) # test if tending duration is different from zero when aphids feed on stems x <- aai %>% filter(aphid_placement_on_plant == "stem" & ant_treatment == "ants") %>% pull("tending_time_minutes") t.test(x, mu = 0) # test if tending duration is different from zero when aphids feed on leaf y <- aai %>% filter(aphid_placement_on_plant == "leaf" & ant_treatment == "ants") %>% pull("tending_time_minutes") t.test(y, mu = 0) # test the influence of host and aphid position on tending duration with year as a fixed effect aai2 <- aai %>% filter(ant_treatment == "ants") lm2 <- lmer(tending_time_minutes ~ host * aphid_placement_on_plant * (1 | year), data = aai2, REML = FALSE) Anova(lm2) lm2.pw <- emmeans(lm2, "aphid_placement_on_plant") pairs(lm2.pw) # test the influence of host plant, aphid position and TCA presence aphid biomass with year as a fixed effect lm3 <- lmer(aphid_position_biomass ~ host * aphid_placement_on_plant * ant_treatment * (1 | year), data = aai, REML = FALSE) Anova(lm3) lm3.pw <- emmeans(lm3, "aphid_placement_on_plant", by = c("host","ant_treatment")) pairs(lm3.pw) #sessinInfo() #R version 4.1.0 (2021-05-18) #Platform: x86_64-apple-darwin17.0 (64-bit) #Running under: macOS Big Sur 11.6.4 #Matrix products: default #LAPACK: /Library/Frameworks/R.framework/Versions/4.1/Resources/lib/libRlapack.dylib #locale: # [1] en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8 #attached base packages: # [1] stats graphics grDevices utils datasets methods base #other attached packages: # [1] multcompView_0.1-8 emmeans_1.7.1-1 car_3.0-12 carData_3.0-4 # [5] lme4_1.1-27.1 Matrix_1.4-0 dplyr_1.0.7 #loaded via a namespace (and not attached): # [1] Rcpp_1.0.7 pillar_1.6.4 compiler_4.1.0 nloptr_1.2.2.3 tools_4.1.0 # [6] boot_1.3-28 lifecycle_1.0.1 tibble_3.1.6 nlme_3.1-153 lattice_0.20-45 # [11] pkgconfig_2.0.3 rlang_0.4.12 DBI_1.1.2 parallel_4.1.0 mvtnorm_1.1-3 # [16] coda_0.19-4 generics_0.1.1 vctrs_0.3.8 grid_4.1.0 tidyselect_1.1.1 # [21] glue_1.6.0 R6_2.5.1 fansi_0.5.0 survival_3.2-13 multcomp_1.4-17 # [26] TH.data_1.1-0 minqa_1.2.4 tidyr_1.1.4 purrr_0.3.4 magrittr_2.0.1 # [31] backports_1.4.1 codetools_0.2-18 ellipsis_0.3.2 MASS_7.3-54 splines_4.1.0 # [36] pbkrtest_0.5.1 assertthat_0.2.1 abind_1.4-5 xtable_1.8-4 sandwich_3.0-1 # [41] utf8_1.2.2 estimability_1.3 broom_0.7.10 crayon_1.4.2 zoo_1.8-9