Abstract

Parasites are ubiquitous in wildlife and can influence health and fitness. Thus, the inclusion of parasites in wildlife monitoring programs could provide important information for understanding declines in population body condition or recruitment rates. However, parasites are often neglected as a factor in wildlife management. We characterised the gastrointestinal parasite community of moose (Alces alces) in central Norway over an autumn hunting season and the following winter, using parasitological examination of faecal samples. We identified an age-related effect on parasite communities, including increased prevalence and abundance of Protostrongylidae species and increased community richness in yearlings compared to older moose. We also found that individuals with a lower body mass had higher burdens of Trichostrongylidae and Protostrongylidae species in autumn. There was some evidence for increased parasite burdens in males compared to females, while there was less evidence for seasonal differences between autumn and winter in a subsample of adult females. We found no strong associations between parasite burdens and moose population density. Our results add to the growing body of literature supporting the use of parasite burdens as proxies for an individual’s health status and potentially as predictors for fitness effects. In many Fennoscandian moose populations, the body condition and recruitment rates of individuals are declining, thus further monitoring of parasites may be needed to better understand the mechanisms behind these declines, including the potential role of parasites.

Here we provide the code used for the analysis of this manuscript. The necessary dataset is available as Supplementary Information from the journal website.

Functions

Custom functions required for the analysis.

run_glm <- function(df, resp_vars, covar_formula, fam, ct_round = FALSE, min.samples = 5){
  # set up empty data frame for summary results
  res <- data.frame(
    resp_var=NULL,
    covariates=NULL,
    estimate=NULL,
    std.error=NULL,
    statistic=NULL,
    p.value=NULL
  )
  
  # set up empty list to hold models
  mods <- list()
  
  if(fam == "binomial"){
    # run logistic GLM for each response variable
    for(x in resp_vars){
      # only run if there are enough positive samples
      if(sum(df[,x], na.rm = T) >= min.samples){
        print(paste0("Running logistic model for ",x)) # include to know which variables trigger warnings
        f <- paste0(x,covar_formula)
        mod <- glm(formula = formula(f),
                   data = df,
                   family = binomial(link = "logit"), 
                   na.action = na.omit) # remove NAs
        mod.sum <- summary(mod)
        colnames(mod.sum$coefficients) <- c("estimate","std.error","statistic","p.value")
        res <- rbind.data.frame(
          res,
          data.frame(
            resp_var=x,
            covariates=rownames(mod.sum$coefficients),
            as.data.frame(mod.sum$coefficients),
            row.names = NULL
          )
        )
        mods[[x]] <- mod
        
      } else {
        print(paste0("Skipping ",x,", not enough positive samples."))
        next
      }
    }
    
  } else if(fam == "gaussian"){
    # run normal GLM for each response variable
    for(x in resp_vars){
      # only run if there are enough positive samples
      if(sum(df[,x] > 0, na.rm = T) >= min.samples){
        print(paste0("Running gaussian model for ",x)) # include to know which variables trigger warnings
        # apply pseudo-count of 1 and log-transform
        df$y_trans <- log10(df[,x] + 1)
        
        f <- paste0("y_trans",covar_formula)
        mod <- glm(formula = formula(f),
                   data = df,
                   family = gaussian, 
                   na.action = na.omit) # remove NAs
        mod.sum <- summary(mod)
        colnames(mod.sum$coefficients) <- c("estimate","std.error","statistic","p.value")
        res <- rbind.data.frame(
          res,
          data.frame(
            resp_var=x,
            covariates=rownames(mod.sum$coefficients),
            as.data.frame(mod.sum$coefficients),
            row.names = NULL
          )
        )
        mods[[x]] <- mod
        
      } else {
        print(paste0("Skipping ",x,", not enough positive samples."))
        next
      }
    }
    
  } else if(fam == "poisson"){
    # run poisson GLM for each response variable
    for(x in resp_vars){
      # only run if there are enough positive samples
      if(sum(df[,x] > 0, na.rm = T) >= min.samples){
        print(paste0("Running Poisson model for ",x)) # include to know which variables trigger warnings
        if(ct_round){
          # round numeric data to integers (note may not always be valid!)
          df$y_rounded <- round(df[,x], digits = 0)
          f <- paste0("y_rounded",covar_formula)
        } else {
          f <- paste0(x,covar_formula)
        }
        
        mod <- glm(formula = formula(f),
                   data = df,
                   family = poisson(link = "log"), 
                   na.action = na.omit) # remove NAs
        
        # check for overdispersion
        dis <- performance::check_overdispersion(mod)
        if(dis$p_value < 0.05){
          # overdispersion detected, run quasi-poisson
          print(paste0("Overdispersion detected; running quasi-Poisson model for ",x))
          mod <- update(mod, family=quasipoisson)
        }
        mod.sum <- summary(mod)
        colnames(mod.sum$coefficients) <- c("estimate","std.error","statistic","p.value")
        res <- rbind.data.frame(
          res,
          data.frame(
            resp_var=x,
            covariates=rownames(mod.sum$coefficients),
            as.data.frame(mod.sum$coefficients),
            row.names = NULL
          )
        )
        mods[[x]] <- mod
        
      } else {
        print(paste0("Skipping ",x,", not enough positive samples."))
        next
      }
    }
    
  } else if(fam %in% c("nbinom1","nbinom2")) {
    # a generalised form of Poisson that deals with overdispersion
    # use glmmTMB library
    for(x in resp_vars){
      # only run if there are enough positive samples
      if(sum(df[,x] > 0, na.rm = T) >= min.samples){
        print(paste0("Running Neg Binomial model for ",x)) # include to know which variables trigger warnings
        if(ct_round){
          # round numeric data to integers (note may not always be valid!)
          df$y_rounded <- round(df[,x], digits = 0)
          f <- paste0("y_rounded",covar_formula)
        } else {
          f <- paste0(x,covar_formula)
        }
        
        if(fam == "nbinom1"){
          # for linear increase in variance with increasing mean
          mod <- glmmTMB(formula = formula(f),
                         data = df,
                         family = nbinom1,   
                         na.action = na.omit) # remove NAs
        } else if(fam == "nbinom2"){
          # for quadratic (rapid) increase in variance with increasing mean
          mod <- glmmTMB(formula = formula(f),
                         data = df,
                         family = nbinom2,
                         na.action = na.omit) # remove NAs
        } else {
          print("Family not implemented yet.")
          break
        }
        
        
        mod.sum <- summary(mod)
        colnames(mod.sum$coefficients$cond) <- c("estimate","std.error","statistic","p.value")
        res <- rbind.data.frame(
          res,
          data.frame(
            resp_var=x,
            covariates=rownames(mod.sum$coefficients$cond),
            as.data.frame(mod.sum$coefficients$cond),
            row.names = NULL
          )
        )
        mods[[x]] <- mod
        
      } else {
        print(paste0("Skipping ",x,", not enough positive samples."))
        next
      }
    }
  } else {
    print("Family not implemented yet.")
    break
  }
  
  # if enough tests, run BH correction
  if(length(unique(res$resp_var)) > 1){
    res$p.adj <- p.adjust(res$p.value,"BH")
  }
  return(list(
    summary=res,
    models=mods))
  
}

calc_median_IQR_label <- function(i, v, groups,
                                  sum.tab = ms.tab1, df.meta = TA16.sub, 
                                  intensity = FALSE){
  # default: calculate abundance (all samples, including 0s)
  # option: calculate intensity (only positive (>0) samples)
  if(intensity){
    df.meta <- df.meta[which(df.meta[,v] > 0),]
    if(nrow(df.meta) < 3){
      return(NA)
    }
  }
  
  if("all" %in% as.character(unlist(sum.tab[i,groups]))){
    # all samples
    m <- median(df.meta[,v], na.rm = T)
    q1 <- quantile(df.meta[,v], probs = 0.25, na.rm = T)[[1]]
    q3 <- quantile(df.meta[,v], probs = 0.75, na.rm = T)[[1]]
  } else {
    
    # loop through and subset by groups
    for(g in groups){
      gg <- as.character(sum.tab[i,g])
      df.meta <- df.meta[which(df.meta[,g] == gg),]
    }

    if(nrow(df.meta) < 3){
      # if less than 3 samples in the group, can't calculate median
      return(NA)
    } else {
      m <- median(df.meta[,v], na.rm = T)
      q1 <- quantile(df.meta[,v], probs = 0.25, na.rm = T)[[1]]
      q3 <- quantile(df.meta[,v], probs = 0.75, na.rm = T)[[1]]
    }
  }
  l <- paste0(round(m, digits = 0)," (",
              round(q1, digits = 0),"-",
              round(q3, digits = 0),")")
}

format_rich_summary <- function(mod){
  tab.sum <- summary(mod)
  colnames(tab.sum$coefficients) <- c("estimate","std.error","statistic","p.value")
  tab2.sum <- data.frame(
    resp_var="num.of.parasite.groups",
    covariates=row.names(tab.sum$coefficients),
    as.data.frame(tab.sum$coefficients),
    p.adj=NA,
    row.names = NULL
  )
  return(tab2.sum)
}

format_posthoc_summary <- function(mod, resp_var_name){
  # for "summary.glht" class
  tab.sum <- summary(mod)
  tab2.sum <- data.frame(
    resp_var=resp_var_name,
    covariates=names(tab.sum$test$coefficients),
    estimate=tab.sum$test$coefficients,
    std.error=tab.sum$test$sigma,
    statistic=tab.sum$test$tstat,
    p.value=tab.sum$test$pvalues,
    p.adj=NA,
    row.names = NULL
    )
   return(tab2.sum)
}

Load data

Data was generated through parasitological examination of faecal samples, using a modified McMasters method to estimate presence and abundance of endoparasitic eggs and oocysts and the Baermann technique quantify and identify parasitic L1 stage larvae in the faeces. The dataset used here is available from Supplementary Information (Table S5).

# set encoding to latin1, to handle additional Norwegian vowels
dat <- read.delim("figures/supp_dataset.txt", sep = "\t", fileEncoding = "latin1")

# set up levels for factors
dat$Season <- factor(dat$Season)
dat$Sex <- factor(dat$Sex,
                  levels = c("Male","Female"))
dat$Adult_age_category <- factor(dat$Adult_age_category, 
                                 levels = c("agegroup1","agegroup2","agegroup3"), 
                                 ordered = T)
dat$Carcass_mass_category <- factor(dat$Carcass_mass_category,
                                    levels = c("Normal","Low"), 
                                    ordered = T)
dat$Municipality <- factor(dat$Municipality,
                           ordered = F)

# add days spent in storage and post as potential confounders
dat$Days.harvested.vs.posted <- as.integer(as.Date(dat$Date_posted, format = "%d.%m.%Y") - as.Date(dat$Date_harvested, format = "%d.%m.%Y"))
dat$Days.harvested.vs.lab <- as.integer(as.Date(dat$Date_received_in_lab, format = "%d.%m.%Y") - as.Date(dat$Date_harvested, format = "%d.%m.%Y"))
dat$Days.posted.vs.lab <- as.integer(as.Date(dat$Date_received_in_lab, format = "%d.%m.%Y") - as.Date(dat$Date_posted, format = "%d.%m.%Y"))

# Parasite groups
mcmaster.parasite.groups.01 <- c("Eimeria01", "Strongylidetypeegg01", "NematodirusNematodirellaEgg01", 
                                 "Trichuris01", "Capillaria01", "MiddEgg01", 
                                 "Moniezia01", "Strongyloides01")
baermann.parasite.groups.01 <- c("ProtostrongylideLarver01", "EalcesLarvae01", 
                                 "ValcesLarvae01", "DictyocaulusLarver01")

mcmaster.parasite.groups.EPG <- c("EimeriaOPG", "StrongylidetypeeggEPG", "NematodirussppEPG", "NematodirusBattusEPG",
                                  "TrichurisEPG", "CapillariaEPG", "MiddEggEPG")
baermann.parasite.groups.LPG <- c("ProtostrongylideLarverLPG", "DictyocaulusLPG")

Autumn 2016 Trøndelag

First, focus on associations within the group of hunted adult moose (1+ years) from autumn 2016 (code TA16).

Summaries

Generate some basic summaries of metadata.

# subset to Trøndelag in 2016
TA16 <- dat[which(dat$Year == "2016" & dat$Season == "Autumn"),]

# exclude samples missing key data
TA16.sub <- TA16[which(!is.na(TA16$Sex) & !is.na(TA16$Adult_age_category) & !is.na(TA16$Carcass_mass_category) & !is.na(TA16$Municipality)),]

Fig. S1

ggplot(TA16.sub, aes(Carcass_mass_category, Carcass_mass_kg))+
  geom_boxplot(aes(fill = Sex), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Sex), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c(Male="#E41A1C",Female="#377EB8"), labels = c(Male="Male", Female="Female"))+
  labs(x = "Carcass mass category", y = "Carcass mass (kg)", fill = "Sex")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "right",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ Adult_age_category, nrow = 1,
             labeller = labeller(Adult_age_category=c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr")))

ggsave("figures/FigS1_Mass_by_SexMassCat.png",units = "in", dpi = 1200, width = 8, height = 4)
# ggsave("figures/Fig2.eps",units = "in", dpi = 1200, width = 8, height = 4)

Other figures

ggplot(TA16.sub, aes(Adult_age_category, Carcass_mass_kg))+
  geom_boxplot(aes(fill = Sex), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Sex), shape = 21, color = "black", size = 2, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#E41A1C","#377EB8"))+
  scale_x_discrete(labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  labs(x = "Age group", y = "Carcass mass (kg)", fill = "Sex")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(TA16.sub, aes(Carcass_mass_category, Carcass_mass_kg))+
  geom_boxplot(aes(fill = Carcass_mass_category), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 2, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  labs(x = "Weight category", y = "Carcass mass (kg)")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "none", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ Adult_age_category, nrow = 1,
             labeller = labeller(Adult_age_category=c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr")))

ggplot(TA16.sub, aes(Municipality, MunicipalityDensity_2016))+ 
  geom_boxplot(aes(fill = Municipality), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 2, 
             position = position_jitterdodge(jitter.width = 0.2))+
  labs(x = "Municipality", y = "Harvest density (2016)")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "none", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(TA16.sub, aes(Municipality, MunicipalityDensity_Mean2016_18))+
  geom_boxplot(aes(fill = Municipality), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 2, 
             position = position_jitterdodge(jitter.width = 0.2))+
  labs(x = "Municipality", y = "Harvest density (mean 2016-2018)")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "none", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(TA16.sub, aes(MunicipalityDensity_2016, Carcass_mass_kg))+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 2)+
  # scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  labs(x = "Harvest density (2016)", y = "Carcass mass (kg)")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(TA16.sub, aes(MunicipalityDensity_Mean2016_18, Carcass_mass_kg))+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 2)+
  # scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  labs(x = "Harvest density (2016-2018)", y = "Carcass mass (kg)")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

Table 1a

Basic stats

table(TA16.sub$McMaster_performed)
## 
##   1 
## 117
table(TA16.sub$Baermann_performed)
## 
##   0   1 
##  14 103
table(TA16.sub$Sex, TA16.sub$Adult_age_category)
##         
##          agegroup1 agegroup2 agegroup3
##   Male          46        12         1
##   Female        29        17        12
sum(table(TA16.sub$Sex, TA16.sub$Adult_age_category, TA16.sub$Carcass_mass_category))
## [1] 117
table(TA16.sub$Carcass_mass_category, TA16.sub$Adult_age_category)
##         
##          agegroup1 agegroup2 agegroup3
##   Normal        58        23        10
##   Low           17         6         3
prop.table(table(TA16.sub$Carcass_mass_category, TA16.sub$Adult_age_category), margin = 2)
##         
##          agegroup1 agegroup2 agegroup3
##   Normal 0.7733333 0.7931034 0.7692308
##   Low    0.2266667 0.2068966 0.2307692
summary(TA16.sub[which(TA16.sub$Adult_age_category == "agegroup1" & TA16.sub$Carcass_mass_category == "Normal"),"Carcass_mass_kg"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   107.0   120.0   127.5   130.0   137.8   196.0
summary(TA16.sub[which(TA16.sub$Adult_age_category == "agegroup1" & TA16.sub$Carcass_mass_category == "Low"),"Carcass_mass_kg"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   81.00   96.00  104.00   99.82  105.00  106.00
summary(TA16.sub[which(TA16.sub$Adult_age_category == "agegroup2" & TA16.sub$Carcass_mass_category == "Normal"),"Carcass_mass_kg"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   140.0   146.5   155.0   158.6   167.0   217.0
summary(TA16.sub[which(TA16.sub$Adult_age_category == "agegroup2" & TA16.sub$Carcass_mass_category == "Low"),"Carcass_mass_kg"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   113.0   118.2   120.5   124.3   132.5   138.0
summary(TA16.sub[which(TA16.sub$Adult_age_category == "agegroup3" & TA16.sub$Carcass_mass_category == "Normal"),"Carcass_mass_kg"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   160.0   181.5   199.5   197.1   208.0   240.0
summary(TA16.sub[which(TA16.sub$Adult_age_category == "agegroup3" & TA16.sub$Carcass_mass_category == "Low"),"Carcass_mass_kg"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   145.0   145.5   146.0   149.3   151.5   157.0
# summary table
ms.tab1 <- as.data.frame(table(TA16.sub$Sex, TA16.sub$Adult_age_category, TA16.sub$Carcass_mass_category))
names(ms.tab1) <- c("Sex","Adult_age_category","Carcass_mass_category","count")

ms.tab1 <- rbind.data.frame(
  ms.tab1,
  data.frame(Sex="all", Adult_age_category="all", Carcass_mass_category="all", count=nrow(TA16.sub))
)

ms.tab1$Carcass_mass_kg.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "Carcass_mass_kg", 
                                      groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                      sum.tab = ms.tab1, df.meta = TA16.sub)

# add major parasite groups
# same as abundance/prevalence models, must be at least 5 positive samples to include in table
# v1 - intensity
ms.tab1$StrongylidetypeeggEPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "StrongylidetypeeggEPG", 
                                               groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                               sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)
ms.tab1$NematodirussppEPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "NematodirussppEPG", 
                                           groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                           sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)
ms.tab1$NematodirusBattusEPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "NematodirusBattusEPG", 
                                              groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                              sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)
ms.tab1$TrichurisEPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "TrichurisEPG", 
                                      groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                      sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)
ms.tab1$CapillariaEPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "CapillariaEPG", 
                                       groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                       sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)
ms.tab1$EimeriaOPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "EimeriaOPG", 
                                    groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                    sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)
ms.tab1$ProtostrongylideLarverLPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "ProtostrongylideLarverLPG", 
                                                   groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                                   sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)
ms.tab1$DictyocaulusLPG.Median <- sapply(seq(1,nrow(ms.tab1)), calc_median_IQR_label, v = "DictyocaulusLPG", 
                                         groups = c("Sex","Adult_age_category","Carcass_mass_category"), 
                                         sum.tab = ms.tab1, df.meta = TA16.sub, intensity = TRUE)

ms.tab1$Season <- "Autumn"

Generate some basic prevalence and abundance plots.

TA16.abund.df <- melt(
  TA16.sub[,c("IndividualID","Sex","Adult_age_category","Carcass_mass_kg","Exact_age","Carcass_mass_category",
              "Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed",
              mcmaster.parasite.groups.EPG, baermann.parasite.groups.LPG)], 
  id.vars = c("IndividualID","Sex","Adult_age_category","Carcass_mass_kg","Exact_age","Carcass_mass_category","Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed"),
  measure.vars = c(mcmaster.parasite.groups.EPG, baermann.parasite.groups.LPG)
)
ggplot(subset(TA16.abund.df, !variable %in% c("MiddEggEPG","NematodirusBattusEPG")),
       aes(Adult_age_category, value))+
  geom_boxplot(aes(fill = Sex), alpha = 0.25, outlier.colour = NA)+
  geom_point(aes(fill = Sex), shape = 21, color = "black", size = 2,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#E41A1C","#377EB8"))+
  labs(x = "Age group", y = "Abundance", fill = "Sex")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, scales = "free_y", nrow = 2)
## Warning: Removed 34 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
## Warning: Removed 34 rows containing missing values or values outside the scale range
## (`geom_point()`).

# exclude parasites with < 5 detections
ggplot(subset(TA16.abund.df, !variable %in% c("MiddEggEPG","NematodirusBattusEPG") & !is.na(Carcass_mass_kg)), 
       aes(Carcass_mass_kg, value))+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 2)+
  scale_y_continuous(transform = "log10")+
  scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"))+ 
  labs(x = "Carcass mass (kg)", y = "Abundance", fill = "Age group")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, scales = "free_y", nrow = 2)
## Warning in scale_y_continuous(transform = "log10"): log-10 transformation
## introduced infinite values.
## Warning: Removed 34 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggplot(subset(TA16.abund.df, !variable %in% c("MiddEggEPG","NematodirusBattusEPG")), aes(Adult_age_category, value))+
  geom_boxplot(aes(fill = Carcass_mass_category), alpha = 0.25, outlier.colour = NA)+
  geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 2, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  scale_x_discrete(labels = c("1 yr","2-5 yr","6+ yr"))+
  labs(x = "Age category", y = "Abundance", fill = "Weight category")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, scales = "free_y", nrow = 2)
## Warning: Removed 34 rows containing non-finite outside the scale range
## (`stat_boxplot()`).
## Warning: Removed 34 rows containing missing values or values outside the scale range
## (`geom_point()`).

Table 2a

Autumn, summary table of prevalence by age and sex.

TA16.det.df <- melt(
  TA16.sub[,c("IndividualID","Sex","Adult_age_category","Carcass_mass_kg","Exact_age","Carcass_mass_category",
              "Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed",    
              mcmaster.parasite.groups.01, baermann.parasite.groups.01)], 
  id.vars = c("IndividualID","Sex","Adult_age_category","Carcass_mass_kg","Exact_age","Carcass_mass_category","Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed"),
  measure.vars = c(mcmaster.parasite.groups.01, baermann.parasite.groups.01)
)

TA16.det.by.group <- dcast(
  TA16.det.df,
  Sex + Adult_age_category ~ variable, 
  value.var = "value",
  fun.aggregate = sum, fill = 0, drop = T, na.rm = T
)

## Calculate no. of individuals based on samples for which test was performed
TA16.det.by.group$num_inds.MM <- sapply(seq(1,nrow(TA16.det.by.group)), function(i){
  sex <- TA16.det.by.group[i,"Sex"]
  age <- TA16.det.by.group[i,"Adult_age_category"]
  length(which(TA16.sub$Sex == sex & TA16.sub$Adult_age_category == age & TA16.sub$McMaster_performed == 1))
})

TA16.det.by.group$num_inds.BA <- sapply(seq(1,nrow(TA16.det.by.group)), function(i){
  sex <- TA16.det.by.group[i,"Sex"]
  age <- TA16.det.by.group[i,"Adult_age_category"]
  length(which(TA16.sub$Sex == sex & TA16.sub$Adult_age_category == age & TA16.sub$Baermann_performed == 1))
})

TA16.det.by.group.hm <- melt(TA16.det.by.group, 
                             id.vars = c("Sex","Adult_age_category","num_inds.MM","num_inds.BA"),
                             measure.vars = c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
                             variable.name = "parasite", value.name = "n.positive")

TA16.det.by.group.hm$group <- paste(TA16.det.by.group.hm$Adult_age_category, TA16.det.by.group.hm$Sex, sep = "_")

TA16.det.by.group.hm$proportion <- ifelse(
  TA16.det.by.group.hm$parasite %in% mcmaster.parasite.groups.01, 
  TA16.det.by.group.hm$n.positive / TA16.det.by.group.hm$num_inds.MM,
  TA16.det.by.group.hm$n.positive / TA16.det.by.group.hm$num_inds.BA
)

# add 95%CI to prevalence
TA16.det.by.group.hm$CI95.lower <- sapply(seq(1,nrow(TA16.det.by.group.hm)), function(i){
  p <- as.character(TA16.det.by.group.hm[i,"parasite"])
  n.det <- TA16.det.by.group.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.group.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.group.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[1])
})

TA16.det.by.group.hm$CI95.upper <- sapply(seq(1,nrow(TA16.det.by.group.hm)), function(i){
  p <- as.character(TA16.det.by.group.hm[i,"parasite"])
  n.det <- TA16.det.by.group.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.group.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.group.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[2])
})


TA16.det.by.group.hm$parasite <- factor(TA16.det.by.group.hm$parasite,
                                        levels = c("MiddEgg01", "Moniezia01", "Eimeria01",
                                                   "Strongyloides01", "Capillaria01", "Trichuris01", "NematodirusNematodirellaEgg01",
                                                   "Strongylidetypeegg01",
                                                   "ValcesLarvae01", "EalcesLarvae01", "ProtostrongylideLarver01",
                                                   "DictyocaulusLarver01"))

# exclude mites
TA16.det.by.group.hm <- TA16.det.by.group.hm[which(TA16.det.by.group.hm$parasite != "MiddEgg01"),]
TA16.det.by.group.hm$parasite <- droplevels(TA16.det.by.group.hm$parasite)

TA16.det.by.group[,c(1:2,15:16)]
##      Sex Adult_age_category num_inds.MM num_inds.BA
## 1   Male          agegroup1          46          40
## 2   Male          agegroup2          12          11
## 3   Male          agegroup3           1           1
## 4 Female          agegroup1          29          27
## 5 Female          agegroup2          17          14
## 6 Female          agegroup3          12          10
TA16.det.by.group.hm$percent <- round(TA16.det.by.group.hm$proportion * 100, 1)

TA16.det.by.group.hm$label_v2 <- sapply(seq(1,nrow(TA16.det.by.group.hm)), function(i){
  ct <- TA16.det.by.group.hm[i, "n.positive"]
  if(ct == 0){
    return(0)
  } else {
    per <- TA16.det.by.group.hm[i,"percent"]
    return(paste0(ct," (",per,"%)"))
  }
})

TA16.det.by.group.hm$label_v3 <- sapply(seq(1,nrow(TA16.det.by.group.hm)), function(i){
  if(TA16.det.by.group.hm[i,"proportion"] == 0){
    return(0)
  } else {
    prop <- round(TA16.det.by.group.hm[i,"proportion"], digits = 2)
    ciL <- round(TA16.det.by.group.hm[i,"CI95.lower"], digits = 1)
    ciU <- round(TA16.det.by.group.hm[i,"CI95.upper"], digits = 1)
    return(paste0(prop,"\n(",ciL,"-",ciU,")"))
  }
}) 

TA16.det.by.group.hm$group <- factor(as.character(TA16.det.by.group.hm$group),
                                     levels = c("agegroup1_Male", "agegroup2_Male", "agegroup3_Male",
                                                "agegroup1_Female", "agegroup2_Female", "agegroup3_Female"))
prev.fig1 <-
ggplot(TA16.det.by.group.hm, aes(group, parasite, fill = proportion))+
  geom_tile(colour = "grey50", linewidth = 0.5)+
  scale_fill_gradient(low="white", high="grey50")+
  # geom_vline(xintercept = 3.5, color = "black", linewidth = 0.5, linetype = 2)+
  geom_text(aes(label=label_v3))+
  scale_y_discrete(labels = c("*Moniezia* spp.<br>eggs","*Eimeria* spp.<br>oocysts",
                              "*Strongyloides* spp.<br>eggs","*Capillaria* spp.<br>eggs","*Trichuris* spp.<br>eggs","Nematodirinae<br>eggs",
                              "Trichostrongylidae<br>spp.", "*V. alces*<br>larvae","*E. alces*<br>larvae","Protostrongylidae<br>larvae",
                              "*Dictyocaulus* spp.<br>larvae"))+
  scale_x_discrete(labels = c("Autumn\nMale\n1 yr\nnL=40\nnE=46","Autumn\nMale\n2-5 yr\nnL=11\nnE=12","Autumn\nMale\n6+ yr\nnL=1\nnE=1",
                              "Autumn\nFemale\n1 yr\nnL=27\nnE=29","Autumn\nFemale\n2-5 yr\nnL=14\nnE=17","Autumn\nFemale\n6+ yr\nnL=10\nnE=12"),
                   position = "top")+
  labs(y = "", x = "", fill = "Prevalence    \n")+
       # tag = "Season\nSex\nAge group\nnL\nnE")+
  # annotate("text", x = -1, y = 12, label = "Season\nSex\nnL\nnE", size = 2, colour = "black")+
  theme_bw()+
  guides(fill = guide_colorbar(barwidth = 10, barheight = 1))+
  theme(axis.title = element_text(size = 13, colour = "black"),
        axis.text.y = ggtext::element_markdown(size = 12, colour = "black", hjust = 1),
        axis.text.x = element_text(size = 12, colour = "black", angle = 0, vjust = 0.5),
        legend.text = element_text(size = 11, colour = "black"), legend.title = element_text(size = 12, colour = "black"),
        legend.position = "bottom",
        panel.border = element_blank(), axis.ticks = element_blank()
        # plot.tag.position = c(0.0698, 0.938), plot.tag = element_text(size = 12, colour = "black", angle = 0, hjust = 0)
        )

prev.fig1

prop.table(table(TA16.sub$Strongylidetypeegg01))
## 
##          0          1 
## 0.01709402 0.98290598

Models

GLMs testing for associations between sex (factor) and age group (ordered factor), as well as carcass mass after accounting for sex and age. Includes adjustment for multiple hypothesis testing.

Prevalence

Must be present in at least 5 samples to test (otherwise not enough variation in dataset). Six models per parasite:

  • exact age + sex + weight + municipality
  • age group + sex + weight category + municipality
  • age group + sex * weight category + municipality
  • exact age * weight category + sex + municipality
  • age group + sex + weight category + harvest density (2016)
  • age group + sex + weight category + harvest density (mean over 2016-2018)
## MAIN: Exact Age and MunicipalityDensity_Mean2016_18 to reduce comparisons in model
TA16.prev.r2 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
  " ~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "binomial",
  min.samples = 5
)
## [1] "Skipping Eimeria01, not enough positive samples."
## [1] "Running logistic model for Strongylidetypeegg01"
## [1] "Running logistic model for NematodirusNematodirellaEgg01"
## [1] "Running logistic model for Trichuris01"
## [1] "Skipping Capillaria01, not enough positive samples."
## [1] "Skipping MiddEgg01, not enough positive samples."
## [1] "Skipping Moniezia01, not enough positive samples."
## [1] "Running logistic model for Strongyloides01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ProtostrongylideLarver01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for EalcesLarvae01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ValcesLarvae01"
## [1] "Skipping DictyocaulusLarver01, not enough positive samples."
## SUPP: 
# kg continuous
TA16.prev.r1 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
  " ~ Exact_age + Carcass_mass_kg + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "binomial",
  min.samples = 5
)
## [1] "Skipping Eimeria01, not enough positive samples."
## [1] "Running logistic model for Strongylidetypeegg01"
## [1] "Running logistic model for NematodirusNematodirellaEgg01"
## [1] "Running logistic model for Trichuris01"
## [1] "Skipping Capillaria01, not enough positive samples."
## [1] "Skipping MiddEgg01, not enough positive samples."
## [1] "Skipping Moniezia01, not enough positive samples."
## [1] "Running logistic model for Strongyloides01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ProtostrongylideLarver01"
## [1] "Running logistic model for EalcesLarvae01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ValcesLarvae01"
## [1] "Skipping DictyocaulusLarver01, not enough positive samples."
# # age group
# TA16.prev.r2 <- run_glm(
#   TA16.sub,
#   c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
#   " ~ Adult_age_category + Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18",
#   fam = "binomial",
#   min.samples = 5
# )

# 2016 density
TA16.prev.r3 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
  " ~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_2016 + Days.harvested.vs.lab",
  fam = "binomial",
  min.samples = 5
)
## [1] "Skipping Eimeria01, not enough positive samples."
## [1] "Running logistic model for Strongylidetypeegg01"
## [1] "Running logistic model for NematodirusNematodirellaEgg01"
## [1] "Running logistic model for Trichuris01"
## [1] "Skipping Capillaria01, not enough positive samples."
## [1] "Skipping MiddEgg01, not enough positive samples."
## [1] "Skipping Moniezia01, not enough positive samples."
## [1] "Running logistic model for Strongyloides01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ProtostrongylideLarver01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for EalcesLarvae01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ValcesLarvae01"
## [1] "Skipping DictyocaulusLarver01, not enough positive samples."
# Municipality
TA16.prev.r4 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
  " ~ Exact_age + Carcass_mass_category + Sex + Municipality + Days.harvested.vs.lab",
  fam = "binomial",
  min.samples = 5
)
## [1] "Skipping Eimeria01, not enough positive samples."
## [1] "Running logistic model for Strongylidetypeegg01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for NematodirusNematodirellaEgg01"
## [1] "Running logistic model for Trichuris01"
## [1] "Skipping Capillaria01, not enough positive samples."
## [1] "Skipping MiddEgg01, not enough positive samples."
## [1] "Skipping Moniezia01, not enough positive samples."
## [1] "Running logistic model for Strongyloides01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ProtostrongylideLarver01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for EalcesLarvae01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ValcesLarvae01"
## [1] "Skipping DictyocaulusLarver01, not enough positive samples."
# sex x weight interaction term
TA16.prev.r5 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
  " ~ Exact_age + Carcass_mass_category * Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "binomial",
  min.samples = 5
)
## [1] "Skipping Eimeria01, not enough positive samples."
## [1] "Running logistic model for Strongylidetypeegg01"
## [1] "Running logistic model for NematodirusNematodirellaEgg01"
## [1] "Running logistic model for Trichuris01"
## [1] "Skipping Capillaria01, not enough positive samples."
## [1] "Skipping MiddEgg01, not enough positive samples."
## [1] "Skipping Moniezia01, not enough positive samples."
## [1] "Running logistic model for Strongyloides01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ProtostrongylideLarver01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for EalcesLarvae01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ValcesLarvae01"
## [1] "Skipping DictyocaulusLarver01, not enough positive samples."
# age x kg cat interaction term
TA16.prev.r6 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
  " ~ Exact_age * Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "binomial",
  min.samples = 5
)
## [1] "Skipping Eimeria01, not enough positive samples."
## [1] "Running logistic model for Strongylidetypeegg01"
## [1] "Running logistic model for NematodirusNematodirellaEgg01"
## [1] "Running logistic model for Trichuris01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Skipping Capillaria01, not enough positive samples."
## [1] "Skipping MiddEgg01, not enough positive samples."
## [1] "Skipping Moniezia01, not enough positive samples."
## [1] "Running logistic model for Strongyloides01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ProtostrongylideLarver01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for EalcesLarvae01"
## Warning: glm.fit: fitted probabilities numerically 0 or 1 occurred
## [1] "Running logistic model for ValcesLarvae01"
## [1] "Skipping DictyocaulusLarver01, not enough positive samples."
TA16.prev.r1$summary[which(TA16.prev.r1$summary$covariates != "(Intercept)" & TA16.prev.r1$summary$p.value < 0.05),]
##                    resp_var covariates  estimate std.error statistic
## 26 ProtostrongylideLarver01  Exact_age -1.706975 0.5869081 -2.908420
## 32           EalcesLarvae01  Exact_age -2.597049 0.8702038 -2.984415
## 38           ValcesLarvae01  Exact_age -1.215502 0.5123512 -2.372399
##        p.value      p.adj
## 26 0.003632602 0.05085642
## 32 0.002841214 0.05085642
## 38 0.017672979 0.14845303
TA16.prev.r2$summary[which(TA16.prev.r2$summary$covariates != "(Intercept)" & TA16.prev.r2$summary$p.value < 0.05),]
##                    resp_var              covariates   estimate std.error
## 26 ProtostrongylideLarver01               Exact_age -2.2002240 0.5571874
## 32           EalcesLarvae01               Exact_age -3.3206061 0.8611806
## 33           EalcesLarvae01 Carcass_mass_category.L  1.7491054 0.8007562
## 38           ValcesLarvae01               Exact_age -1.3140766 0.4485914
## 39           ValcesLarvae01 Carcass_mass_category.L  0.9670895 0.4926710
##    statistic      p.value      p.adj
## 26 -3.948805 7.854244e-05 0.00242163
## 32 -3.855876 1.153157e-04 0.00242163
## 33  2.184317 2.893896e-02 0.15192952
## 38 -2.929340 3.396827e-03 0.02419897
## 39  1.962952 4.965178e-02 0.20853749
TA16.prev.r3$summary[which(TA16.prev.r3$summary$covariates != "(Intercept)" & TA16.prev.r3$summary$p.value < 0.05),]
##                    resp_var              covariates  estimate std.error
## 26 ProtostrongylideLarver01               Exact_age -2.190376 0.5526011
## 32           EalcesLarvae01               Exact_age -3.330831 0.8629707
## 33           EalcesLarvae01 Carcass_mass_category.L  1.736644 0.8013825
## 38           ValcesLarvae01               Exact_age -1.314138 0.4454480
##    statistic      p.value       p.adj
## 26 -3.963756 7.377956e-05 0.002383799
## 32 -3.859726 1.135142e-04 0.002383799
## 33  2.167059 3.023032e-02 0.158709174
## 38 -2.950150 3.176196e-03 0.026680043
TA16.prev.r4$summary[which(TA16.prev.r4$summary$covariates != "(Intercept)" & TA16.prev.r4$summary$p.value < 0.05),]
##                    resp_var              covariates  estimate std.error
## 24              Trichuris01       MunicipalitySelbu -1.893457 0.8779352
## 38 ProtostrongylideLarver01               Exact_age -2.470020 0.6432193
## 47           EalcesLarvae01               Exact_age -4.257373 1.2480872
## 48           EalcesLarvae01 Carcass_mass_category.L  1.956695 0.8870405
## 56           ValcesLarvae01               Exact_age -1.505810 0.5135315
## 57           ValcesLarvae01 Carcass_mass_category.L  1.001546 0.4983439
## 62           ValcesLarvae01       MunicipalityTydal  3.896743 1.7677963
##    statistic      p.value       p.adj
## 24 -2.156716 0.0310278123 0.279250311
## 38 -3.840090 0.0001229893 0.007748328
## 47 -3.411118 0.0006469712 0.020379593
## 48  2.205869 0.0273931477 0.279250311
## 56 -2.932264 0.0033650101 0.070665211
## 57  2.009748 0.0444578278 0.329977638
## 62  2.204294 0.0275036550 0.279250311
TA16.prev.r5$summary[which(TA16.prev.r5$summary$covariates != "(Intercept)" & TA16.prev.r5$summary$p.value < 0.05),]
##                    resp_var covariates  estimate std.error statistic
## 30 ProtostrongylideLarver01  Exact_age -2.232596 0.5807771 -3.844153
## 37           EalcesLarvae01  Exact_age -3.658237 1.0696693 -3.419970
## 44           ValcesLarvae01  Exact_age -1.314280 0.4489651 -2.927354
##         p.value       p.adj
## 30 0.0001209695 0.005927505
## 37 0.0006262795 0.015343849
## 44 0.0034185954 0.055837058
TA16.prev.r6$summary[which(TA16.prev.r6$summary$covariates != "(Intercept)" & TA16.prev.r6$summary$p.value < 0.05),]
##                    resp_var covariates  estimate std.error statistic
## 30 ProtostrongylideLarver01  Exact_age -2.352179 0.7287718 -3.227593
## 37           EalcesLarvae01  Exact_age -3.170190 0.8669529 -3.656704
## 44           ValcesLarvae01  Exact_age -1.444032 0.5841358 -2.472083
##         p.value      p.adj
## 30 0.0012483643 0.02038995
## 37 0.0002554792 0.01251848
## 44 0.0134328208 0.10970137
# posthoc pairwise comparisons for variables significant for Municipality
TA16.prev.r4.posthoc.Trichuris <- glht(TA16.prev.r4$models$Trichuris01, linfct = mcp(Municipality = "Tukey"))

TA16.prev.r4.posthoc.Valces <- glht(TA16.prev.r4$models$ValcesLarvae01, linfct = mcp(Municipality = "Tukey"))
plot(allEffects(TA16.prev.r1$models$ProtostrongylideLarver01))

plot(allEffects(TA16.prev.r1$models$EalcesLarvae01))

plot(allEffects(TA16.prev.r1$models$ValcesLarvae01))

plot(allEffects(TA16.prev.r2$models$Trichuris01))

plot(allEffects(TA16.prev.r2$models$ProtostrongylideLarver01))

plot(allEffects(TA16.prev.r2$models$EalcesLarvae01))

plot(allEffects(TA16.prev.r2$models$ValcesLarvae01))

plot(allEffects(TA16.prev.r3$models$EalcesLarvae01))

plot(allEffects(TA16.prev.r4$models$EalcesLarvae01))

plot(allEffects(TA16.prev.r6$models$ProtostrongylideLarver01))

plot(allEffects(TA16.prev.r6$models$EalcesLarvae01))

plot(allEffects(TA16.prev.r6$models$ValcesLarvae01))

Model selection for key parasite groups

TA16.prev.aic <- rbind.data.frame(
  data.frame(resp_var="ProtostrongylideLarver01",
             AIC(TA16.prev.r1$models$ProtostrongylideLarver01, 
                 TA16.prev.r2$models$ProtostrongylideLarver01, 
                 TA16.prev.r3$models$ProtostrongylideLarver01, 
                 TA16.prev.r4$models$ProtostrongylideLarver01, 
                 TA16.prev.r5$models$ProtostrongylideLarver01,
                 TA16.prev.r6$models$ProtostrongylideLarver01)),
  data.frame(resp_var="EalcesLarvae01",
             AIC(TA16.prev.r1$models$EalcesLarvae01, 
                 TA16.prev.r2$models$EalcesLarvae01, 
                 TA16.prev.r3$models$EalcesLarvae01, 
                 TA16.prev.r4$models$EalcesLarvae01, 
                 TA16.prev.r5$models$EalcesLarvae01,
                 TA16.prev.r6$models$EalcesLarvae01)),
  data.frame(resp_var="ValcesLarvae01",
             AIC(TA16.prev.r1$models$ValcesLarvae01, 
                 TA16.prev.r2$models$ValcesLarvae01, 
                 TA16.prev.r3$models$ValcesLarvae01, 
                 TA16.prev.r4$models$ValcesLarvae01, 
                 TA16.prev.r5$models$ValcesLarvae01,
                 TA16.prev.r6$models$ValcesLarvae01))
)
TA16.prev.aic[order(TA16.prev.aic$resp_var, TA16.prev.aic$AIC),]
##                                                              resp_var df
## TA16.prev.r2$models$EalcesLarvae01                     EalcesLarvae01  6
## TA16.prev.r3$models$EalcesLarvae01                     EalcesLarvae01  6
## TA16.prev.r5$models$EalcesLarvae01                     EalcesLarvae01  7
## TA16.prev.r6$models$EalcesLarvae01                     EalcesLarvae01  7
## TA16.prev.r4$models$EalcesLarvae01                     EalcesLarvae01  9
## TA16.prev.r1$models$EalcesLarvae01                     EalcesLarvae01  6
## TA16.prev.r2$models$ProtostrongylideLarver01 ProtostrongylideLarver01  6
## TA16.prev.r3$models$ProtostrongylideLarver01 ProtostrongylideLarver01  6
## TA16.prev.r5$models$ProtostrongylideLarver01 ProtostrongylideLarver01  7
## TA16.prev.r1$models$ProtostrongylideLarver01 ProtostrongylideLarver01  6
## TA16.prev.r6$models$ProtostrongylideLarver01 ProtostrongylideLarver01  7
## TA16.prev.r4$models$ProtostrongylideLarver01 ProtostrongylideLarver01  9
## TA16.prev.r2$models$ValcesLarvae01                     ValcesLarvae01  6
## TA16.prev.r3$models$ValcesLarvae01                     ValcesLarvae01  6
## TA16.prev.r4$models$ValcesLarvae01                     ValcesLarvae01  9
## TA16.prev.r6$models$ValcesLarvae01                     ValcesLarvae01  7
## TA16.prev.r5$models$ValcesLarvae01                     ValcesLarvae01  7
## TA16.prev.r1$models$ValcesLarvae01                     ValcesLarvae01  6
##                                                    AIC
## TA16.prev.r2$models$EalcesLarvae01            86.28170
## TA16.prev.r3$models$EalcesLarvae01            86.28615
## TA16.prev.r5$models$EalcesLarvae01            86.40806
## TA16.prev.r6$models$EalcesLarvae01            88.02912
## TA16.prev.r4$models$EalcesLarvae01            88.69450
## TA16.prev.r1$models$EalcesLarvae01            91.32413
## TA16.prev.r2$models$ProtostrongylideLarver01  88.34388
## TA16.prev.r3$models$ProtostrongylideLarver01  88.69656
## TA16.prev.r5$models$ProtostrongylideLarver01  88.94797
## TA16.prev.r1$models$ProtostrongylideLarver01  89.65814
## TA16.prev.r6$models$ProtostrongylideLarver01  90.19641
## TA16.prev.r4$models$ProtostrongylideLarver01  92.52291
## TA16.prev.r2$models$ValcesLarvae01           113.71232
## TA16.prev.r3$models$ValcesLarvae01           114.10209
## TA16.prev.r4$models$ValcesLarvae01           115.23682
## TA16.prev.r6$models$ValcesLarvae01           115.54372
## TA16.prev.r5$models$ValcesLarvae01           115.71126
## TA16.prev.r1$models$ValcesLarvae01           117.81090
# EalcesLarvae01: r2/r3
# ProtostrongylideLarver01: r2c, then r3
# ValcesLarvae01: r2, then r3

Add no. of positive samples to models

TA16.prev.r1$summary$n.pos <- sapply(TA16.prev.r1$summary$resp_var, function(x){
  sum(TA16.sub[,x], na.rm = T)
})
TA16.prev.r2$summary$n.pos <- sapply(TA16.prev.r2$summary$resp_var, function(x){
  sum(TA16.sub[,x], na.rm = T)
})
TA16.prev.r3$summary$n.pos <- sapply(TA16.prev.r3$summary$resp_var, function(x){
  sum(TA16.sub[,x], na.rm = T)
})
TA16.prev.r4$summary$n.pos <- sapply(TA16.prev.r4$summary$resp_var, function(x){
  sum(TA16.sub[,x], na.rm = T)
})
TA16.prev.r5$summary$n.pos <- sapply(TA16.prev.r5$summary$resp_var, function(x){
  sum(TA16.sub[,x], na.rm = T)
})
TA16.prev.r6$summary$n.pos <- sapply(TA16.prev.r6$summary$resp_var, function(x){
  sum(TA16.sub[,x], na.rm = T)
})
TA16.prev.r2.resplotA <-
ggplot(
  data.frame(
    fitted=TA16.prev.r2$models$ProtostrongylideLarver01$fitted.values,
    residual=TA16.prev.r2$models$ProtostrongylideLarver01$residuals
  ), 
  aes(fitted, residual))+
  geom_hline(yintercept = 0, colour = "grey50", linewidth = 0.5, linetype = 2)+
  geom_point()+
  geom_smooth(method = "loess")+ 
  labs(x = "Fitted values", y = "Residuals", title = "Protostrongylidae detection")+
  theme_classic()+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))

TA16.prev.r2.resplotB <-
ggplot(
  data.frame(
    fitted=TA16.prev.r2$models$EalcesLarvae01$fitted.values,
    residual=TA16.prev.r2$models$EalcesLarvae01$residuals
  ), 
  aes(fitted, residual))+
  geom_hline(yintercept = 0, colour = "grey50", linewidth = 0.5, linetype = 2)+
  geom_point()+
  geom_smooth(method = "loess")+ 
  labs(x = "Fitted values", y = "Residuals", title = "E. alces detection")+
  theme_classic()+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))

TA16.prev.r2.resplotC <-
ggplot(
  data.frame(
    fitted=TA16.prev.r2$models$ValcesLarvae01$fitted.values,
    residual=TA16.prev.r2$models$ValcesLarvae01$residuals
  ), 
  aes(fitted, residual))+
  geom_hline(yintercept = 0, colour = "grey50", linewidth = 0.5, linetype = 2)+
  geom_point()+
  geom_smooth(method = "loess")+ 
  labs(x = "Fitted values", y = "Residuals", title = "V. alces detection")+
  theme_classic()+
  theme(plot.title = element_text(face = "bold", hjust = 0.5))
plot_grid(TA16.prev.r2.resplotA, TA16.prev.r2.resplotB, TA16.prev.r2.resplotC,
          nrow = 1)
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'
## `geom_smooth()` using formula = 'y ~ x'

ggplot(subset(TA16.det.df, variable %in% c("ProtostrongylideLarver01","EalcesLarvae01","ValcesLarvae01")),
       aes(Adult_age_category, value))+
  geom_violin(aes(fill = Adult_age_category), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2, jitter.height = 0.05))+
  scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"))+
  scale_x_discrete(labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  labs(x = "Age group", y = "Detection", fill = "", title = "Trøndelag autumn 2016")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "none",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, nrow = 1)

# E & V alces only really relevant for agegroup=1
ggplot(subset(TA16.det.df, variable %in% c("EalcesLarvae01","ValcesLarvae01")),
       aes(Sex, value))+
  geom_violin(aes(fill = Carcass_mass_category), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2, jitter.height = 0.05))+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  # scale_x_discrete(labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  labs(x = "Sex", y = "Detection", fill = "Weight category", title = "Trøndelag høst 2016")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable + Adult_age_category, nrow = 1)

ggplot(subset(TA16.det.df, variable %in% c("ValcesLarvae01") & Adult_age_category == "agegroup1"),
       aes(Municipality, value))+
  geom_violin(aes(fill = Municipality), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2, jitter.height = 0.05))+
  geom_signif(comparisons = list(c("Malvik","Tydal")), annotations = c("."),
              tip_length = 0.05, y_position = 1.1)+
  scale_y_continuous(expand = expansion(mult = c(0, 0.15)))+
  labs(x = "Municipality", y = "Detection", fill = "", title = "Trøndelag høst 2016")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "none",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 90))+
  facet_wrap(~ variable + Adult_age_category, nrow = 3)

Fig. 2

Point plot with 95% CI:

TA16.det.by.age <- dcast(
  TA16.det.df,
  Adult_age_category ~ variable, 
  value.var = "value",
  fun.aggregate = sum, fill = 0, drop = T, na.rm = T
)

## Calculate no. of individuals based on samples for which test was performed
TA16.det.by.age$num_inds.MM <- sapply(seq(1,nrow(TA16.det.by.age)), function(i){
  age <- TA16.det.by.age[i,"Adult_age_category"]
  length(which(TA16.sub$Adult_age_category == age & TA16.sub$McMaster_performed == 1))
})

TA16.det.by.age$num_inds.BA <- sapply(seq(1,nrow(TA16.det.by.age)), function(i){
  age <- TA16.det.by.age[i,"Adult_age_category"]
  length(which(TA16.sub$Adult_age_category == age & TA16.sub$Baermann_performed == 1))
})

TA16.det.by.age.hm <- melt(TA16.det.by.age, 
                             id.vars = c("Adult_age_category","num_inds.MM","num_inds.BA"),
                             measure.vars = c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
                             variable.name = "parasite", value.name = "n.positive")

TA16.det.by.age.hm$proportion <- ifelse(
  TA16.det.by.age.hm$parasite %in% mcmaster.parasite.groups.01, 
  TA16.det.by.age.hm$n.positive / TA16.det.by.age.hm$num_inds.MM,
  TA16.det.by.age.hm$n.positive / TA16.det.by.age.hm$num_inds.BA
)

# add 95%CI to prevalence
TA16.det.by.age.hm$CI95.lower <- sapply(seq(1,nrow(TA16.det.by.age.hm)), function(i){
  p <- as.character(TA16.det.by.age.hm[i,"parasite"])
  n.det <- TA16.det.by.age.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.age.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.age.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[1])
})

TA16.det.by.age.hm$CI95.upper <- sapply(seq(1,nrow(TA16.det.by.age.hm)), function(i){
  p <- as.character(TA16.det.by.age.hm[i,"parasite"])
  n.det <- TA16.det.by.age.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.age.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.age.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[2])
})

TA16.det.by.age.hm$CI95.lower.v2 <- ifelse(TA16.det.by.age.hm$proportion == 0,NA,TA16.det.by.age.hm$CI95.lower)
TA16.det.by.age.hm$CI95.upper.v2 <- ifelse(TA16.det.by.age.hm$proportion == 0,NA,TA16.det.by.age.hm$CI95.upper)

TA16.det.by.age.hm$variable <- factor(TA16.det.by.age.hm$parasite,
                                        levels = levels(TA16.det.df$variable))
TA16.plot.detA <-
ggplot(
  subset(TA16.det.by.age.hm, variable %in% c("ProtostrongylideLarver01","EalcesLarvae01","ValcesLarvae01")))+
  geom_errorbar(aes(x = Adult_age_category, ymin = CI95.lower.v2, ymax = CI95.upper.v2),
                width = 0.5, linewidth = 0.75, colour = "black")+
  geom_point(aes(Adult_age_category, proportion, fill = Adult_age_category, size = num_inds.BA), shape = 21)+
  scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"), labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"), guide = "none")+
  scale_x_discrete(labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  labs(x = "Age group", y = "Prevalence", size = "Total no.\nof samples")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = ggtext::element_markdown(size = 13),
        legend.position = "right",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable, nrow = 1, 
             labeller = labeller(variable = c(ProtostrongylideLarver01="Protostrongylidae", EalcesLarvae01="*E. alces*", ValcesLarvae01="*V. alces*")))
TA16.det.by.KgCat <- dcast(
  TA16.det.df,
  Adult_age_category + Carcass_mass_category ~ variable, 
  value.var = "value",
  fun.aggregate = sum, fill = 0, drop = T, na.rm = T
)

## Calculate no. of individuals based on samples for which test was performed
TA16.det.by.KgCat$num_inds.MM <- sapply(seq(1,nrow(TA16.det.by.KgCat)), function(i){
  age <- TA16.det.by.KgCat[i,"Adult_age_category"]
  kgC <- TA16.det.by.KgCat[i,"Carcass_mass_category"]
  length(which(TA16.sub$Adult_age_category == age & TA16.sub$Carcass_mass_category == kgC & TA16.sub$McMaster_performed == 1))
})

TA16.det.by.KgCat$num_inds.BA <- sapply(seq(1,nrow(TA16.det.by.KgCat)), function(i){
  age <- TA16.det.by.KgCat[i,"Adult_age_category"]
  kgC <- TA16.det.by.KgCat[i,"Carcass_mass_category"]
  length(which(TA16.sub$Adult_age_category == age & TA16.sub$Carcass_mass_category == kgC & TA16.sub$Baermann_performed == 1))
})

TA16.det.by.KgCat.hm <- melt(TA16.det.by.KgCat, 
                             id.vars = c("Adult_age_category","Carcass_mass_category","num_inds.MM","num_inds.BA"),
                             measure.vars = c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
                             variable.name = "parasite", value.name = "n.positive")

TA16.det.by.KgCat.hm$proportion <- ifelse(
  TA16.det.by.KgCat.hm$parasite %in% mcmaster.parasite.groups.01, 
  TA16.det.by.KgCat.hm$n.positive / TA16.det.by.KgCat.hm$num_inds.MM,
  TA16.det.by.KgCat.hm$n.positive / TA16.det.by.KgCat.hm$num_inds.BA
)

# add 95%CI to prevalence
TA16.det.by.KgCat.hm$CI95.lower <- sapply(seq(1,nrow(TA16.det.by.KgCat.hm)), function(i){
  p <- as.character(TA16.det.by.KgCat.hm[i,"parasite"])
  n.det <- TA16.det.by.KgCat.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.KgCat.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.KgCat.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[1])
})

TA16.det.by.KgCat.hm$CI95.upper <- sapply(seq(1,nrow(TA16.det.by.KgCat.hm)), function(i){
  p <- as.character(TA16.det.by.KgCat.hm[i,"parasite"])
  n.det <- TA16.det.by.KgCat.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.KgCat.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.KgCat.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[2])
})

TA16.det.by.KgCat.hm$CI95.lower.v2 <- ifelse(TA16.det.by.KgCat.hm$proportion == 0,NA,TA16.det.by.KgCat.hm$CI95.lower)
TA16.det.by.KgCat.hm$CI95.upper.v2 <- ifelse(TA16.det.by.KgCat.hm$proportion == 0,NA,TA16.det.by.KgCat.hm$CI95.upper)

TA16.det.by.KgCat.hm$variable <- factor(TA16.det.by.KgCat.hm$parasite,
                                        levels = levels(TA16.det.df$variable))

# TA16.det.by.KgCat.hm$group <- factor(paste(TA16.det.by.KgCat.hm$Carcass_mass_category, TA16.det.by.KgCat.hm$Sex, sep = "_"),
#                                      levels = c("Normal_Male","Low_Male","Normal_Female","Low_Female"))
TA16.plot.detB <-
ggplot(
  subset(TA16.det.by.KgCat.hm, variable %in% c("ProtostrongylideLarver01","EalcesLarvae01","ValcesLarvae01") & Adult_age_category == "agegroup1"))+
  geom_errorbar(aes(x = Carcass_mass_category, ymin = CI95.lower.v2, ymax = CI95.upper.v2),
                width = 0.5, linewidth = 0.75, colour = "black")+
  geom_point(aes(Carcass_mass_category, proportion, fill = Carcass_mass_category, size = num_inds.BA), shape = 21)+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"), guide = "none")+
  scale_size(limits = c(10,60), range = c(1,5))+
  labs(x = "Carcass mass category", y = "Prevalence", size = "Total no.\nof samples", fill = "Carcass mass\ncategory")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = ggtext::element_markdown(size = 13),
        legend.position = "right", legend.box = "horizontal",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable + Adult_age_category, nrow = 1, 
             labeller = labeller(variable = c(ProtostrongylideLarver01="Protostrongylidae", EalcesLarvae01="*E. alces*", ValcesLarvae01="*V. alces*"),
                                 Adult_age_category = c(agegroup1 = "1 yr")))
plot_grid(TA16.plot.detA, TA16.plot.detB,
          align = "hv", axis = "tblr", nrow = 2,
          labels = c("a","b"))

ggsave("figures/Fig2_PrevalenceDSL_by_AgeMassCat.png",units = "in", dpi = 1200, width = 9, height = 6.5)

Comparison of carcass mass (ns) vs carcass mass category (sig) for EalcesLarvae01 & ValcesLarvae01

ggplot(
  data.frame(
    variable=c("EalcesLarvae01","EalcesLarvae01",
               "ValcesLarvae01","ValcesLarvae01"),
    group=c("Normal","Low","Normal","Low"),
    proportion=c(38/(38+15),13/(13+1),
                 33/(33+20),11/(11+3)),
    CI95.lower=c(binom.test(38, (38+15), conf.level = 0.95)$conf.int[1],
                 binom.test(13, (13+1), conf.level = 0.95)$conf.int[1],
                 binom.test(33, (33+20), conf.level = 0.95)$conf.int[1],
                 binom.test(11, (11+3), conf.level = 0.95)$conf.int[1]),
    CI95.upper=c(binom.test(38, (38+15), conf.level = 0.95)$conf.int[2],
                 binom.test(13, (13+1), conf.level = 0.95)$conf.int[2],
                 binom.test(33, (33+20), conf.level = 0.95)$conf.int[2],
                 binom.test(11, (11+3), conf.level = 0.95)$conf.int[2])
  ))+
  geom_errorbar(aes(x = group, ymin = CI95.lower, ymax = CI95.upper),
                width = 0.5, linewidth = 0.75, colour = "black")+
  geom_point(aes(group, proportion, fill = group), shape = 21, size = 4)+
  scale_fill_manual(values = c("#CBC9DA", "#3C2692"))+
  labs(x = "Carcass mass category", y = "Prevalence", size = "Total no.\nof samples", fill = "Carcass mass\ncategory", title = "Yearlings")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = ggtext::element_markdown(size = 13),
        legend.position = "none", legend.box = "horizontal",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable, nrow = 1, 
             labeller = labeller(variable = c(EalcesLarvae01="*E. alces*", ValcesLarvae01="*V. alces*")))

ggplot(subset(TA16.det.df, variable %in% c("EalcesLarvae01","ValcesLarvae01") & Adult_age_category == "agegroup1" & !is.na(value)),
       aes(as.factor(value), Carcass_mass_kg))+
  geom_hline(yintercept = 106, linewidth = 1, colour = "grey50", linetype = 2)+
  geom_boxplot(aes(fill = as.factor(value)), alpha = 0.25, outlier.colour = NA)+
  geom_point(aes(fill = as.factor(value)), shape = 21, color = "black", size = 3)+
  scale_x_discrete(labels = c("No","Yes"))+
  scale_fill_manual(values = c("grey25","grey75"))+
  labs(x = "Parasite detected", y = "Carcass mass (kg)", title = "Yearlings")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable, nrow = 1, 
             labeller = labeller(variable = c(EalcesLarvae01="E. alces", ValcesLarvae01="V. alces")))

# ggplot(subset(TA16.det.df, variable %in% c("EalcesLarvae01","ValcesLarvae01") & Adult_age_category == "agegroup1"),
#        aes(Carcass_mass_kg, value))+
#   geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 3)+
#   scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
#   labs(x = "Carcass mass (kg)", y = "Detected (binary)", title = "Yearlings")+
#   theme_classic()+
#   theme(plot.title = element_text(size = 13, hjust = 0.5),
#         axis.text = element_text(color = "black", size = 12), 
#         axis.title = element_text(size = 13),
#         axis.text.x = element_text(angle = 0),
#         strip.text.x = element_text(size = 13),
#         legend.position = "none",
#         legend.text = element_text(color = "black", size = 12),
#         legend.title = element_text(size = 13))+
#   facet_wrap(~ variable, nrow = 2, 
#              labeller = labeller(variable = c(EalcesLarvae01="E. alces", ValcesLarvae01="V. alces")))

Abundance

Must be present in at least 5 samples to test (otherwise not enough variation in dataset). Rounding abundances to nearest integer and running negative binomial GLMs with nbinom1. Six models per parasite:

  • exact age + sex + weight + municipality
  • age group + sex + weight category + municipality
  • age group + sex * weight category + municipality
  • exact age * weight category + sex + municipality
  • age group + sex + weight category + harvest density (2016)
  • age group + sex + weight category + harvest density (mean over 2016-2018)
TA16.abund.r2 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
  " ~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "nbinom1",
  ct_round = T,
  min.samples = 5
)
## [1] "Skipping EimeriaOPG, not enough positive samples."
## [1] "Running Neg Binomial model for StrongylidetypeeggEPG"
## [1] "Running Neg Binomial model for NematodirussppEPG"
## [1] "Skipping NematodirusBattusEPG, not enough positive samples."
## [1] "Running Neg Binomial model for TrichurisEPG"
## [1] "Skipping CapillariaEPG, not enough positive samples."
## [1] "Skipping MiddEggEPG, not enough positive samples."
## [1] "Running Neg Binomial model for ProtostrongylideLarverLPG"
## [1] "Skipping DictyocaulusLPG, not enough positive samples."
# kg continuous
TA16.abund.r1 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
  " ~ Exact_age + Carcass_mass_kg + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "nbinom1",
  ct_round = T,
  min.samples = 5
)
## [1] "Skipping EimeriaOPG, not enough positive samples."
## [1] "Running Neg Binomial model for StrongylidetypeeggEPG"
## [1] "Running Neg Binomial model for NematodirussppEPG"
## [1] "Skipping NematodirusBattusEPG, not enough positive samples."
## [1] "Running Neg Binomial model for TrichurisEPG"
## [1] "Skipping CapillariaEPG, not enough positive samples."
## [1] "Skipping MiddEggEPG, not enough positive samples."
## [1] "Running Neg Binomial model for ProtostrongylideLarverLPG"
## [1] "Skipping DictyocaulusLPG, not enough positive samples."
# age group
# TA16.abund.r2 <- run_glm(
#   TA16.sub,
#   c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
#   " ~ Adult_age_category + Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18",
#   fam = "nbinom1",
#   ct_round = T,
#   min.samples = 5
# )

# 2016 density
TA16.abund.r3 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
  " ~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_2016 + Days.harvested.vs.lab",
  fam = "nbinom1",
  ct_round = T,
  min.samples = 5
)
## [1] "Skipping EimeriaOPG, not enough positive samples."
## [1] "Running Neg Binomial model for StrongylidetypeeggEPG"
## [1] "Running Neg Binomial model for NematodirussppEPG"
## [1] "Skipping NematodirusBattusEPG, not enough positive samples."
## [1] "Running Neg Binomial model for TrichurisEPG"
## [1] "Skipping CapillariaEPG, not enough positive samples."
## [1] "Skipping MiddEggEPG, not enough positive samples."
## [1] "Running Neg Binomial model for ProtostrongylideLarverLPG"
## [1] "Skipping DictyocaulusLPG, not enough positive samples."
# Municipality
TA16.abund.r4 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
  " ~ Exact_age + Carcass_mass_category + Sex + Municipality + Days.harvested.vs.lab",
  fam = "nbinom1",
  ct_round = T,
  min.samples = 5
)
## [1] "Skipping EimeriaOPG, not enough positive samples."
## [1] "Running Neg Binomial model for StrongylidetypeeggEPG"
## [1] "Running Neg Binomial model for NematodirussppEPG"
## [1] "Skipping NematodirusBattusEPG, not enough positive samples."
## [1] "Running Neg Binomial model for TrichurisEPG"
## [1] "Skipping CapillariaEPG, not enough positive samples."
## [1] "Skipping MiddEggEPG, not enough positive samples."
## [1] "Running Neg Binomial model for ProtostrongylideLarverLPG"
## [1] "Skipping DictyocaulusLPG, not enough positive samples."
# sex x weight interaction term
TA16.abund.r5 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
  " ~ Exact_age + Carcass_mass_category * Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "nbinom1",
  ct_round = T,
  min.samples = 5
)
## [1] "Skipping EimeriaOPG, not enough positive samples."
## [1] "Running Neg Binomial model for StrongylidetypeeggEPG"
## [1] "Running Neg Binomial model for NematodirussppEPG"
## [1] "Skipping NematodirusBattusEPG, not enough positive samples."
## [1] "Running Neg Binomial model for TrichurisEPG"
## [1] "Skipping CapillariaEPG, not enough positive samples."
## [1] "Skipping MiddEggEPG, not enough positive samples."
## [1] "Running Neg Binomial model for ProtostrongylideLarverLPG"
## [1] "Skipping DictyocaulusLPG, not enough positive samples."
# age x kg cat interaction term
TA16.abund.r6 <- run_glm(
  TA16.sub,
  c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
  " ~ Exact_age * Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "nbinom1",
  ct_round = T,
  min.samples = 5
)
## [1] "Skipping EimeriaOPG, not enough positive samples."
## [1] "Running Neg Binomial model for StrongylidetypeeggEPG"
## [1] "Running Neg Binomial model for NematodirussppEPG"
## [1] "Skipping NematodirusBattusEPG, not enough positive samples."
## [1] "Running Neg Binomial model for TrichurisEPG"
## [1] "Skipping CapillariaEPG, not enough positive samples."
## [1] "Skipping MiddEggEPG, not enough positive samples."
## [1] "Running Neg Binomial model for ProtostrongylideLarverLPG"
## [1] "Skipping DictyocaulusLPG, not enough positive samples."
TA16.abund.r1$summary[which(TA16.abund.r1$summary$covariates != "(Intercept)" & TA16.abund.r1$summary$p.value < 0.05),]
##                     resp_var            covariates    estimate   std.error
## 20 ProtostrongylideLarverLPG             Exact_age -1.24104385 0.397741012
## 21 ProtostrongylideLarverLPG       Carcass_mass_kg -0.01804358 0.006941988
## 24 ProtostrongylideLarverLPG Days.harvested.vs.lab  0.08905558 0.025821339
##    statistic      p.value       p.adj
## 20 -3.120231 0.0018070925 0.010842555
## 21 -2.599194 0.0093442840 0.044852563
## 24  3.448914 0.0005628456 0.004502765
TA16.abund.r2$summary[which(TA16.abund.r2$summary$covariates != "(Intercept)" & TA16.abund.r2$summary$p.value < 0.05),]
##                     resp_var              covariates    estimate  std.error
## 3      StrongylidetypeeggEPG Carcass_mass_category.L  0.24953999 0.12403997
## 4      StrongylidetypeeggEPG               SexFemale -0.33399104 0.16034083
## 20 ProtostrongylideLarverLPG               Exact_age -1.65800204 0.38520675
## 21 ProtostrongylideLarverLPG Carcass_mass_category.L  0.74932746 0.17768185
## 22 ProtostrongylideLarverLPG               SexFemale -0.54856357 0.24023279
## 24 ProtostrongylideLarverLPG   Days.harvested.vs.lab  0.09611575 0.02484926
##    statistic      p.value        p.adj
## 3   2.011771 4.424411e-02 0.1327323186
## 4  -2.083007 3.725061e-02 0.1277163640
## 20 -4.304187 1.675997e-05 0.0001340798
## 21  4.217243 2.473079e-05 0.0001483847
## 22 -2.283467 2.240290e-02 0.0896115807
## 24  3.867952 1.097532e-04 0.0005268155
TA16.abund.r3$summary[which(TA16.abund.r3$summary$covariates != "(Intercept)" & TA16.abund.r3$summary$p.value < 0.05),]
##                     resp_var              covariates    estimate  std.error
## 4      StrongylidetypeeggEPG               SexFemale -0.32534254 0.16032298
## 20 ProtostrongylideLarverLPG               Exact_age -1.68398890 0.38703777
## 21 ProtostrongylideLarverLPG Carcass_mass_category.L  0.73711894 0.17553713
## 22 ProtostrongylideLarverLPG               SexFemale -0.55551365 0.23927322
## 24 ProtostrongylideLarverLPG   Days.harvested.vs.lab  0.09512646 0.02471322
##    statistic      p.value        p.adj
## 4  -2.029294 4.242830e-02 0.1454684717
## 20 -4.350968 1.355379e-05 0.0001084303
## 21  4.199220 2.678365e-05 0.0001607019
## 22 -2.321671 2.025067e-02 0.0810026748
## 24  3.849213 1.184978e-04 0.0005687894
TA16.abund.r4$summary[which(TA16.abund.r4$summary$covariates != "(Intercept)" & TA16.abund.r4$summary$p.value < 0.05),]
##                     resp_var              covariates    estimate  std.error
## 3      StrongylidetypeeggEPG Carcass_mass_category.L  0.23694734 0.12070813
## 4      StrongylidetypeeggEPG               SexFemale -0.35246577 0.16050113
## 6      StrongylidetypeeggEPG       MunicipalitySelbu  0.90794612 0.33869841
## 24              TrichurisEPG       MunicipalitySelbu -1.63560186 0.68257673
## 29 ProtostrongylideLarverLPG               Exact_age -1.91127716 0.39672676
## 30 ProtostrongylideLarverLPG Carcass_mass_category.L  0.79327464 0.17718616
## 31 ProtostrongylideLarverLPG               SexFemale -0.57447542 0.24157287
## 34 ProtostrongylideLarverLPG    MunicipalityStjørdal  1.55677808 0.69726554
## 36 ProtostrongylideLarverLPG   Days.harvested.vs.lab  0.09055432 0.02434742
##    statistic      p.value        p.adj
## 3   1.962977 4.964879e-02 1.378070e-01
## 4  -2.196033 2.808958e-02 9.192955e-02
## 6   2.680692 7.347011e-03 3.778463e-02
## 24 -2.396217 1.656529e-02 6.961547e-02
## 29 -4.817616 1.452837e-06 1.743404e-05
## 30  4.477069 7.567481e-06 6.810733e-05
## 31 -2.378063 1.740387e-02 6.961547e-02
## 34  2.232690 2.556937e-02 9.192955e-02
## 36  3.719257 1.998095e-04 1.438628e-03
TA16.abund.r5$summary[which(TA16.abund.r5$summary$covariates != "(Intercept)" & TA16.abund.r5$summary$p.value < 0.05),]
##                     resp_var              covariates   estimate std.error
## 23 ProtostrongylideLarverLPG               Exact_age -1.6591378 0.3860986
## 24 ProtostrongylideLarverLPG Carcass_mass_category.L  0.7871043 0.2260995
## 25 ProtostrongylideLarverLPG               SexFemale -0.5617693 0.2438951
## 27 ProtostrongylideLarverLPG   Days.harvested.vs.lab  0.0957379 0.0249543
##    statistic      p.value        p.adj
## 23 -4.297186 1.729797e-05 0.0001614478
## 24  3.481229 4.991183e-04 0.0027950625
## 25 -2.303323 2.126067e-02 0.0992164731
## 27  3.836530 1.247852e-04 0.0008734961
TA16.abund.r6$summary[which(TA16.abund.r6$summary$covariates != "(Intercept)" & TA16.abund.r6$summary$p.value < 0.05),]
##                     resp_var            covariates    estimate  std.error
## 4      StrongylidetypeeggEPG             SexFemale -0.33472266 0.16033347
## 23 ProtostrongylideLarverLPG             Exact_age -1.75138568 0.47068866
## 25 ProtostrongylideLarverLPG             SexFemale -0.55238972 0.23982323
## 27 ProtostrongylideLarverLPG Days.harvested.vs.lab  0.09633104 0.02483006
##    statistic      p.value        p.adj
## 4  -2.087666 0.0368280105 0.1718640488
## 23 -3.720901 0.0001985136 0.0013895953
## 25 -2.303320 0.0212608256 0.1190606233
## 27  3.879614 0.0001046222 0.0009764742
TA16.abund.r4.posthoc.Strongylide <- glht(TA16.abund.r4$models$StrongylidetypeeggEPG, linfct = mcp(Municipality = "Tukey"))
summary(TA16.abund.r4.posthoc.Strongylide)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: glmmTMB(formula = y_rounded ~ Exact_age + Carcass_mass_category + 
##     Sex + Municipality + Days.harvested.vs.lab, data = df, family = nbinom1, 
##     na.action = na.omit, ziformula = ~0, dispformula = ~1)
## 
## Linear Hypotheses:
##                         Estimate Std. Error z value Pr(>|z|)  
## Meråker - Malvik == 0    0.72487    0.44306   1.636   0.4523  
## Selbu - Malvik == 0      0.90795    0.33870   2.681   0.0523 .
## Stjørdal - Malvik == 0   0.66273    0.44284   1.497   0.5427  
## Tydal - Malvik == 0      0.78425    0.40632   1.930   0.2831  
## Selbu - Meråker == 0     0.18308    0.30578   0.599   0.9726  
## Stjørdal - Meråker == 0 -0.06214    0.41428  -0.150   0.9999  
## Tydal - Meråker == 0     0.05939    0.37042   0.160   0.9998  
## Stjørdal - Selbu == 0   -0.24522    0.30307  -0.809   0.9209  
## Tydal - Selbu == 0      -0.12369    0.24571  -0.503   0.9856  
## Tydal - Stjørdal == 0    0.12152    0.36943   0.329   0.9972  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
TA16.abund.r4.posthoc.Strongylide.summary <- format_posthoc_summary(TA16.abund.r4.posthoc.Strongylide, "StrongylidetypeeggEPG")

TA16.abund.r4.posthoc.Trichuris <- glht(TA16.abund.r4$models$TrichurisEPG, linfct = mcp(Municipality = "Tukey"))
summary(TA16.abund.r4.posthoc.Trichuris)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: glmmTMB(formula = y_rounded ~ Exact_age + Carcass_mass_category + 
##     Sex + Municipality + Days.harvested.vs.lab, data = df, family = nbinom1, 
##     na.action = na.omit, ziformula = ~0, dispformula = ~1)
## 
## Linear Hypotheses:
##                         Estimate Std. Error z value Pr(>|z|)
## Meråker - Malvik == 0   -1.65521    1.17814  -1.405    0.607
## Selbu - Malvik == 0     -1.63560    0.68258  -2.396    0.109
## Stjørdal - Malvik == 0  -1.10809    0.94273  -1.175    0.752
## Tydal - Malvik == 0     -1.20587    0.91630  -1.316    0.665
## Selbu - Meråker == 0     0.01961    1.05800   0.019    1.000
## Stjørdal - Meråker == 0  0.54713    1.25521   0.436    0.992
## Tydal - Meråker == 0     0.44934    1.19764   0.375    0.995
## Stjørdal - Selbu == 0    0.52752    0.78916   0.668    0.960
## Tydal - Selbu == 0       0.42973    0.69985   0.614    0.971
## Tydal - Stjørdal == 0   -0.09778    0.93821  -0.104    1.000
## (Adjusted p values reported -- single-step method)
TA16.abund.r4.posthoc.Protostrongylide <- glht(TA16.abund.r4$models$ProtostrongylideLarverLPG, linfct = mcp(Municipality = "Tukey"))
summary(TA16.abund.r4.posthoc.Protostrongylide)
## 
##   Simultaneous Tests for General Linear Hypotheses
## 
## Multiple Comparisons of Means: Tukey Contrasts
## 
## 
## Fit: glmmTMB(formula = y_rounded ~ Exact_age + Carcass_mass_category + 
##     Sex + Municipality + Days.harvested.vs.lab, data = df, family = nbinom1, 
##     na.action = na.omit, ziformula = ~0, dispformula = ~1)
## 
## Linear Hypotheses:
##                         Estimate Std. Error z value Pr(>|z|)  
## Meråker - Malvik == 0    0.57039    0.77240   0.738   0.9416  
## Selbu - Malvik == 0      0.50555    0.61889   0.817   0.9175  
## Stjørdal - Malvik == 0   1.55678    0.69727   2.233   0.1537  
## Tydal - Malvik == 0      0.40860    0.72957   0.560   0.9783  
## Selbu - Meråker == 0    -0.06485    0.49745  -0.130   0.9999  
## Stjørdal - Meråker == 0  0.98639    0.59456   1.659   0.4349  
## Tydal - Meråker == 0    -0.16179    0.61379  -0.264   0.9988  
## Stjørdal - Selbu == 0    1.05123    0.35864   2.931   0.0253 *
## Tydal - Selbu == 0      -0.09694    0.42900  -0.226   0.9993  
## Tydal - Stjørdal == 0   -1.14818    0.53642  -2.140   0.1869  
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## (Adjusted p values reported -- single-step method)
TA16.abund.r4.posthoc.Protostrongylide.summary <- format_posthoc_summary(TA16.abund.r4.posthoc.Protostrongylide, "ProtostrongylideLarverLPG")
TA16.abund.aic <- rbind.data.frame(
  data.frame(resp_var="ProtostrongylideLarverLPG",
             AIC(TA16.abund.r1$models$ProtostrongylideLarverLPG, 
                 TA16.abund.r2$models$ProtostrongylideLarverLPG, 
                 TA16.abund.r3$models$ProtostrongylideLarverLPG, 
                 TA16.abund.r4$models$ProtostrongylideLarverLPG, 
                 TA16.abund.r5$models$ProtostrongylideLarverLPG,
                 TA16.abund.r6$models$ProtostrongylideLarverLPG)),
  data.frame(resp_var="StrongylidetypeeggEPG",
             AIC(TA16.abund.r1$models$StrongylidetypeeggEPG, 
                 TA16.abund.r2$models$StrongylidetypeeggEPG, 
                 TA16.abund.r3$models$StrongylidetypeeggEPG, 
                 TA16.abund.r4$models$StrongylidetypeeggEPG, 
                 TA16.abund.r5$models$StrongylidetypeeggEPG,
                 TA16.abund.r6$models$StrongylidetypeeggEPG))
)
TA16.abund.aic[order(TA16.abund.aic$resp_var, TA16.abund.aic$AIC),]
##                                                                 resp_var df
## TA16.abund.r3$models$ProtostrongylideLarverLPG ProtostrongylideLarverLPG  7
## TA16.abund.r4$models$ProtostrongylideLarverLPG ProtostrongylideLarverLPG 10
## TA16.abund.r2$models$ProtostrongylideLarverLPG ProtostrongylideLarverLPG  7
## TA16.abund.r6$models$ProtostrongylideLarverLPG ProtostrongylideLarverLPG  8
## TA16.abund.r5$models$ProtostrongylideLarverLPG ProtostrongylideLarverLPG  8
## TA16.abund.r1$models$ProtostrongylideLarverLPG ProtostrongylideLarverLPG  7
## TA16.abund.r4$models$StrongylidetypeeggEPG         StrongylidetypeeggEPG 10
## TA16.abund.r2$models$StrongylidetypeeggEPG         StrongylidetypeeggEPG  7
## TA16.abund.r3$models$StrongylidetypeeggEPG         StrongylidetypeeggEPG  7
## TA16.abund.r5$models$StrongylidetypeeggEPG         StrongylidetypeeggEPG  8
## TA16.abund.r6$models$StrongylidetypeeggEPG         StrongylidetypeeggEPG  8
## TA16.abund.r1$models$StrongylidetypeeggEPG         StrongylidetypeeggEPG  7
##                                                      AIC
## TA16.abund.r3$models$ProtostrongylideLarverLPG  555.5019
## TA16.abund.r4$models$ProtostrongylideLarverLPG  555.8622
## TA16.abund.r2$models$ProtostrongylideLarverLPG  556.0400
## TA16.abund.r6$models$ProtostrongylideLarverLPG  557.7863
## TA16.abund.r5$models$ProtostrongylideLarverLPG  557.9711
## TA16.abund.r1$models$ProtostrongylideLarverLPG  563.0724
## TA16.abund.r4$models$StrongylidetypeeggEPG     1410.4468
## TA16.abund.r2$models$StrongylidetypeeggEPG     1412.8775
## TA16.abund.r3$models$StrongylidetypeeggEPG     1414.0250
## TA16.abund.r5$models$StrongylidetypeeggEPG     1414.1108
## TA16.abund.r6$models$StrongylidetypeeggEPG     1414.8578
## TA16.abund.r1$models$StrongylidetypeeggEPG     1415.2085
# ProtostrongylideLarverLPG: r3/r4/r2
# StrongylidetypeeggEPG: r6/r4/r2c

Add no. of positive samples to selected models

TA16.abund.r1$summary$n.pos <- sapply(TA16.abund.r1$summary$resp_var, function(x){
  sum(TA16.sub[,x] > 0, na.rm = T)
})
TA16.abund.r2$summary$n.pos <- sapply(TA16.abund.r2$summary$resp_var, function(x){
  sum(TA16.sub[,x] > 0, na.rm = T)
})
TA16.abund.r3$summary$n.pos <- sapply(TA16.abund.r3$summary$resp_var, function(x){
  sum(TA16.sub[,x] > 0, na.rm = T)
})
TA16.abund.r4$summary$n.pos <- sapply(TA16.abund.r4$summary$resp_var, function(x){
  sum(TA16.sub[,x] > 0, na.rm = T)
})
TA16.abund.r5$summary$n.pos <- sapply(TA16.abund.r5$summary$resp_var, function(x){
  sum(TA16.sub[,x] > 0, na.rm = T)
})
TA16.abund.r6$summary$n.pos <- sapply(TA16.abund.r6$summary$resp_var, function(x){
  sum(TA16.sub[,x] > 0, na.rm = T)
})
TA16.plot.ageA <-
ggplot(subset(TA16.abund.df, variable %in% c("StrongylidetypeeggEPG") & 
                !is.na(Sex) & !is.na(Adult_age_category) & !is.na(Carcass_mass_category) & !is.na(Municipality)),
       aes(Adult_age_category, value))+
  geom_boxplot(aes(fill = Adult_age_category), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"))+
  scale_x_discrete(labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  scale_y_continuous(transform = "log10")+
  labs(x = "Age group", y = "Abundance (log EPG)", fill = "")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable, nrow = 1,
             labeller = labeller(variable = c(StrongylidetypeeggEPG = "Trichostrongylidae eggs")))

TA16.plot.ageB <-
ggplot(subset(TA16.abund.df, variable %in% c("ProtostrongylideLarverLPG") & 
                !is.na(Sex) & !is.na(Adult_age_category) & !is.na(Carcass_mass_category) & !is.na(Municipality)),
       aes(Adult_age_category, value))+
  geom_boxplot(aes(fill = Adult_age_category), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"))+
  scale_x_discrete(labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  scale_y_continuous(transform = "log10")+
  labs(x = "Age group", y = "Abundance (log LPG)", fill = "")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable, nrow = 1,
             labeller = labeller(variable = c(ProtostrongylideLarverLPG="Protostrongylidae larvae")))
plot_grid(TA16.plot.ageB, TA16.plot.ageA, 
          nrow = 1, align = "hv", axis = "tblr")

ggplot(subset(TA16.abund.df, variable %in% c("StrongylidetypeeggEPG")),
       aes(Municipality, value))+
  geom_boxplot(aes(fill = Municipality), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  geom_signif(comparisons = list(c("Malvik","Meråker"),c("Malvik","Selbu"),c("Malvik","Tydal")), annotations = c(".","**","."),
              tip_length = 0.04, step_increase = 0.25)+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.15)))+
  labs(x = "Municipality", y = "Abundance (log-scale)", fill = "", title = "Trøndelag høst 2016")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "none",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 90))+
  facet_wrap(~ variable, nrow = 3)

Fig. 3

TA16.plot.abundA <-
ggplot(subset(TA16.abund.df, variable %in% c("StrongylidetypeeggEPG")),
       aes(Carcass_mass_category, value))+
  geom_boxplot(aes(fill = Carcass_mass_category), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Carcass mass category", y = "Abundance (log EPG)", fill = "Carcass mass category")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable + Adult_age_category, nrow = 1, 
             labeller = labeller(variable = c(StrongylidetypeeggEPG="Trichostrongylidae"),
                                 Adult_age_category = c(agegroup1="1 yr", agegroup2="2-5 yr", agegroup3="6+ yr")))
# only really relevant for age group 1
TA16.plot.abundB <-
ggplot(subset(TA16.abund.df, variable %in% c("ProtostrongylideLarverLPG") & Adult_age_category == "agegroup1"),
       aes(Carcass_mass_category, value))+
  geom_boxplot(aes(fill = Carcass_mass_category), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Carcass mass category", y = "Abundance (log LPG)", fill = "Carcass mass\ncategory")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable + Adult_age_category, nrow = 1, 
             labeller = labeller(variable = c(ProtostrongylideLarverLPG="Protostrongylidae"),
                                 Adult_age_category = c(agegroup1="1 yr", agegroup2="2-5 yr", agegroup3="6+ yr")))
plot_grid(TA16.plot.abundA, TA16.plot.abundB, 
          nrow = 1, align = "hv", axis = "tb",
          rel_widths = c(1,0.6),
          labels = c("a","b"))

ggsave("figures/Fig3_Abundance_by_AgeMassCat.png",units = "in", dpi = 1200, width = 11, height = 4)

Fig. S3

Comparison of carcass mass (sig) vs carcass mass category (sig) for ProtostrongylideLarverLPG

ggplot(subset(TA16.abund.df, variable %in% c("ProtostrongylideLarverLPG") & Adult_age_category == "agegroup1"),
       aes(Carcass_mass_kg, value))+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 3)+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  # scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  scale_y_continuous(limits = c(0,round(max(subset(TA16.abund.df, variable %in% c("ProtostrongylideLarverLPG") & Adult_age_category == "agegroup1")$value, na.rm = T),-1)))+
  labs(x = "Carcass mass (kg)", y = "Abundance (LPG)", fill = "Carcass mass\ncategory")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "right",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable + Adult_age_category, nrow = 1, 
             labeller = labeller(variable = c(ProtostrongylideLarverLPG="Protostrongylidae"),
                                 Adult_age_category = c(agegroup1="1 yr", agegroup2="2-5 yr", agegroup3="6+ yr")))
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 8 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 13 rows containing missing values or values outside the scale range
## (`geom_smooth()`).
## Warning: Removed 8 rows containing missing values or values outside the scale range
## (`geom_point()`).

ggsave("figures/FigS3_ProtostrongylidaeAbundance_by_MassKg.png",units = "in", dpi = 1200, width = 7.5, height = 4)
## `geom_smooth()` using formula = 'y ~ x'
## Warning: Removed 8 rows containing non-finite outside the scale range
## (`stat_smooth()`).
## Warning: Removed 13 rows containing missing values or values outside the scale range
## (`geom_smooth()`).
## Warning: Removed 8 rows containing missing values or values outside the scale range
## (`geom_point()`).
ggplot(subset(TA16.abund.df, variable %in% c("TrichurisEPG")),
       aes(Carcass_mass_kg, value))+
  geom_smooth(method=glm , color="black", fill="grey70", se=TRUE)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3)+
  scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"), labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  labs(x = "Carcass mass (kg)", y = "Abundance (EPG)", fill = "Age group")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "right",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))

ggplot(subset(TA16.abund.df, variable %in% c("TrichurisEPG")),
       aes(Adult_age_category, value))+
  # geom_smooth(method=glm , color="black", fill="grey70", se=TRUE)+
  # geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 3)+
  # scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  # labs(x = "Exact age (years)", y = "Abundance (EPG)", fill = "Carcass mass\ncategory")+
  geom_boxplot(aes(fill = Adult_age_category), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"), labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Age group", y = "Abundance (EPG)", fill = "Age group")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))

Fig. S5

Trichostrongylidae & Protostrongylidae egg abundance and municipality

TA16.sub$Municipality2 <- factor(
  TA16.sub$Municipality,
  levels = unique(TA16.sub[order(TA16.sub$MunicipalityDensity_Mean2016_18),"Municipality"]))
TA16.plot.abundC <-
ggplot(TA16.sub, aes(MunicipalityDensity_Mean2016_18, StrongylidetypeeggEPG))+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  # geom_point(fill = "gold", shape = 21, color = "black", size = 3)+
  geom_point(aes(fill = Municipality2), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.height = 0.1, jitter.width = 0.05))+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  scale_x_continuous(limits = c(0.2,0.7))+
  labs(x = "Moose density (mean 2016-2018)", y = "Abundance (log EPG)", fill = "")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))

TA16.plot.abundD <-
ggplot(TA16.sub, aes(Municipality2, StrongylidetypeeggEPG))+
  geom_violin(aes(fill = Municipality2), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Municipality2), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.width = 0.2))+
  geom_signif(comparisons = list(c("Selbu","Malvik")),
              annotations = paste0("p = ",
                                   round(TA16.abund.r4.posthoc.Strongylide.summary[which(TA16.abund.r4.posthoc.Strongylide.summary$covariates == "Selbu - Malvik"),"p.value"], 
                                         digits = 2)), 
              step_increase = 0.1)+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Municipality", y = "Abundance (log EPG)", fill = "", title = "Trichostrongylidae egg abundance\nby municipality (autumn)")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))

TA16.plot.abundE <-
ggplot(TA16.sub, aes(MunicipalityDensity_Mean2016_18, ProtostrongylideLarverLPG))+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  # geom_point(fill = "gold", shape = 21, color = "black", size = 3)+
  geom_point(aes(fill = Municipality2), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.height = 0.1, jitter.width = 0.05))+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  scale_x_continuous(limits = c(0.2,0.7))+
  labs(x = "Moose density (mean 2016-2018)", y = "Abundance (log LPG)", fill = "")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))

TA16.plot.abundF <-
ggplot(TA16.sub, aes(Municipality2, ProtostrongylideLarverLPG))+
  geom_violin(aes(fill = Municipality2), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Municipality2), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.width = 0.2))+
  geom_signif(comparisons = list(c("Selbu","Stjørdal")),
              annotations = paste0("p = ",
                                   round(TA16.abund.r4.posthoc.Protostrongylide.summary[which(TA16.abund.r4.posthoc.Protostrongylide.summary$covariates == "Stjørdal - Selbu"),"p.value"], 
                                         digits = 2)), 
              step_increase = 0.1)+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Municipality", y = "Abundance (log LPG)", fill = "", title = "Protostrongylidae larvae abundance\nby municipality (autumn)")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))
plot_grid(TA16.plot.abundD, TA16.plot.abundF, TA16.plot.abundC, TA16.plot.abundE,
          align = "hv", axis = "tblr",
          nrow = 2, labels = c("a","b","c","d"))

ggsave("figures/FigS5_Abundance_by_Municipality_autumn.png",units = "in", dpi = 1200, width = 10, height = 7)

Richness

Number of parasite groups, excluding hatched strongylide (as already counted in Strongylide). All cases of ProtostrongylideLarver detection have E. alces or V. alces identified, using instead of Protostrongylide detection.

# also excluding mites because so few anyway, and we don't know if they are soil/food or host parasites
# all cases of ProtostrongylideLarver detection have E or V identified, use instead of P detection
# table(TA16[,c("EalcesLarvae01","ValcesLarvae01","ProtostrongylideLarver01")])

TA16.sub$num.of.parasite.groups <- rowSums(TA16.sub[,c("Eimeria01", "Strongylidetypeegg01", "Moniezia01", "NematodirusNematodirellaEgg01", 
                                               "Trichuris01", "Capillaria01", "Strongyloides01",
                                               "EalcesLarvae01","ValcesLarvae01", "DictyocaulusLarver01")], na.rm = T)

Using Poisson distribution, as richness is count data.

## MAIN: Exact Age and MunicipalityDensity_Mean2016_18 to reduce comparisons in model
TA16.richP.r2 <- glm(
  formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab,
  data = TA16.sub,
  family = poisson(link = "log"),
  na.action = na.omit
)

## SUPP:
# kg continuous
TA16.richP.r1 <- glm(
  formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_kg + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab,
  data = TA16.sub,
  family = poisson(link = "log"),
  na.action = na.omit
)

# age group
# TA16.richP.r2 <- glm(
#   formula = num.of.parasite.groups ~ Adult_age_category + Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18,
#   data = TA16.sub,
#   family = poisson(link = "log"),
#   na.action = na.omit
# )

# 2016 density
TA16.richP.r3 <- glm(
  formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_2016 + Days.harvested.vs.lab,
  data = TA16.sub,
  family = poisson(link = "log"),
  na.action = na.omit
)

# Municipality
TA16.richP.r4 <- glm(
  formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category + Sex + Municipality + Days.harvested.vs.lab,
  data = TA16.sub,
  family = poisson(link = "log"),
  na.action = na.omit
)

# sex x weight interaction term
TA16.richP.r5 <- glm(
  formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category * Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab,
  data = TA16.sub,
  family = poisson(link = "log"),
  na.action = na.omit
)

# age x kg cat interaction term
TA16.richP.r6 <- glm(
  formula = num.of.parasite.groups ~ Exact_age * Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab,
  data = TA16.sub,
  family = poisson(link = "log"),
  na.action = na.omit
)
summary(TA16.richP.r1)
## 
## Call:
## glm(formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_kg + 
##     Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab, 
##     family = poisson(link = "log"), data = TA16.sub, na.action = na.omit)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                      1.557357   0.459165   3.392 0.000695 ***
## Exact_age                       -0.048539   0.033538  -1.447 0.147821    
## Carcass_mass_kg                 -0.003765   0.002708  -1.390 0.164382    
## SexFemale                       -0.130659   0.129239  -1.011 0.312023    
## MunicipalityDensity_Mean2016_18 -0.346338   0.521487  -0.664 0.506604    
## Days.harvested.vs.lab            0.017513   0.014328   1.222 0.221599    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 69.719  on 116  degrees of freedom
## Residual deviance: 54.680  on 111  degrees of freedom
## AIC: 374.42
## 
## Number of Fisher Scoring iterations: 4
performance::check_overdispersion(TA16.richP.r1)
## # Overdispersion test
## 
##        dispersion ratio =  0.483
##   Pearson's Chi-Squared = 53.563
##                 p-value =      1
## No overdispersion detected.
summary(TA16.richP.r2)
## 
## Call:
## glm(formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category + 
##     Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab, 
##     family = poisson(link = "log"), data = TA16.sub, na.action = na.omit)
## 
## Coefficients:
##                                 Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                      1.07136    0.28189   3.801 0.000144 ***
## Exact_age                       -0.07498    0.02933  -2.556 0.010585 *  
## Carcass_mass_category.L          0.04098    0.10801   0.379 0.704364    
## SexFemale                       -0.10811    0.12921  -0.837 0.402765    
## MunicipalityDensity_Mean2016_18 -0.25524    0.52439  -0.487 0.626444    
## Days.harvested.vs.lab            0.01748    0.01432   1.221 0.221960    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 69.719  on 116  degrees of freedom
## Residual deviance: 56.486  on 111  degrees of freedom
## AIC: 376.23
## 
## Number of Fisher Scoring iterations: 5
performance::check_overdispersion(TA16.richP.r2)
## # Overdispersion test
## 
##        dispersion ratio =  0.497
##   Pearson's Chi-Squared = 55.159
##                 p-value =      1
## No overdispersion detected.
summary(TA16.richP.r3)
## 
## Call:
## glm(formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category + 
##     Sex + MunicipalityDensity_2016 + Days.harvested.vs.lab, family = poisson(link = "log"), 
##     data = TA16.sub, na.action = na.omit)
## 
## Coefficients:
##                          Estimate Std. Error z value Pr(>|z|)    
## (Intercept)               1.06572    0.29840   3.571 0.000355 ***
## Exact_age                -0.07495    0.02936  -2.552 0.010696 *  
## Carcass_mass_category.L   0.03826    0.10732   0.357 0.721457    
## SexFemale                -0.10706    0.12924  -0.828 0.407442    
## MunicipalityDensity_2016 -0.24510    0.56833  -0.431 0.666273    
## Days.harvested.vs.lab     0.01766    0.01431   1.234 0.217195    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 69.719  on 116  degrees of freedom
## Residual deviance: 56.537  on 111  degrees of freedom
## AIC: 376.28
## 
## Number of Fisher Scoring iterations: 5
performance::check_overdispersion(TA16.richP.r3)
## # Overdispersion test
## 
##        dispersion ratio =  0.497
##   Pearson's Chi-Squared = 55.194
##                 p-value =      1
## No overdispersion detected.
summary(TA16.richP.r4)
## 
## Call:
## glm(formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category + 
##     Sex + Municipality + Days.harvested.vs.lab, family = poisson(link = "log"), 
##     data = TA16.sub, na.action = na.omit)
## 
## Coefficients:
##                         Estimate Std. Error z value Pr(>|z|)   
## (Intercept)              0.81666    0.26541   3.077  0.00209 **
## Exact_age               -0.07657    0.02942  -2.603  0.00925 **
## Carcass_mass_category.L  0.04874    0.10933   0.446  0.65575   
## SexFemale               -0.12429    0.13061  -0.952  0.34130   
## MunicipalityMeråker     -0.08717    0.37502  -0.232  0.81620   
## MunicipalitySelbu        0.18860    0.26603   0.709  0.47836   
## MunicipalityStjørdal     0.20193    0.34400   0.587  0.55720   
## MunicipalityTydal        0.38892    0.32263   1.205  0.22802   
## Days.harvested.vs.lab    0.01336    0.01474   0.906  0.36468   
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 69.719  on 116  degrees of freedom
## Residual deviance: 53.901  on 108  degrees of freedom
## AIC: 379.64
## 
## Number of Fisher Scoring iterations: 4
performance::check_overdispersion(TA16.richP.r4)
## # Overdispersion test
## 
##        dispersion ratio =  0.484
##   Pearson's Chi-Squared = 52.277
##                 p-value =      1
## No overdispersion detected.
summary(TA16.richP.r5)
## 
## Call:
## glm(formula = num.of.parasite.groups ~ Exact_age + Carcass_mass_category * 
##     Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab, 
##     family = poisson(link = "log"), data = TA16.sub, na.action = na.omit)
## 
## Coefficients:
##                                    Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                        1.040208   0.292469   3.557 0.000376 ***
## Exact_age                         -0.074721   0.029316  -2.549 0.010809 *  
## Carcass_mass_category.L           -0.008176   0.163693  -0.050 0.960166    
## SexFemale                         -0.074577   0.153991  -0.484 0.628176    
## MunicipalityDensity_Mean2016_18   -0.242498   0.525862  -0.461 0.644696    
## Days.harvested.vs.lab              0.017682   0.014322   1.235 0.216978    
## Carcass_mass_category.L:SexFemale  0.086307   0.212267   0.407 0.684306    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 69.719  on 116  degrees of freedom
## Residual deviance: 56.320  on 110  degrees of freedom
## AIC: 378.06
## 
## Number of Fisher Scoring iterations: 5
performance::check_overdispersion(TA16.richP.r5)
## # Overdispersion test
## 
##        dispersion ratio =  0.501
##   Pearson's Chi-Squared = 55.086
##                 p-value =      1
## No overdispersion detected.
summary(TA16.richP.r6)
## 
## Call:
## glm(formula = num.of.parasite.groups ~ Exact_age * Carcass_mass_category + 
##     Sex + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab, 
##     family = poisson(link = "log"), data = TA16.sub, na.action = na.omit)
## 
## Coefficients:
##                                    Estimate Std. Error z value Pr(>|z|)    
## (Intercept)                        1.077567   0.283391   3.802 0.000143 ***
## Exact_age                         -0.078471   0.034244  -2.292 0.021934 *  
## Carcass_mass_category.L            0.058978   0.137951   0.428 0.668991    
## SexFemale                         -0.109125   0.129261  -0.844 0.398545    
## MunicipalityDensity_Mean2016_18   -0.250292   0.524664  -0.477 0.633325    
## Days.harvested.vs.lab              0.017249   0.014364   1.201 0.229808    
## Exact_age:Carcass_mass_category.L -0.009813   0.047298  -0.207 0.835637    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 69.719  on 116  degrees of freedom
## Residual deviance: 56.442  on 110  degrees of freedom
## AIC: 378.19
## 
## Number of Fisher Scoring iterations: 5
performance::check_overdispersion(TA16.richP.r6)
## # Overdispersion test
## 
##        dispersion ratio =  0.499
##   Pearson's Chi-Squared = 54.911
##                 p-value =      1
## No overdispersion detected.
plot(allEffects(TA16.richP.r1))

plot(allEffects(TA16.richP.r2))

Model selection

TA16.richP.aic <- AIC(TA16.richP.r1, TA16.richP.r2, TA16.richP.r3, TA16.richP.r4, TA16.richP.r5, TA16.richP.r6)
TA16.richP.aic[order(TA16.richP.aic$AIC),]
##               df      AIC
## TA16.richP.r1  6 374.4226
## TA16.richP.r2  6 376.2291
## TA16.richP.r3  6 376.2801
## TA16.richP.r5  7 378.0627
## TA16.richP.r6  7 378.1850
## TA16.richP.r4  9 379.6437
# r1, then r2c, then r3 

Fig. S2ab

TA16.plot.richA <-
ggplot(subset(TA16.sub, !is.na(num.of.parasite.groups)), 
       aes(Exact_age, num.of.parasite.groups))+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  geom_point(shape = 21, color = "black", fill = "green3", size = 3)+
  # geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3)+
  # scale_fill_manual(values = c("#C7E9C0","#74C476","#006D2C"))+
  scale_y_continuous(limits = c(0, round(max(TA16.sub$num.of.parasite.groups, na.rm = T)+1)))+
  labs(x = "\nAge (years)", y = "No. of parasite groups", fill = "", title = "Autumn\n")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))


TA16.plot.richB <-
ggplot(subset(TA16.sub, !is.na(num.of.parasite.groups)), 
       aes(Carcass_mass_category, num.of.parasite.groups))+
  # geom_boxplot(aes(fill = Carcass_mass_category), outlier.colour = NA, alpha = 0.25)+
  geom_violin(aes(fill = Carcass_mass_category), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Carcass_mass_category), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#3C2692","#CBC9DA"))+
  scale_y_continuous(limits = c(0, round(max(TA16.sub$num.of.parasite.groups, na.rm = T)+1)))+
  labs(x = "\nCarcass mass category", y = "No. of parasite groups", fill = "", title = "Autumn\n")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))
TA16.plot.richA
## `geom_smooth()` using formula = 'y ~ x'

TA16.plot.richB

Other figures

ggplot(subset(TA16.sub, !is.na(num.of.parasite.groups)), 
       aes(Adult_age_category, num.of.parasite.groups))+
  geom_boxplot(aes(fill = Sex), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Sex), shape = 21, color = "black", size = 2, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#E41A1C","#377EB8"))+
  scale_x_discrete(labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  labs(x = "Age group", y = "No. of parasite groups", fill = "Sex")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(subset(TA16.sub, !is.na(num.of.parasite.groups)), 
       aes(Municipality, num.of.parasite.groups))+
  geom_boxplot(aes(fill = Municipality), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 2, 
             position = position_jitterdodge(jitter.width = 0.2))+
  labs(x = "Municipality", y = "No. of parasite groups", fill = "")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(subset(TA16.sub, !is.na(num.of.parasite.groups)), 
       aes(MunicipalityDensity_2016, num.of.parasite.groups))+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 2)+
  labs(x = "Harvest density (2016)", y = "No. of parasite groups", fill = "Municipality")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(subset(TA16.sub, !is.na(num.of.parasite.groups)), 
       aes(MunicipalityDensity_Mean2016_18, num.of.parasite.groups))+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 2)+
  labs(x = "Harvest density (2016-2018)", y = "No. of parasite groups", fill = "Municipality")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "", 
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

Table 3

Stat tables

# main table, present best AIC fit
TA16.richP.r1.summary <- summary(TA16.richP.r1)
colnames(TA16.richP.r1.summary$coefficients) <- c("estimate","std.error","statistic","p.value")
TA16.richP.r1.summary <- data.frame(
  resp_var="num.of.parasite.groups",
  covariates=row.names(TA16.richP.r1.summary$coefficients),
  as.data.frame(TA16.richP.r1.summary$coefficients),
  p.adj=NA,
  row.names = NULL
)

TA16.prev.r2$summary[which(TA16.prev.r2$summary$covariates != "(Intercept)" & TA16.prev.r2$summary$p.value < 0.05),]
##                    resp_var              covariates   estimate std.error
## 26 ProtostrongylideLarver01               Exact_age -2.2002240 0.5571874
## 32           EalcesLarvae01               Exact_age -3.3206061 0.8611806
## 33           EalcesLarvae01 Carcass_mass_category.L  1.7491054 0.8007562
## 38           ValcesLarvae01               Exact_age -1.3140766 0.4485914
## 39           ValcesLarvae01 Carcass_mass_category.L  0.9670895 0.4926710
##    statistic      p.value      p.adj n.pos
## 26 -3.948805 7.854244e-05 0.00242163    61
## 32 -3.855876 1.153157e-04 0.00242163    53
## 33  2.184317 2.893896e-02 0.15192952    53
## 38 -2.929340 3.396827e-03 0.02419897    48
## 39  1.962952 4.965178e-02 0.20853749    48
TA16.abund.r4$summary[which(TA16.abund.r4$summary$resp_var %in% c("StrongylidetypeeggEPG","ProtostrongylideLarverLPG") & TA16.abund.r4$summary$covariates != "(Intercept)" & TA16.abund.r4$summary$p.value < 0.05),]
##                     resp_var              covariates    estimate  std.error
## 3      StrongylidetypeeggEPG Carcass_mass_category.L  0.23694734 0.12070813
## 4      StrongylidetypeeggEPG               SexFemale -0.35246577 0.16050113
## 6      StrongylidetypeeggEPG       MunicipalitySelbu  0.90794612 0.33869841
## 29 ProtostrongylideLarverLPG               Exact_age -1.91127716 0.39672676
## 30 ProtostrongylideLarverLPG Carcass_mass_category.L  0.79327464 0.17718616
## 31 ProtostrongylideLarverLPG               SexFemale -0.57447542 0.24157287
## 34 ProtostrongylideLarverLPG    MunicipalityStjørdal  1.55677808 0.69726554
## 36 ProtostrongylideLarverLPG   Days.harvested.vs.lab  0.09055432 0.02434742
##    statistic      p.value        p.adj n.pos
## 3   1.962977 4.964879e-02 1.378070e-01   114
## 4  -2.196033 2.808958e-02 9.192955e-02   114
## 6   2.680692 7.347011e-03 3.778463e-02   114
## 29 -4.817616 1.452837e-06 1.743404e-05    61
## 30  4.477069 7.567481e-06 6.810733e-05    61
## 31 -2.378063 1.740387e-02 6.961547e-02    61
## 34  2.232690 2.556937e-02 9.192955e-02    61
## 36  3.719257 1.998095e-04 1.438628e-03    61
TA16.richP.r1.summary[which(TA16.richP.r1.summary$covariates != "(Intercept)" & TA16.richP.r1.summary$p.value < 0.05),]
## [1] resp_var   covariates estimate   std.error  statistic  p.value    p.adj     
## <0 rows> (or 0-length row.names)
stats.tab1 <- rbind.data.frame(
  data.frame(model="M2", TA16.prev.r2$summary[which(TA16.prev.r2$summary$resp_var %in% c("ProtostrongylideLarver01","EalcesLarvae01","ValcesLarvae01")),]),
  data.frame(model="M4", TA16.abund.r4$summary[which(TA16.abund.r4$summary$resp_var %in% c("StrongylidetypeeggEPG") & 
                                TA16.abund.r4$summary$covariates %in% c("(Intercept)","Exact_age","Carcass_mass_category.L","SexFemale","Days.harvested.vs.lab")),]),
  data.frame(model="M4", TA16.abund.r4.posthoc.Strongylide.summary[which(TA16.abund.r4.posthoc.Strongylide.summary$p.value < 0.1),], n.pos=""), # put rest in supp
  data.frame(model="M4", TA16.abund.r4$summary[which(TA16.abund.r4$summary$resp_var %in% c("ProtostrongylideLarverLPG") & 
                                TA16.abund.r4$summary$covariates %in% c("(Intercept)","Exact_age","Carcass_mass_category.L","SexFemale","Days.harvested.vs.lab")),]),
  data.frame(model="M4", TA16.abund.r4.posthoc.Protostrongylide.summary[which(TA16.abund.r4.posthoc.Protostrongylide.summary$p.value < 0.1),], n.pos=""), # put rest in supp
  data.frame(model="M1", TA16.richP.r1.summary, n.pos=length(which(!is.na(TA16.sub$num.of.parasite.groups))))
  
)

stats.tab1$coeff_print <- ifelse(is.na(stats.tab1$estimate),"",paste(round(stats.tab1$estimate, digits = 3),"\u00B1", round(stats.tab1$std.error, digits = 3)))
stats.tab1$pval_print <- ifelse(is.na(stats.tab1$p.value),"",ifelse(stats.tab1$p.value >= 0.001, round(stats.tab1$p.value, digits = 3), "<0.001")) 
stats.tab1$padj_print <- ifelse(is.na(stats.tab1$p.adj),"",ifelse(stats.tab1$p.adj >= 0.001, round(stats.tab1$p.adj, digits = 3), "<0.001"))

stats.tab1[,c("model","resp_var","n.pos","covariates","coeff_print","pval_print","padj_print")]
##     model                  resp_var n.pos                      covariates
## 25     M2  ProtostrongylideLarver01    61                     (Intercept)
## 26     M2  ProtostrongylideLarver01    61                       Exact_age
## 27     M2  ProtostrongylideLarver01    61         Carcass_mass_category.L
## 28     M2  ProtostrongylideLarver01    61                       SexFemale
## 29     M2  ProtostrongylideLarver01    61 MunicipalityDensity_Mean2016_18
## 30     M2  ProtostrongylideLarver01    61           Days.harvested.vs.lab
## 31     M2            EalcesLarvae01    53                     (Intercept)
## 32     M2            EalcesLarvae01    53                       Exact_age
## 33     M2            EalcesLarvae01    53         Carcass_mass_category.L
## 34     M2            EalcesLarvae01    53                       SexFemale
## 35     M2            EalcesLarvae01    53 MunicipalityDensity_Mean2016_18
## 36     M2            EalcesLarvae01    53           Days.harvested.vs.lab
## 37     M2            ValcesLarvae01    48                     (Intercept)
## 38     M2            ValcesLarvae01    48                       Exact_age
## 39     M2            ValcesLarvae01    48         Carcass_mass_category.L
## 40     M2            ValcesLarvae01    48                       SexFemale
## 41     M2            ValcesLarvae01    48 MunicipalityDensity_Mean2016_18
## 42     M2            ValcesLarvae01    48           Days.harvested.vs.lab
## 1      M4     StrongylidetypeeggEPG   114                     (Intercept)
## 2      M4     StrongylidetypeeggEPG   114                       Exact_age
## 3      M4     StrongylidetypeeggEPG   114         Carcass_mass_category.L
## 4      M4     StrongylidetypeeggEPG   114                       SexFemale
## 9      M4     StrongylidetypeeggEPG   114           Days.harvested.vs.lab
## 21     M4     StrongylidetypeeggEPG                        Selbu - Malvik
## 281    M4 ProtostrongylideLarverLPG    61                     (Intercept)
## 291    M4 ProtostrongylideLarverLPG    61                       Exact_age
## 301    M4 ProtostrongylideLarverLPG    61         Carcass_mass_category.L
## 311    M4 ProtostrongylideLarverLPG    61                       SexFemale
## 361    M4 ProtostrongylideLarverLPG    61           Days.harvested.vs.lab
## 8      M4 ProtostrongylideLarverLPG                      Stjørdal - Selbu
## 11     M1    num.of.parasite.groups   117                     (Intercept)
## 22     M1    num.of.parasite.groups   117                       Exact_age
## 310    M1    num.of.parasite.groups   117                 Carcass_mass_kg
## 43     M1    num.of.parasite.groups   117                       SexFemale
## 5      M1    num.of.parasite.groups   117 MunicipalityDensity_Mean2016_18
## 6      M1    num.of.parasite.groups   117           Days.harvested.vs.lab
##        coeff_print pval_print padj_print
## 25   5.588 ± 1.612     <0.001      0.007
## 26    -2.2 ± 0.557     <0.001      0.002
## 27    1.13 ± 0.675      0.094      0.304
## 28  -0.762 ± 0.586      0.193      0.406
## 29  -3.805 ± 2.633      0.149      0.367
## 30   0.124 ± 0.083      0.138      0.367
## 31   5.227 ± 1.666      0.002      0.018
## 32  -3.321 ± 0.861     <0.001      0.002
## 33   1.749 ± 0.801      0.029      0.152
## 34  -1.005 ± 0.592       0.09      0.304
## 35  -0.226 ± 2.589      0.931      0.996
## 36   0.118 ± 0.084      0.163       0.38
## 37    3.79 ± 1.296      0.003      0.024
## 38  -1.314 ± 0.449      0.003      0.024
## 39   0.967 ± 0.493       0.05      0.209
## 40  -0.788 ± 0.504      0.118      0.354
## 41  -3.835 ± 2.244      0.088      0.304
## 42   0.081 ± 0.062      0.188      0.406
## 1    4.738 ± 0.348     <0.001     <0.001
## 2   -0.003 ± 0.024      0.901      0.927
## 3    0.237 ± 0.121       0.05      0.138
## 4   -0.352 ± 0.161      0.028      0.092
## 9    -0.039 ± 0.02      0.052      0.138
## 21   0.908 ± 0.339      0.052           
## 281  4.134 ± 0.753     <0.001     <0.001
## 291 -1.911 ± 0.397     <0.001     <0.001
## 301  0.793 ± 0.177     <0.001     <0.001
## 311 -0.574 ± 0.242      0.017       0.07
## 361  0.091 ± 0.024     <0.001      0.001
## 8    1.051 ± 0.359      0.025           
## 11   1.557 ± 0.459     <0.001           
## 22  -0.049 ± 0.034      0.148           
## 310 -0.004 ± 0.003      0.164           
## 43  -0.131 ± 0.129      0.312           
## 5   -0.346 ± 0.521      0.507           
## 6    0.018 ± 0.014      0.222
write.table(stats.tab1[,c("resp_var","model","n.pos","covariates","coeff_print","pval_print","padj_print")],
            "figures/table_statistic_models_autumn.txt",
            row.names = F, quote = F, sep = "\t", fileEncoding = "latin1")

Autumn vs Winter Trøndelag

Associations comparing adult moose (female, due to low male numbers) between autumn 2016 (hunted) and winter 2017 (GPS-marked) in Trøndelag (code TS1617 - “S” for seasonal differences).

Summaries

Generate some basic summaries of metadata.

# subset to adult female moose in Trøndelag in 2016 and 2017
TS1617 <- dat[which(dat$Year %in% c("2017","2016") & 
                      dat$Adult_age_category %in% c("agegroup2","agegroup3") &
                      dat$Sex == "Female"),]

table(TS1617[,c("Adult_age_category","Year")])
##                   Year
## Adult_age_category 2016 2017
##          agegroup1    0    0
##          agegroup2   25   14
##          agegroup3   17    6
TS1617 <- TS1617[which(!is.na(TS1617$Municipality)),]

Table 1b

Basic stats

table(TS1617$McMaster_performed)
## 
##  1 
## 62
table(TS1617$Baermann_performed)
## 
##  0  1 
##  8 54
table(TS1617$Sex, TS1617$Adult_age_category, TS1617$Season)
## , ,  = Autumn
## 
##         
##          agegroup1 agegroup2 agegroup3
##   Male           0         0         0
##   Female         0        25        17
## 
## , ,  = Winter
## 
##         
##          agegroup1 agegroup2 agegroup3
##   Male           0         0         0
##   Female         0        14         6
table(TS1617$Sex, TS1617$Season)
##         
##          Autumn Winter
##   Male        0      0
##   Female     42     20
sum(table(TS1617$Sex, TS1617$Adult_age_category))
## [1] 62
# summary table
ms.tab2 <- as.data.frame(table(TS1617$Sex, TS1617$Adult_age_category, TS1617$Season))
names(ms.tab2) <- c("Sex","Adult_age_category","Season","count")

ms.tab2 <- rbind.data.frame(
  ms.tab2,
  data.frame(Sex="Female", Adult_age_category="all", Season="all", count=nrow(TS1617))
)

ms.tab2$Carcass_mass_kg.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "Carcass_mass_kg", 
                                      groups = c("Sex","Adult_age_category","Season"), 
                                      sum.tab = ms.tab2, df.meta = TS1617)

# add major parasite groups
# same as abundance/prevalence models, must be at least 5 positive samples to include in table
# v1 - intensity
ms.tab2$StrongylidetypeeggEPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "StrongylidetypeeggEPG", 
                                               groups = c("Sex","Adult_age_category","Season"), 
                                               sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)
ms.tab2$NematodirussppEPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "NematodirussppEPG", 
                                           groups = c("Sex","Adult_age_category","Season"), 
                                           sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)
ms.tab2$NematodirusBattusEPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "NematodirusBattusEPG", 
                                              groups = c("Sex","Adult_age_category","Season"), 
                                              sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)
ms.tab2$TrichurisEPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "TrichurisEPG", 
                                      groups = c("Sex","Adult_age_category","Season"), 
                                      sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)
ms.tab2$CapillariaEPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "CapillariaEPG", 
                                       groups = c("Sex","Adult_age_category","Season"), 
                                       sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)
ms.tab2$EimeriaOPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "EimeriaOPG", 
                                    groups = c("Sex","Adult_age_category","Season"), 
                                    sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)
ms.tab2$ProtostrongylideLarverLPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "ProtostrongylideLarverLPG", 
                                                   groups = c("Sex","Adult_age_category","Season"), 
                                                   sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)
ms.tab2$DictyocaulusLPG.Median <- sapply(seq(1,nrow(ms.tab2)), calc_median_IQR_label, v = "DictyocaulusLPG", 
                                         groups = c("Sex","Adult_age_category","Season"), 
                                         sum.tab = ms.tab2, df.meta = TS1617, intensity = TRUE)

ms.tab2$Carcass_mass_category <- NA 

Table 2b

Autumn vs winter, summary table of prevalence by age and season

TS1617.det.df <- melt(
  TS1617[,c("IndividualID","Season","Adult_age_category",
            "Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed", 
            mcmaster.parasite.groups.01, baermann.parasite.groups.01)], 
  id.vars = c("IndividualID","Season","Adult_age_category",
              "Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed"),
  measure.vars = c(mcmaster.parasite.groups.01, baermann.parasite.groups.01)
)

TS1617.det.by.group <- dcast(
  TS1617.det.df,
  Season + Adult_age_category ~ variable, 
  value.var = "value",
  fun.aggregate = sum, fill = 0, drop = T, na.rm = T
)

## Calculate no. of individuals based on samples for which test was performed
TS1617.det.by.group$num_inds.MM <- sapply(seq(1,nrow(TS1617.det.by.group)), function(i){
  s <- TS1617.det.by.group[i,"Season"]
  age <- TS1617.det.by.group[i,"Adult_age_category"]
  length(which(TS1617$Season == s & TS1617$Adult_age_category == age & TS1617$McMaster_performed == 1))
})

TS1617.det.by.group$num_inds.BA <- sapply(seq(1,nrow(TS1617.det.by.group)), function(i){
  s <- TS1617.det.by.group[i,"Season"]
  age <- TS1617.det.by.group[i,"Adult_age_category"]
  length(which(TS1617$Season == s & TS1617$Adult_age_category == age & TS1617$Baermann_performed == 1))
})

TS1617.det.by.group.hm <- melt(TS1617.det.by.group, 
                             id.vars = c("Season","Adult_age_category","num_inds.MM","num_inds.BA"),
                             measure.vars = c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
                             variable.name = "parasite", value.name = "n.positive")

TS1617.det.by.group.hm$group <- paste(TS1617.det.by.group.hm$Season, TS1617.det.by.group.hm$Adult_age_category, sep = "_")

TS1617.det.by.group.hm$proportion <- ifelse(
  TS1617.det.by.group.hm$parasite %in% mcmaster.parasite.groups.01, 
  TS1617.det.by.group.hm$n.positive / TS1617.det.by.group.hm$num_inds.MM,
  TS1617.det.by.group.hm$n.positive / TS1617.det.by.group.hm$num_inds.BA
)

# add 95%CI to prevalence
TS1617.det.by.group.hm$CI95.lower <- sapply(seq(1,nrow(TS1617.det.by.group.hm)), function(i){
  p <- as.character(TS1617.det.by.group.hm[i,"parasite"])
  n.det <- TS1617.det.by.group.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TS1617.det.by.group.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TS1617.det.by.group.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[1])
})

TS1617.det.by.group.hm$CI95.upper <- sapply(seq(1,nrow(TS1617.det.by.group.hm)), function(i){
  p <- as.character(TS1617.det.by.group.hm[i,"parasite"])
  n.det <- TS1617.det.by.group.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TS1617.det.by.group.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TS1617.det.by.group.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[2])
})

TS1617.det.by.group.hm$parasite <- factor(TS1617.det.by.group.hm$parasite,
                                          levels = c("MiddEgg01", "Moniezia01", "Eimeria01",
                                                     "Strongyloides01", "Capillaria01", "Trichuris01", "NematodirusNematodirellaEgg01",
                                                     "Strongylidetypeegg01",
                                                     "ValcesLarvae01", "EalcesLarvae01", "ProtostrongylideLarver01",
                                                     "DictyocaulusLarver01"))

# exclude mites
TS1617.det.by.group.hm <- TS1617.det.by.group.hm[which(TS1617.det.by.group.hm$parasite != "MiddEgg01"),]
TS1617.det.by.group.hm$parasite <- droplevels(TS1617.det.by.group.hm$parasite)
TS1617.det.by.group.hm$percent <- round(TS1617.det.by.group.hm$proportion * 100, 1)

TS1617.det.by.group.hm$label_v2 <- sapply(seq(1,nrow(TS1617.det.by.group.hm)), function(i){
  ct <- TS1617.det.by.group.hm[i, "n.positive"]
  if(ct == 0){
    return(0)
  } else {
    per <- TS1617.det.by.group.hm[i,"percent"]
    return(paste0(ct," (",per,"%)"))
  }
})

TS1617.det.by.group.hm$label_v3 <- sapply(seq(1,nrow(TS1617.det.by.group.hm)), function(i){
  if(TS1617.det.by.group.hm[i,"proportion"] == 0){
    return(0)
  } else {
    prop <- round(TS1617.det.by.group.hm[i,"proportion"], digits = 2)
    ciL <- round(TS1617.det.by.group.hm[i,"CI95.lower"], digits = 1)
    ciU <- round(TS1617.det.by.group.hm[i,"CI95.upper"], digits = 1)
    return(paste0(prop,"\n(",ciL,"-",ciU,")"))
  }
}) 

TS1617.det.by.group[,c("Season","Adult_age_category","num_inds.BA","num_inds.MM")]
##   Season Adult_age_category num_inds.BA num_inds.MM
## 1 Autumn          agegroup2          20          25
## 2 Autumn          agegroup3          14          17
## 3 Winter          agegroup2          14          14
## 4 Winter          agegroup3           6           6
prev.fig2 <-
ggplot(TS1617.det.by.group.hm, aes(group, parasite, fill = proportion))+
  geom_tile(colour = "grey50", linewidth = 0.5)+
  scale_fill_gradient(low="white", high="grey50")+
  # geom_vline(xintercept = 2.5, color = "black", linewidth = 0.5, linetype = 2)+
  geom_text(aes(label=label_v3))+
  scale_y_discrete(labels = c("*Moniezia* spp. eggs","*Eimeria* spp. oocysts",
                              "*Strongyloides* spp. eggs","*Capillaria* spp. eggs","*Trichuris* spp. eggs","Nematodirinae eggs",
                              "Trichostrongylidae spp.", "*V. alces* larvae","*E. alces* larvae","Protostrongylidae larvae",
                              "*Dictyocaulus* spp. larvae"))+
  scale_x_discrete(labels = c("Autumn\nFemale\n2-5 yr\nnL=20\nnE=25","Autumn\nFemale\n6+ yr\nnL=14\nnE=17",
                              "Winter\nFemale\n2-5 yr\nnL=14\nnE=14","Winter\nFemale\n6+ yr\nnL=6\nnE=6"),
                   position = "top")+
  labs(y = "", x = "", fill = "Prevalence    \n")+
  theme_bw()+
  guides(fill = guide_colorbar(barwidth = 10, barheight = 1))+
  theme(axis.title = element_text(size = 13, colour = "black"),
        # axis.text.y = ggtext::element_markdown(size = 13, colour = "black", hjust = 1), 
        axis.text.y = element_blank(),
        axis.text.x = element_text(size = 12, colour = "black", angle = 0, vjust = 0.5),
        legend.text = element_text(size = 11, colour = "black"), legend.title = element_text(size = 12, colour = "black"),
        legend.position = "none",
        panel.border = element_blank(), axis.ticks = element_blank())
prev.fig2

prop.table(table(TS1617$Strongylidetypeegg01, TS1617$Season), margin = 2)
##    
##         Autumn     Winter
##   0 0.07142857 0.10000000
##   1 0.92857143 0.90000000

Other figures

TS1617.abund.df <- melt(
  TS1617[,c("IndividualID","Season","Adult_age_category",
            "Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed",
            mcmaster.parasite.groups.EPG, baermann.parasite.groups.LPG)], 
  id.vars = c("IndividualID","Season","Adult_age_category",
              "Municipality","MunicipalityDensity_2016","MunicipalityDensity_Mean2016_18","McMaster_performed","Baermann_performed"),
  measure.vars = c(mcmaster.parasite.groups.EPG, baermann.parasite.groups.LPG)
)
ggplot(subset(TS1617.abund.df, !variable %in% c("EimeriaOPG","CapillariaEPG","MiddEggEPG",
                                                "NematodirusBattusEPG","DictyocaulusLPG")),
       aes(Season, value))+
  geom_violin(aes(fill = Adult_age_category), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#74C476","#006D2C"), labels = c(agegroup1="1 yr",agegroup2="2-5 yr",agegroup3="6+ yr"))+
  # scale_x_discrete()+
  # scale_y_continuous(transform = "log10")+
  labs(x = "Season", y = "Abundance (log scale)", fill = "Age group", title = "")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, nrow = 1, scales = "free_y")

Models

GLMs testing for associations between season (factor) and age group (ordered factor), as well as environment (mean harvest density over 2016-2018, to match Autumn models). Includes adjustment for multiple hypothesis testing.

Must be present in at least 5 samples to test (otherwise not enough variation in dataset). One model per parasite:

  • season + age group + harvest density (mean over 2016-2018)

Prevalence

## MAIN
TS1617.prev <- run_glm(
  TS1617,
  c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
  " ~ Season + Adult_age_category + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "binomial",
  min.samples = 5
)
## [1] "Skipping Eimeria01, not enough positive samples."
## [1] "Running logistic model for Strongylidetypeegg01"
## [1] "Running logistic model for NematodirusNematodirellaEgg01"
## [1] "Running logistic model for Trichuris01"
## [1] "Skipping Capillaria01, not enough positive samples."
## [1] "Skipping MiddEgg01, not enough positive samples."
## [1] "Skipping Moniezia01, not enough positive samples."
## [1] "Skipping Strongyloides01, not enough positive samples."
## [1] "Running logistic model for ProtostrongylideLarver01"
## [1] "Skipping EalcesLarvae01, not enough positive samples."
## [1] "Skipping ValcesLarvae01, not enough positive samples."
## [1] "Skipping DictyocaulusLarver01, not enough positive samples."
TS1617.prev$summary[which(TS1617.prev$summary$covariates != "(Intercept)" & TS1617.prev$summary$p.value < 0.1),]
##               resp_var           covariates  estimate std.error statistic
## 3 Strongylidetypeegg01 Adult_age_category.L -1.519379 0.8426482   -1.8031
##      p.value     p.adj
## 3 0.07137245 0.5976107

Add no. of positive samples to table

TS1617.prev$summary$n.pos <- sapply(TS1617.prev$summary$resp_var, function(x){
  sum(TS1617[,x], na.rm = T)
})
ggplot(subset(TS1617.det.df, variable %in% c("Strongylidetypeegg01")),
       aes(Season, value))+
  geom_violin(aes(fill = Adult_age_category), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2, jitter.height = 0.05))+
  scale_fill_manual(values = c("#74C476","#006D2C"), labels = c(agegroup2="2-5 yr",agegroup3="6+ yr"))+
  scale_x_discrete(labels = c("Autumn"="Autumn (2016)","Winter"="Winter (2017)"))+
  labs(x = "Season (year)", y = "Detection", fill = "Age group")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, nrow = 1,
             labeller = labeller(variable = c(Strongylidetypeegg01="Trichostrongylidae eggs")))

Abundance

Rounding abundances to nearest integer and running negative binomial GLMs.

## MAIN
TS1617.abund <- run_glm(
  TS1617,
  c(mcmaster.parasite.groups.EPG,baermann.parasite.groups.LPG),
  " ~ Season + Adult_age_category + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab",
  fam = "nbinom1",
  ct_round = T,
  min.samples = 5
)
## [1] "Skipping EimeriaOPG, not enough positive samples."
## [1] "Running Neg Binomial model for StrongylidetypeeggEPG"
## [1] "Running Neg Binomial model for NematodirussppEPG"
## [1] "Skipping NematodirusBattusEPG, not enough positive samples."
## [1] "Running Neg Binomial model for TrichurisEPG"
## [1] "Skipping CapillariaEPG, not enough positive samples."
## [1] "Skipping MiddEggEPG, not enough positive samples."
## [1] "Running Neg Binomial model for ProtostrongylideLarverLPG"
## [1] "Skipping DictyocaulusLPG, not enough positive samples."
TS1617.abund$summary[which(TS1617.abund$summary$covariates != "(Intercept)" & TS1617.abund$summary$p.value < 0.1),]
##                 resp_var                      covariates   estimate std.error
## 3  StrongylidetypeeggEPG            Adult_age_category.L -0.3246267 0.1858473
## 14          TrichurisEPG MunicipalityDensity_Mean2016_18 -3.5752370 2.1179319
##    statistic    p.value     p.adj
## 3  -1.746739 0.08068262 0.3560971
## 14 -1.688079 0.09139602 0.3560971

Add no. of positive samples to table

TS1617.abund$summary$n.pos <- sapply(TS1617.abund$summary$resp_var, function(x){
  sum(TS1617[,x] > 0, na.rm = T)
})

Fig. 4

TS1617.plot.detA <-
ggplot(subset(TS1617.abund.df, variable %in% c("StrongylidetypeeggEPG")),
       aes(Season, value))+
  geom_boxplot(aes(fill = Season), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Season), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c(Autumn="#E57200",Winter="#004F71"))+
  scale_x_discrete(labels = c(Autumn="Autumn\n2016",Winter="Winter\n2017"))+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Season", y = "Abundance (log EPG)", fill = "Season")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable, nrow = 1, 
             labeller = labeller(variable = c(StrongylidetypeeggEPG="Trichostrongylidae")))
TS1617.det.by.season <- dcast(
  TS1617.det.df,
  Season ~ variable, 
  value.var = "value",
  fun.aggregate = sum, fill = 0, drop = T, na.rm = T
)

## Calculate no. of individuals based on samples for which test was performed
TS1617.det.by.season$num_inds.MM <- sapply(seq(1,nrow(TS1617.det.by.season)), function(i){
  sn <- TS1617.det.by.season[i,"Season"]
  length(which(TS1617$Season == sn & TS1617$McMaster_performed == 1))
})

TS1617.det.by.season$num_inds.BA <- sapply(seq(1,nrow(TS1617.det.by.season)), function(i){
  sn <- TS1617.det.by.season[i,"Season"]
  length(which(TS1617$Season == sn & TS1617$Baermann_performed == 1))
})

TS1617.det.by.season.hm <- melt(TS1617.det.by.season, 
                             id.vars = c("Season","num_inds.MM","num_inds.BA"),
                             measure.vars = c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
                             variable.name = "parasite", value.name = "n.positive")

TS1617.det.by.season.hm$proportion <- ifelse(
  TS1617.det.by.season.hm$parasite %in% mcmaster.parasite.groups.01, 
  TS1617.det.by.season.hm$n.positive / TS1617.det.by.season.hm$num_inds.MM,
  TS1617.det.by.season.hm$n.positive / TS1617.det.by.season.hm$num_inds.BA
)

# add 95%CI to prevalence
TS1617.det.by.season.hm$CI95.lower <- sapply(seq(1,nrow(TS1617.det.by.season.hm)), function(i){
  p <- as.character(TS1617.det.by.season.hm[i,"parasite"])
  n.det <- TS1617.det.by.season.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TS1617.det.by.season.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TS1617.det.by.season.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[1])
})

TS1617.det.by.season.hm$CI95.upper <- sapply(seq(1,nrow(TS1617.det.by.season.hm)), function(i){
  p <- as.character(TS1617.det.by.season.hm[i,"parasite"])
  n.det <- TS1617.det.by.season.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TS1617.det.by.season.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TS1617.det.by.season.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[2])
})

TS1617.det.by.season.hm$CI95.lower.v2 <- ifelse(TS1617.det.by.season.hm$proportion == 0,NA,TS1617.det.by.season.hm$CI95.lower)
TS1617.det.by.season.hm$CI95.upper.v2 <- ifelse(TS1617.det.by.season.hm$proportion == 0,NA,TS1617.det.by.season.hm$CI95.upper)

TS1617.det.by.season.hm$variable <- factor(TS1617.det.by.season.hm$parasite,
                                        levels = levels(TS1617.det.df$variable))
TS1617.plot.detB <-
ggplot(
  subset(TS1617.det.by.season.hm, variable %in% c("Trichuris01")))+
  geom_errorbar(aes(x = Season, ymin = CI95.lower.v2, ymax = CI95.upper.v2),
                width = 0.5, linewidth = 0.75, colour = "black")+
  geom_point(aes(Season, proportion, fill = Season, size = num_inds.BA), shape = 21)+
  scale_fill_manual(values = c(Autumn="#E57200",Winter="#004F71"), )+
  scale_x_discrete(labels = c(Autumn="Autumn\n2016",Winter="Winter\n2017"))+
  labs(x = "Season", y = "Prevalence", size = "Total no.\nof samples")+
  guides(fill = "none")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = ggtext::element_markdown(size = 13),
        legend.position = "right",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable, nrow = 1, 
             labeller = labeller(variable = c(Trichuris01="*Trichuris*")))
plot_grid(TS1617.plot.detA, TS1617.plot.detB, 
          nrow = 1, align = "h", axis = "tb",
          rel_widths = c(0.75,1),
          labels = c("a","b"))

ggsave("figures/Fig4_AbundancePrevalence_by_Season.png",units = "in", dpi = 1200, width = 7.5, height = 4)
ggplot(subset(TS1617.abund.df, variable %in% c("StrongylidetypeeggEPG")),
       aes(Season, value))+
  geom_boxplot(aes(fill = Adult_age_category), alpha = 0.25, outlier.colour = NA)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#74C476","#006D2C"), labels = c(agegroup2="2-5 yr",agegroup3="6+ yr"))+
  scale_x_discrete(labels = c("Autumn"="Autumn (2016)","Winter"="Winter (2017)"))+
  scale_y_continuous(transform = "log10")+
  labs(x = "Season (year)", y = "Abundance (log EGP)", fill = "Age group")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, nrow = 1,
             labeller = labeller(variable = c(StrongylidetypeeggEPG="Trichostrongylidae eggs")))

ggplot(subset(TS1617.abund.df, variable %in% c("ProtostrongylideLarverLPG")),
       aes(Municipality, value))+
  geom_boxplot(aes(fill = Municipality), alpha = 0.25, outlier.colour = NA)+
  geom_point(aes(fill = Municipality), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  geom_signif(comparisons = list(c("Stjørdal","Meråker")), annotations = c("."),
              tip_length = 0.02)+
  scale_y_continuous(expand = expansion(mult = c(0, 0.15)))+
  labs(x = "Municipality", y = "Abundance", fill = "", title = "Autumn vs Winter (adult females)")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "none",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ variable, nrow = 1)

Richness

Number of parasite groups, excluding hatched strongylide (as already counted in Strongylide). Note there are two cases of ProtostrongylideLarver detection where E. alces or V. alces could not be specifically identified, therefore using Protostrongylide detection instead.

# also excluding mites because so few anyway, and we don't know if they are soil/food or host parasites
# two cases of ProtostrongylideLarver detection do NOT have E or V identified BUT E not found in this dataset, so can use ProtostrongylideLarver instead (as it is either unknown or V)
# table(TS1617[,c("EalcesLarvae01","ValcesLarvae01","ProtostrongylideLarver01")])

TS1617$num.of.parasite.groups <- rowSums(TS1617[,c("Eimeria01", "Strongylidetypeegg01", "Moniezia01", "NematodirusNematodirellaEgg01", 
                                               "Trichuris01", "Capillaria01", "Strongyloides01",
                                               "ProtostrongylideLarver01","DictyocaulusLarver01")], na.rm = T)

Using Poisson distribution, as richness is count data.

## MAIN
TS1617.richP <- glm(
  formula = num.of.parasite.groups ~ Season + Adult_age_category + MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab,
  data = TS1617,
  family = poisson(link = "log"),
  na.action = na.omit
)
summary(TS1617.richP)
## 
## Call:
## glm(formula = num.of.parasite.groups ~ Season + Adult_age_category + 
##     MunicipalityDensity_Mean2016_18 + Days.harvested.vs.lab, 
##     family = poisson(link = "log"), data = TS1617, na.action = na.omit)
## 
## Coefficients:
##                                  Estimate Std. Error z value Pr(>|z|)
## (Intercept)                      0.673520   0.420558   1.601    0.109
## SeasonWinter                     0.105147   0.245363   0.429    0.668
## Adult_age_category.L            -0.137635   0.167055  -0.824    0.410
## MunicipalityDensity_Mean2016_18 -0.805360   0.680837  -1.183    0.237
## Days.harvested.vs.lab           -0.008092   0.028569  -0.283    0.777
## 
## (Dispersion parameter for poisson family taken to be 1)
## 
##     Null deviance: 31.846  on 61  degrees of freedom
## Residual deviance: 29.208  on 57  degrees of freedom
## AIC: 168.03
## 
## Number of Fisher Scoring iterations: 5
performance::check_overdispersion(TS1617.richP)
## # Overdispersion test
## 
##        dispersion ratio =  0.472
##   Pearson's Chi-Squared = 26.892
##                 p-value =      1
## No overdispersion detected.
plot(allEffects(TS1617.richP))

Fig. S2c

TS1617.plot.richA <-
ggplot(TS1617, aes(Season, num.of.parasite.groups))+
  # geom_boxplot(aes(fill = Season), outlier.colour = NA, alpha = 0.25)+
  geom_violin(aes(fill = Season), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Season), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c(Autumn="#E57200",Winter="#004F71"))+
  scale_x_discrete(labels = c(Autumn="Autumn\n2016",Winter="Winter\n2017"))+
  scale_y_continuous(limits = c(0, round(max(c(TA16.sub$num.of.parasite.groups, TS1617$num.of.parasite.groups), na.rm = T)+1)))+
  labs(x = "Season", y = "No. of parasite groups", fill = "", title = "Autumn vs Winter\n(adult females)")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))
TS1617.plot.richA

ggplot(TS1617, aes(Season, num.of.parasite.groups))+
  geom_boxplot(aes(fill = Adult_age_category), alpha = 0.25, outlier.colour = NA)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c("#74C476","#006D2C"), labels = c(agegroup2="2-5 yr",agegroup3="6+ yr"))+
  scale_x_discrete(labels = c("Autumn"="Autumn (2016)","Winter"="Winter (2017)"))+
  labs(x = "Season (year)", y = "Richness", fill = "Age group")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))

ggplot(TS1617, aes(MunicipalityDensity_Mean2016_18, num.of.parasite.groups))+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  geom_point(fill = "gold", shape = 21, color = "black", size = 3)+
  labs(x = "Moose density (mean 2016-2018)", y = "Richness", title = "")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))
## `geom_smooth()` using formula = 'y ~ x'

ggplot(TS1617, aes(MunicipalityDensity_Mean2016_18, num.of.parasite.groups))+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  geom_point(aes(fill = Adult_age_category), shape = 21, color = "black", size = 3)+
  scale_fill_manual(values = c("#74C476","#006D2C"), labels = c(agegroup2="2-5 yr",agegroup3="6+ yr"))+
  labs(x = "Moose density (mean 2016-2018)", y = "Richness", fill = "Age group")+
  theme_classic()+
  theme(axis.text = element_text(color = "black", size = 12), legend.position = "top",
        plot.title = element_text(size = 13, hjust = 0.5),
        axis.title = element_text(size = 12), strip.text.x = element_text(size = 9.5),
        axis.text.x = element_text(angle = 0))+
  facet_wrap(~ Season + Adult_age_category, nrow = 1)
## `geom_smooth()` using formula = 'y ~ x'

TS1617$Municipality2 <- factor(
  TS1617$Municipality,
  levels = unique(TS1617[order(TS1617$MunicipalityDensity_Mean2016_18),"Municipality"]))


TA1617.plot.richA <-
ggplot(TS1617, aes(MunicipalityDensity_Mean2016_18, num.of.parasite.groups))+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  # geom_point(fill = "gold", shape = 21, color = "black", size = 3)+
  geom_point(aes(fill = Municipality2), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.height = 0.1, jitter.width = 0.05))+
  scale_y_continuous(limits = c(0,5))+
  scale_x_continuous(limits = c(0.2,0.8))+
  labs(x = "Moose density (mean 2016-2018)", y = "No. of parasite groups", fill = "")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))

TA1617.plot.richB <-
ggplot(TS1617, aes(Municipality2, num.of.parasite.groups))+
  geom_violin(aes(fill = Municipality2), alpha = 0.25, draw_quantiles = 0.5)+
  geom_point(aes(fill = Municipality2), shape = 21, color = "black", size = 3, 
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_y_continuous(limits = c(0,5))+
  labs(x = "Municipality", y = "No. of parasite groups", fill = "", title = "Richness by municipality (adult females)")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))
plot_grid(TA1617.plot.richB, TA1617.plot.richA,
          align = "hv", axis = "tblr",
          nrow = 2, labels = c("a","b"))

Table 4

Stat tables

# main table
TS1617.richP.summary <- summary(TS1617.richP)
colnames(TS1617.richP.summary$coefficients) <- c("estimate","std.error","statistic","p.value")
TS1617.richP.summary <- data.frame(
  resp_var="num.of.parasite.groups",
  covariates=row.names(TS1617.richP.summary$coefficients),
  as.data.frame(TS1617.richP.summary$coefficients),
  p.adj=NA,
  row.names = NULL
)

TS1617.prev$summary[which(TS1617.prev$summary$covariates != "(Intercept)" & TS1617.prev$summary$p.value < 0.1),]
##               resp_var           covariates  estimate std.error statistic
## 3 Strongylidetypeegg01 Adult_age_category.L -1.519379 0.8426482   -1.8031
##      p.value     p.adj n.pos
## 3 0.07137245 0.5976107    57
TS1617.abund$summary[which(TS1617.abund$summary$covariates != "(Intercept)" & TS1617.abund$summary$p.value < 0.1),]
##                 resp_var                      covariates   estimate std.error
## 3  StrongylidetypeeggEPG            Adult_age_category.L -0.3246267 0.1858473
## 14          TrichurisEPG MunicipalityDensity_Mean2016_18 -3.5752370 2.1179319
##    statistic    p.value     p.adj n.pos
## 3  -1.746739 0.08068262 0.3560971    53
## 14 -1.688079 0.09139602 0.3560971    10
TS1617.richP.summary[which(TS1617.richP.summary$covariates != "(Intercept)" & TS1617.richP.summary$p.value < 0.1),]
## [1] resp_var   covariates estimate   std.error  statistic  p.value    p.adj     
## <0 rows> (or 0-length row.names)
stats.tab2 <- rbind.data.frame(
  TS1617.prev$summary[which(TS1617.prev$summary$resp_var %in% c("Strongylidetypeegg01")),],
  TS1617.abund$summary[which(TS1617.abund$summary$resp_var %in% c("StrongylidetypeeggEPG")),],
  data.frame(TS1617.richP.summary, n.pos=length(which(!is.na(TS1617$num.of.parasite.groups))))
)

stats.tab2$coeff_print <- paste(round(stats.tab2$estimate, digits = 3),"\u00B1", round(stats.tab2$std.error, digits = 3))
stats.tab2$pval_print <- ifelse(stats.tab2$p.value >= 0.001, round(stats.tab2$p.value, digits = 3), "<0.001") 
stats.tab2$padj_print <- ifelse(stats.tab2$p.adj >= 0.001, round(stats.tab2$p.adj, digits = 3), "<0.001") 

stats.tab2[,c("resp_var","n.pos","covariates","coeff_print","pval_print","padj_print")]
##                  resp_var n.pos                      covariates    coeff_print
## 1    Strongylidetypeegg01    57                     (Intercept)   1.805 ± 2.71
## 2    Strongylidetypeegg01    57                    SeasonWinter -3.202 ± 2.228
## 3    Strongylidetypeegg01    57            Adult_age_category.L -1.519 ± 0.843
## 4    Strongylidetypeegg01    57 MunicipalityDensity_Mean2016_18 -2.777 ± 4.071
## 5    Strongylidetypeegg01    57           Days.harvested.vs.lab  0.591 ± 0.424
## 6   StrongylidetypeeggEPG    53                     (Intercept)  5.168 ± 0.486
## 7   StrongylidetypeeggEPG    53                    SeasonWinter -0.439 ± 0.302
## 8   StrongylidetypeeggEPG    53            Adult_age_category.L -0.325 ± 0.186
## 9   StrongylidetypeeggEPG    53 MunicipalityDensity_Mean2016_18 -0.763 ± 0.736
## 10  StrongylidetypeeggEPG    53           Days.harvested.vs.lab -0.028 ± 0.033
## 11 num.of.parasite.groups    62                     (Intercept)  0.674 ± 0.421
## 12 num.of.parasite.groups    62                    SeasonWinter  0.105 ± 0.245
## 13 num.of.parasite.groups    62            Adult_age_category.L -0.138 ± 0.167
## 14 num.of.parasite.groups    62 MunicipalityDensity_Mean2016_18 -0.805 ± 0.681
## 15 num.of.parasite.groups    62           Days.harvested.vs.lab -0.008 ± 0.029
##    pval_print padj_print
## 1       0.505      0.919
## 2       0.151      0.598
## 3       0.071      0.598
## 4       0.495      0.919
## 5       0.163      0.598
## 6      <0.001     <0.001
## 7       0.146      0.418
## 8       0.081      0.356
## 9         0.3      0.501
## 10      0.398      0.612
## 11      0.109       <NA>
## 12      0.668       <NA>
## 13       0.41       <NA>
## 14      0.237       <NA>
## 15      0.777       <NA>
write.table(stats.tab2[,c("resp_var","n.pos","covariates","coeff_print","pval_print","padj_print")],
            "figures/table_statistic_models_seasonal.txt",
            row.names = F, quote = F, sep = "\t", fileEncoding = "latin1")

Other material for paper

Table 1

Combine summary statistics into one table & format

ms.tab.summary <- rbind.data.frame(ms.tab1, ms.tab2)

ms.tab.summary$Sex <- gsub("Male", "Male", ms.tab.summary$Sex)
ms.tab.summary$Sex <- gsub("Female", "Female", ms.tab.summary$Sex)

ms.tab.summary$Adult_age_category <- gsub("agegroup1", "1 yr", ms.tab.summary$Adult_age_category)
ms.tab.summary$Adult_age_category <- gsub("agegroup2", "2-5 yr", ms.tab.summary$Adult_age_category)
ms.tab.summary$Adult_age_category <- gsub("agegroup3", "6+ yr", ms.tab.summary$Adult_age_category)

write.table(ms.tab.summary[,c("Season","Sex","Adult_age_category","Carcass_mass_category","count",
                              grep("Median",names(ms.tab.summary), value = T))],
            "figures/table_sampling_summary.txt",
            row.names = F, quote = F, sep = "\t", fileEncoding = "latin1")

Table 2

Combine heatmaps into one figure.

prev.fig1.header.df <- data.frame(
  Season="Autumn",
  TA16.det.by.group.hm[!duplicated(TA16.det.by.group.hm[,c("Sex","Adult_age_category","num_inds.MM","num_inds.BA","group")]),c("Sex","Adult_age_category","num_inds.MM","num_inds.BA","group")]
)
prev.fig1.header.df$Adult_age_category <- ifelse(prev.fig1.header.df$Adult_age_category == "agegroup1","1 yr",
                                              ifelse(prev.fig1.header.df$Adult_age_category == "agegroup2", "2-5 yr", "6+ yr"))

prev.fig1.header.df <- melt(prev.fig1.header.df, 
                         id.vars = "group", measure.vars = c("Season","Sex","Adult_age_category","num_inds.MM","num_inds.BA"))
## Warning: attributes are not identical across measure variables; they will be
## dropped
prev.fig1.header.df$group <- factor(as.character(prev.fig1.header.df$group),
                                     levels = c("agegroup1_Male", "agegroup2_Male", "agegroup3_Male",
                                                "agegroup1_Female", "agegroup2_Female", "agegroup3_Female"))
prev.fig1.header.df$variable <- as.character(prev.fig1.header.df$variable)
prev.fig1.header.df[which(prev.fig1.header.df$variable == "Adult_age_category"),"variable"] <- "Age group"
prev.fig1.header.df[which(prev.fig1.header.df$variable == "num_inds.MM"),"variable"] <- "n (McMaster)"
prev.fig1.header.df[which(prev.fig1.header.df$variable == "num_inds.BA"),"variable"] <- "n (Baermann)"
prev.fig1.header.df$variable <- factor(prev.fig1.header.df$variable,
                                    levels = rev(c("Season","Sex","Age group","n (McMaster)","n (Baermann)")))

prev.fig1.header <-
ggplot(prev.fig1.header.df, aes(group, variable))+
  geom_tile(fill = "white", colour = "grey50", linewidth = 0.5)+
  geom_text(aes(label=value))+
  theme_bw()+
  guides(fill = guide_colorbar(barwidth = 10, barheight = 1))+
  theme(axis.title = element_blank(),
        axis.text.y = ggtext::element_markdown(size = 12, colour = "black", hjust = 1),
        axis.text.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks = element_blank()
        )
prev.fig2.header.df <- data.frame(
  Sex="Female",
  TS1617.det.by.group.hm[!duplicated(TS1617.det.by.group.hm[,c("Season","Adult_age_category","num_inds.MM","num_inds.BA","group")]),c("Season","Adult_age_category","num_inds.MM","num_inds.BA","group")]
)
prev.fig2.header.df$Adult_age_category <- ifelse(prev.fig2.header.df$Adult_age_category == "agegroup1","1 yr",
                                              ifelse(prev.fig2.header.df$Adult_age_category == "agegroup2", "2-5 yr", "6+ yr"))

prev.fig2.header.df <- melt(prev.fig2.header.df, 
                         id.vars = "group", measure.vars = c("Season","Sex","Adult_age_category","num_inds.MM","num_inds.BA"))
## Warning: attributes are not identical across measure variables; they will be
## dropped
prev.fig2.header.df$variable <- as.character(prev.fig2.header.df$variable)
prev.fig2.header.df[which(prev.fig2.header.df$variable == "Adult_age_category"),"variable"] <- "Age group"
prev.fig2.header.df[which(prev.fig2.header.df$variable == "num_inds.MM"),"variable"] <- "n (McMaster)"
prev.fig2.header.df[which(prev.fig2.header.df$variable == "num_inds.BA"),"variable"] <- "n (Baermann)"
prev.fig2.header.df$variable <- factor(prev.fig2.header.df$variable,
                                    levels = rev(c("Season","Sex","Age group","n (McMaster)","n (Baermann)")))

prev.fig2.header <-
ggplot(prev.fig2.header.df, aes(group, variable))+
  geom_tile(fill = "white", colour = "grey50", linewidth = 0.5)+
  geom_text(aes(label=value))+
  theme_bw()+
  guides(fill = guide_colorbar(barwidth = 10, barheight = 1))+
  theme(axis.title = element_blank(),
        axis.text.y = ggtext::element_markdown(size = 12, colour = "black", hjust = 1),
        axis.text.x = element_blank(),
        panel.border = element_blank(),
        axis.ticks = element_blank()
        )
plot_grid(
  prev.fig1.header, 
  prev.fig2.header+
    theme(axis.text.y = element_blank()), 
  prev.fig1+
    theme(axis.text.x = element_blank()),
  prev.fig2+
    theme(axis.text.x = element_blank()),
  align = "hv", axis = "trbl",
  nrow = 2, ncol = 2, 
  rel_heights = c(0.5,1,0.5,1),
  rel_widths = c(1,1,0.47,0.47),
  labels = c("a","b")
)

# and then use Inkscape to remove some of the white space?
# ggsave("figures/PrevalenceHeatmap_by_SeasonSexAge_250228.png",units = "in", dpi = 1200, width = 14, height = 7)
# ggtext doesn't render correctly with ggsave, use dev instead
png("figures/Table2_Prevalence_by_SeasonSexAge.png", units = "in", res = 1200, width = 12, height = 11)
plot_grid(
  prev.fig1.header, 
  prev.fig2.header+
    theme(axis.text.y = element_blank()), 
  prev.fig1+
    theme(axis.text.x = element_blank()),
  prev.fig2+
    theme(axis.text.x = element_blank()),
  align = "hv", axis = "trbl",
  nrow = 2, ncol = 2, 
  rel_heights = c(0.5,1,0.5,1),
  rel_widths = c(1,1,0.47,0.47),
  labels = c("a","b")
)
dev.off()
## png 
##   2

Fig. S2

plot_grid(TA16.plot.richA, TA16.plot.richB, TS1617.plot.richA,
          align = "hv", axis = "tblr",
          nrow = 1, labels = c("a","b","c"))
## `geom_smooth()` using formula = 'y ~ x'

ggsave("figures/FigS2_Richness_by_AgeMassCatSeason.png",units = "in", dpi = 1200, width = 10, height = 4)

Fig. S4

Weak associations with sex

TA16.det.by.Sex <- dcast(
  TA16.det.df,
  Adult_age_category + Sex ~ variable, 
  value.var = "value",
  fun.aggregate = sum, fill = 0, drop = T, na.rm = T
)

## Calculate no. of individuals based on samples for which test was performed
TA16.det.by.Sex$num_inds.MM <- sapply(seq(1,nrow(TA16.det.by.Sex)), function(i){
  age <- TA16.det.by.Sex[i,"Adult_age_category"]
  sex <- TA16.det.by.Sex[i,"Sex"]
  length(which(TA16.sub$Adult_age_category == age & TA16.sub$Sex == sex & TA16.sub$McMaster_performed == 1))
})

TA16.det.by.Sex$num_inds.BA <- sapply(seq(1,nrow(TA16.det.by.Sex)), function(i){
  age <- TA16.det.by.Sex[i,"Adult_age_category"]
  sex <- TA16.det.by.Sex[i,"Sex"]
  length(which(TA16.sub$Adult_age_category == age & TA16.sub$Sex == sex & TA16.sub$Baermann_performed == 1))
})

TA16.det.by.Sex.hm <- melt(TA16.det.by.Sex, 
                             id.vars = c("Adult_age_category","Sex","num_inds.MM","num_inds.BA"),
                             measure.vars = c(mcmaster.parasite.groups.01,baermann.parasite.groups.01),
                             variable.name = "parasite", value.name = "n.positive")

TA16.det.by.Sex.hm$proportion <- ifelse(
  TA16.det.by.Sex.hm$parasite %in% mcmaster.parasite.groups.01, 
  TA16.det.by.Sex.hm$n.positive / TA16.det.by.Sex.hm$num_inds.MM,
  TA16.det.by.Sex.hm$n.positive / TA16.det.by.Sex.hm$num_inds.BA
)

# add 95%CI to prevalence
TA16.det.by.Sex.hm$CI95.lower <- sapply(seq(1,nrow(TA16.det.by.Sex.hm)), function(i){
  p <- as.character(TA16.det.by.Sex.hm[i,"parasite"])
  n.det <- TA16.det.by.Sex.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.Sex.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.Sex.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[1])
})

TA16.det.by.Sex.hm$CI95.upper <- sapply(seq(1,nrow(TA16.det.by.Sex.hm)), function(i){
  p <- as.character(TA16.det.by.Sex.hm[i,"parasite"])
  n.det <- TA16.det.by.Sex.hm[i,"n.positive"]
  if(p %in% mcmaster.parasite.groups.01){
    n.tot <- TA16.det.by.Sex.hm[i,"num_inds.MM"]
  } else if(p %in% baermann.parasite.groups.01){
    n.tot <- TA16.det.by.Sex.hm[i,"num_inds.BA"]
  } else {
    return(NA)
  }
  t <- binom.test(n.det, n.tot, conf.level = 0.95)
  return(t$conf.int[2])
})

TA16.det.by.Sex.hm$CI95.lower.v2 <- ifelse(TA16.det.by.Sex.hm$proportion == 0,NA,TA16.det.by.Sex.hm$CI95.lower)
TA16.det.by.Sex.hm$CI95.upper.v2 <- ifelse(TA16.det.by.Sex.hm$proportion == 0,NA,TA16.det.by.Sex.hm$CI95.upper)

TA16.det.by.Sex.hm$variable <- factor(TA16.det.by.Sex.hm$parasite,
                                        levels = levels(TA16.det.df$variable))
TA16.plot.sexA <-
ggplot(
  subset(TA16.det.by.Sex.hm, variable %in% c("ProtostrongylideLarver01","EalcesLarvae01","ValcesLarvae01") & Adult_age_category == "agegroup1"))+
  geom_errorbar(aes(x = Sex, ymin = CI95.lower.v2, ymax = CI95.upper.v2),
                width = 0.5, linewidth = 0.75, colour = "black")+
  geom_point(aes(Sex, proportion, fill = Sex, size = num_inds.BA), shape = 21)+
  scale_fill_manual(values = c(Male="#E41A1C",Female="#377EB8"), labels = c(Male="Male", Female="Female"), guide = "none")+
  scale_size(limits = c(10,50), range = c(1,4))+
  labs(x = "Sex", y = "Prevalence", size = "Total no.\nof samples", fill = "Sex")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = ggtext::element_markdown(size = 13),
        legend.position = "right", legend.box = "horizontal",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable + Adult_age_category, nrow = 1, 
             labeller = labeller(variable = c(ProtostrongylideLarver01="Protostrongylidae", EalcesLarvae01="*E. alces*", ValcesLarvae01="*V. alces*"),
                                 Adult_age_category = c(agegroup1 = "1 yr")))
TA16.plot.sexB <-
ggplot(subset(TA16.abund.df, variable %in% c("StrongylidetypeeggEPG")),
       aes(Sex, value))+
  geom_boxplot(aes(fill = Sex), outlier.colour = NA, alpha = 0.25)+
  geom_point(aes(fill = Sex), shape = 21, color = "black", size = 3,
             position = position_jitterdodge(jitter.width = 0.2))+
  scale_fill_manual(values = c(Male="#E41A1C",Female="#377EB8"), labels = c(Male="Male", Female="Female"))+
  scale_y_continuous(transform = "log10", expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Sex", y = "Abundance (log EPG)")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ variable + Adult_age_category, nrow = 1, 
             labeller = labeller(variable = c(StrongylidetypeeggEPG="Trichostrongylidae"),
                                 Adult_age_category = c(agegroup1="1 yr", agegroup2="2-5 yr", agegroup3="6+ yr")))
plot_grid(TA16.plot.sexA, TA16.plot.sexB,
          align = "hv", axis = "tblr", nrow = 2,
          labels = c("a","b"))

ggsave("figures/FigS4_Abundance_by_Sex.png",units = "in", dpi = 1200, width = 9, height = 6.5)

Fig. S6

Harvest date vs postage vs date received in the lab

# autumn
summary(dat[which(dat$Season == "Autumn"),"Days.harvested.vs.posted"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   2.000   2.000   3.269   4.000   8.000
summary(dat[which(dat$Season == "Autumn"),"Days.harvested.vs.lab"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   2.000   3.000   5.000   6.177   8.000  17.000
summary(dat[which(dat$Season == "Autumn"),"Days.posted.vs.lab"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##   1.000   1.000   1.000   2.908   3.000  13.000
# winter
summary(dat[which(dat$Season == "Winter"),"Days.harvested.vs.posted"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    6.00    7.00    8.00    8.05    9.00   12.00
summary(dat[which(dat$Season == "Winter"),"Days.harvested.vs.lab"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    7.00    8.00    9.00    9.05   10.00   13.00
summary(dat[which(dat$Season == "Winter"),"Days.posted.vs.lab"])
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##       1       1       1       1       1       1
dat.plot.daysA <-
ggplot(subset(dat, !is.na(StrongylidetypeeggEPG)), aes(Days.harvested.vs.lab, StrongylidetypeeggEPG))+
  geom_point(aes(fill = Season), shape = 21, color = "black", size = 3)+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  scale_fill_manual(values = c(Autumn="#E57200",Winter="#004F71"))+
  scale_y_continuous(expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Days in transit", y = "Trichostrongylidae\nabundance (EPG)")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ Season, nrow = 1)

dat.plot.daysB <-
ggplot(subset(dat, !is.na(ProtostrongylideLarverLPG)), aes(Days.harvested.vs.lab, ProtostrongylideLarverLPG))+
  geom_point(aes(fill = Season), shape = 21, color = "black", size = 3)+
  geom_smooth(method=lm , color="black", fill="grey70", se=TRUE)+
  scale_fill_manual(values = c(Autumn="#E57200",Winter="#004F71"))+
  scale_y_continuous(expand = expansion(mult = c(0, 0.1)))+
  labs(x = "Days in transit", y = "Protostrongylidae\nabundance (LPG)")+
  theme_classic()+
  theme(plot.title = element_text(size = 13, hjust = 0.5),
        axis.text = element_text(color = "black", size = 12), 
        axis.title = element_text(size = 13),
        axis.text.x = element_text(angle = 0),
        strip.text.x = element_text(size = 13),
        legend.position = "none",
        legend.text = element_text(color = "black", size = 12),
        legend.title = element_text(size = 13))+
  facet_wrap(~ Season, nrow = 1)
plot_grid(
  dat.plot.daysA, dat.plot.daysB,
  align = "hv", axis = "tblr",
  nrow = 2, labels = c("a","b")
)

ggsave("figures/FigS6_Abundance_by_DaysInTransit.png",units = "in", dpi = 1200, height = 7, width = 8)

Table S2

AIC model selection results

aic.res <- rbind.data.frame(
  TA16.prev.aic,
  TA16.abund.aic,
  data.frame(resp_var="num.of.parasite.groups",TA16.richP.aic)
)

names(aic.res) <- c("parasite_group","degrees_of_freedom","AIC")

aic.res$model <- gsub("\\$.*","", gsub(".*\\.r","M",row.names(aic.res)))

aic.res$model_formula <- sapply(row.names(aic.res), function(x){
  if(grepl("r1",x)){
    "~ Exact_age + Carcass_mass_kg + Sex + MunicipalityDensity_Mean2016_18 + Days.in.transit"
  } else if(grepl("r2",x)){
    "~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.in.transit"
  } else if(grepl("r3",x)){
    "~ Exact_age + Carcass_mass_category + Sex + MunicipalityDensity_2016 + Days.in.transit"
  } else if(grepl("r4",x)){
    "~ Exact_age + Carcass_mass_category + Sex + Municipality + Days.in.transit"
  } else if(grepl("r5",x)){
    "~ Exact_age + Carcass_mass_category * Sex + MunicipalityDensity_Mean2016_18 + Days.in.transit"
  } else if(grepl("r6",x)){
    "~ Exact_age * Carcass_mass_category + Sex + MunicipalityDensity_Mean2016_18 + Days.in.transit"
  } else {
    NA
  }
})

write.table(aic.res[,c("model","model_formula","parasite_group","degrees_of_freedom","AIC")],
            "figures/supp_table_AIC_comparisons_autumn.txt",
            row.names = F, quote = F, sep = "\t", fileEncoding = "latin1")

Table S3

Autumn - Stats table for all other models

# all supp models (+ parasites not included in main models)
TA16.rich.supp <- rbind.data.frame(
  data.frame(model="M2", format_rich_summary(TA16.richP.r2), n.pos=length(which(!is.na(TA16.sub$num.of.parasite.groups)))),
  data.frame(model="M3", format_rich_summary(TA16.richP.r3), n.pos=length(which(!is.na(TA16.sub$num.of.parasite.groups)))),
  data.frame(model="M4", format_rich_summary(TA16.richP.r4), n.pos=length(which(!is.na(TA16.sub$num.of.parasite.groups)))),
  data.frame(model="M5", format_rich_summary(TA16.richP.r5), n.pos=length(which(!is.na(TA16.sub$num.of.parasite.groups)))),
  data.frame(model="M6", format_rich_summary(TA16.richP.r6), n.pos=length(which(!is.na(TA16.sub$num.of.parasite.groups))))
)

TA16.prev.supp <- rbind.data.frame(
  data.frame(model="M2", TA16.prev.r2$summary[which(!TA16.prev.r2$summary$resp_var %in% c("ProtostrongylideLarver01","EalcesLarvae01","ValcesLarvae01")),]),
  data.frame(model="M1", TA16.prev.r1$summary),
  data.frame(model="M3", TA16.prev.r3$summary),
  data.frame(model="M4", TA16.prev.r4$summary),
  data.frame(model="M4.posthoc", format_posthoc_summary(TA16.prev.r4.posthoc.Trichuris, "Trichuris01"), n.pos=""),
  data.frame(model="M4.posthoc", format_posthoc_summary(TA16.prev.r4.posthoc.Valces, "ValcesLarvae01"), n.pos=""),
  data.frame(model="M5", TA16.prev.r5$summary),
  data.frame(model="M6", TA16.prev.r6$summary)
)

TA16.abund.supp <- rbind.data.frame(
  data.frame(model="M1", TA16.abund.r1$summary),
  data.frame(model="M2", TA16.abund.r2$summary),
  data.frame(model="M3", TA16.abund.r3$summary),
  data.frame(model="M4", TA16.abund.r4$summary), # include all models, as non-posthoc aren't in the main text table,
  data.frame(model="M4.posthoc", TA16.abund.r4.posthoc.Strongylide.summary, n.pos=""),
  data.frame(model="M4.posthoc", TA16.abund.r4.posthoc.Protostrongylide.summary, n.pos=""),
  data.frame(model="M4.posthoc", format_posthoc_summary(TA16.abund.r4.posthoc.Trichuris, "TrichurisEPG"), n.pos=""),
  data.frame(model="M5", TA16.abund.r5$summary),
  data.frame(model="M6", TA16.abund.r6$summary)
)
supp.stats.tab1 <- rbind.data.frame(
  TA16.prev.supp,
  TA16.abund.supp,
  TA16.rich.supp
)

supp.stats.tab1$coeff_print <- paste(round(supp.stats.tab1$estimate, digits = 3),"\u00B1", round(supp.stats.tab1$std.error, digits = 3))
supp.stats.tab1$pval_print <- ifelse(supp.stats.tab1$p.value >= 0.001, round(supp.stats.tab1$p.value, digits = 3), "<0.001") 
supp.stats.tab1$padj_print <- ifelse(supp.stats.tab1$p.adj >= 0.001, round(supp.stats.tab1$p.adj, digits = 3), "<0.001") 
supp.stats.tab1$sig_print <- ifelse(supp.stats.tab1$p.adj > 0.1,"",
                                    ifelse(supp.stats.tab1$p.adj > 0.05,".",
                                           ifelse(supp.stats.tab1$p.adj > 0.01,"*",
                                                  ifelse(supp.stats.tab1$p.adj > 0.001,"**","***"))))
supp.stats.tab1[is.na(supp.stats.tab1$sig_print),"sig_print"] <- ifelse(supp.stats.tab1[is.na(supp.stats.tab1$sig_print),"p.value"] > 0.1,"",
                                                                        ifelse(supp.stats.tab1[is.na(supp.stats.tab1$sig_print),"p.value"] > 0.05,".",
                                                                               ifelse(supp.stats.tab1[is.na(supp.stats.tab1$sig_print),"p.value"] > 0.01,"*",
                                                                                      ifelse(supp.stats.tab1[is.na(supp.stats.tab1$sig_print),"p.value"] > 0.001,"**","***"))))
supp.stats.tab1[which(supp.stats.tab1$covariates == "(Intercept)"),"sig_print"] <- ""

# format for direct inclusion in supp
resp_var.2.name <- c("Trichostrongylidae spp. detection", "Nematodirinae egg detection", 
                     "Trichuris egg detection", "Strongyloides egg detection", 
                     "Protostrongylidae larvae detection", "E. alces larvae detection", 
                     "V. alces larvae detection", "Nematodirinae egg abundance", "Trichuris egg abundance", 
                     "Trichostrongylidae egg abundance", 
                     "Protostrongylidae larvae abundance", "Richness (no. of parasite groups)"
)
names(resp_var.2.name) <- c("Strongylidetypeegg01", "NematodirusNematodirellaEgg01", "Trichuris01", 
                            "Strongyloides01", "ProtostrongylideLarver01", "EalcesLarvae01", 
                            "ValcesLarvae01", "NematodirussppEPG", "TrichurisEPG", 
                            "StrongylidetypeeggEPG",
                            "ProtostrongylideLarverLPG", "num.of.parasite.groups"
)
supp.stats.tab1$parasite_group <- sapply(supp.stats.tab1$resp_var, function(x){
  as.character(resp_var.2.name[x])
})

covar.2.name <- c("(Intercept)", "Exact age", "Carcass mass category", "Sex", 
                  "Mean moose density", "Days in transit", "Carcass mass (cont.)", 
                  "Moose density (2016)", "Municipality: Meråker - Malvik", "Municipality: Selbu - Malvik", 
                  "Municipality: Stjørdal - Malvik", "Municipality: Tydal - Malvik", "Municipality: Meråker - Malvik", 
                  "Municipality: Selbu - Malvik", "Municipality: Stjørdal - Malvik", "Municipality: Tydal - Malvik", "Municipality: Selbu - Meråker", 
                  "Municipality: Stjørdal - Meråker", "Municipality: Tydal - Meråker", "Municipality: Stjørdal - Selbu", 
                  "Municipality: Tydal - Selbu", "Municipality: Tydal - Stjørdal", 
                  "Carcass mass category:Sex", "Carcass mass category:Exact age" 
)

names(covar.2.name) <- c("(Intercept)", "Exact_age", "Carcass_mass_category.L", "SexFemale", 
                         "MunicipalityDensity_Mean2016_18", "Days.harvested.vs.lab", "Carcass_mass_kg", 
                         "MunicipalityDensity_2016", "MunicipalityMeråker", "MunicipalitySelbu", 
                         "MunicipalityStjørdal", "MunicipalityTydal", "Meråker - Malvik", 
                         "Selbu - Malvik", "Stjørdal - Malvik", "Tydal - Malvik", "Selbu - Meråker", 
                         "Stjørdal - Meråker", "Tydal - Meråker", "Stjørdal - Selbu", 
                         "Tydal - Selbu", "Tydal - Stjørdal", 
                         "Carcass_mass_category.L:SexFemale", "Exact_age:Carcass_mass_category.L"
)

supp.stats.tab1$covariates_print <- sapply(supp.stats.tab1$covariates, function(x){
  as.character(covar.2.name[x])
})

head(supp.stats.tab1[,c("parasite_group","n.pos","covariates_print","coeff_print","pval_print","padj_print","sig_print")])
##                      parasite_group n.pos      covariates_print
## 1 Trichostrongylidae spp. detection   115           (Intercept)
## 2 Trichostrongylidae spp. detection   115             Exact age
## 3 Trichostrongylidae spp. detection   115 Carcass mass category
## 4 Trichostrongylidae spp. detection   115                   Sex
## 5 Trichostrongylidae spp. detection   115    Mean moose density
## 6 Trichostrongylidae spp. detection   115       Days in transit
##         coeff_print pval_print padj_print sig_print
## 1 11.459 ± 1671.036      0.995      0.996          
## 2    -0.088 ± 0.176      0.618      0.838          
## 3 11.903 ± 2363.196      0.996      0.996          
## 4      0.19 ± 1.611      0.906      0.996          
## 5    -1.345 ± 6.292      0.831      0.996          
## 6     0.311 ± 0.434      0.474      0.701
tail(supp.stats.tab1[,c("parasite_group","n.pos","covariates_print","coeff_print","pval_print","padj_print","sig_print")])
##                        parasite_group n.pos                covariates_print
## 513 Richness (no. of parasite groups)   117                       Exact age
## 514 Richness (no. of parasite groups)   117           Carcass mass category
## 515 Richness (no. of parasite groups)   117                             Sex
## 516 Richness (no. of parasite groups)   117              Mean moose density
## 517 Richness (no. of parasite groups)   117                 Days in transit
## 518 Richness (no. of parasite groups)   117 Carcass mass category:Exact age
##        coeff_print pval_print padj_print sig_print
## 513 -0.078 ± 0.034      0.022       <NA>         *
## 514  0.059 ± 0.138      0.669       <NA>          
## 515 -0.109 ± 0.129      0.399       <NA>          
## 516  -0.25 ± 0.525      0.633       <NA>          
## 517  0.017 ± 0.014       0.23       <NA>          
## 518  -0.01 ± 0.047      0.836       <NA>
write.table(supp.stats.tab1[,c("parasite_group","model","n.pos","covariates_print","coeff_print","pval_print","padj_print","sig_print")],
            "figures/supp_table_all_statistic_models_autumn.txt",
            row.names = F, quote = F, sep = "\t", fileEncoding = "latin1")

Table S4

Autumn vs winter - Stats table for all other models

# parasites not included in main model
TS1617.prev.supp <- rbind.data.frame(
  data.frame(model="", TS1617.prev$summary[which(!TS1617.prev$summary$resp_var %in% c("Strongylidetypeegg01")),])
)

TS1617.abund.supp <- rbind.data.frame(
  data.frame(model="", TS1617.abund$summary[which(!TS1617.abund$summary$resp_var %in% c("StrongylidetypeeggEPG")),])
)
supp.stats.tab2 <- rbind.data.frame(
  TS1617.prev.supp,
  TS1617.abund.supp
)

supp.stats.tab2$coeff_print <- paste(round(supp.stats.tab2$estimate, digits = 3),"\u00B1", round(supp.stats.tab2$std.error, digits = 3))
supp.stats.tab2$pval_print <- ifelse(supp.stats.tab2$p.value >= 0.001, round(supp.stats.tab2$p.value, digits = 3), "<0.001") 
supp.stats.tab2$padj_print <- ifelse(supp.stats.tab2$p.adj >= 0.001, round(supp.stats.tab2$p.adj, digits = 3), "<0.001") 
supp.stats.tab2$sig_print <- ifelse(supp.stats.tab2$p.adj > 0.1,"",
                                    ifelse(supp.stats.tab2$p.adj > 0.05,".",
                                           ifelse(supp.stats.tab2$p.adj > 0.01,"*",
                                                  ifelse(supp.stats.tab2$p.adj > 0.001,"**","***"))))
supp.stats.tab2[is.na(supp.stats.tab2$sig_print),"sig_print"] <- ifelse(supp.stats.tab2[is.na(supp.stats.tab2$sig_print),"p.value"] > 0.1,"",
                                                                        ifelse(supp.stats.tab2[is.na(supp.stats.tab2$sig_print),"p.value"] > 0.05,".",
                                                                               ifelse(supp.stats.tab2[is.na(supp.stats.tab2$sig_print),"p.value"] > 0.01,"*",
                                                                                      ifelse(supp.stats.tab2[is.na(supp.stats.tab2$sig_print),"p.value"] > 0.001,"**","***"))))
supp.stats.tab2[which(supp.stats.tab2$covariates == "(Intercept)"),"sig_print"] <- ""

# format for direct inclusion in supp
supp.stats.tab2$parasite_group <- sapply(supp.stats.tab2$resp_var, function(x){
  as.character(resp_var.2.name[x])
})

covar.2.name <- append(covar.2.name, c(SeasonWinter="Season",
                                       Adult_age_category.L="Age category (2-5 vs 6+ years)",
                                       MunicipalityTrondheim="Municipality: Trondheim - Malvik"))
supp.stats.tab2$covariates_print <- sapply(supp.stats.tab2$covariates, function(x){
  as.character(covar.2.name[x])
})

head(supp.stats.tab2[,c("parasite_group","n.pos","covariates_print","coeff_print","pval_print","padj_print","sig_print")])
##                 parasite_group n.pos               covariates_print
## 6  Nematodirinae egg detection     6                    (Intercept)
## 7  Nematodirinae egg detection     6                         Season
## 8  Nematodirinae egg detection     6 Age category (2-5 vs 6+ years)
## 9  Nematodirinae egg detection     6             Mean moose density
## 10 Nematodirinae egg detection     6                Days in transit
## 11     Trichuris egg detection    10                    (Intercept)
##       coeff_print pval_print padj_print sig_print
## 6  -0.648 ± 2.336      0.781      0.993          
## 7   2.618 ± 2.328      0.261      0.598          
## 8  -0.934 ± 0.818      0.254      0.598          
## 9   0.833 ± 2.955      0.778      0.993          
## 10 -0.565 ± 0.435      0.194      0.598          
## 11 -0.055 ± 1.375      0.968      0.994
tail(supp.stats.tab2[,c("parasite_group","n.pos","covariates_print","coeff_print","pval_print","padj_print","sig_print")])
##                         parasite_group n.pos               covariates_print
## 151            Trichuris egg abundance    10                Days in transit
## 161 Protostrongylidae larvae abundance     5                    (Intercept)
## 171 Protostrongylidae larvae abundance     5                         Season
## 181 Protostrongylidae larvae abundance     5 Age category (2-5 vs 6+ years)
## 191 Protostrongylidae larvae abundance     5             Mean moose density
## 201 Protostrongylidae larvae abundance     5                Days in transit
##             coeff_print pval_print padj_print sig_print
## 151      -0.027 ± 0.089      0.766      0.958          
## 161   -9.913 ± 9733.101      0.999      0.999          
## 171       -0.09 ± 0.923      0.922      0.999          
## 181 -14.684 ± 13764.684      0.999      0.999          
## 191       -3.55 ± 2.816      0.207      0.501          
## 201       0.004 ± 0.098      0.964      0.999
write.table(supp.stats.tab2[,c("parasite_group","model","n.pos","covariates_print","coeff_print","pval_print","padj_print","sig_print")],
            "figures/supp_table_all_statistic_models_seasonal.txt",
            row.names = F, quote = F, sep = "\t", fileEncoding = "latin1")

END