knitr::opts_chunk$set(echo = TRUE)
knitr::opts_chunk$set(cache = TRUE)

library(lme4)
library(tidyverse)
load(file = paste0('D:/projects/linkedModels/data/out/dG_bktbntats1997_forLmer.RData')) # made by running mainAnalysis.R with speciesGr = c("bkt", "bnt","ats") through ddG[[ii]] <- dddG[[ii]] %>% prepareDataForJags("growth")

d2 <- data.frame(
  #sampleNumber=ddG[[1]][[2]]$sampleNumber,
  ind=ddG[[1]][[1]]$ind,
  river=ddG[[1]][[1]]$riverDATA,
  season=ddG[[1]][[1]]$season,
  species=ddG[[1]][[1]]$species,
  isYOY=ddG[[1]][[1]]$isYOYDATA,
  length=ddG[[1]][[1]]$lengthDATAStd,
  lengthByYear=ddG[[1]][[1]]$lengthDATAStd_ByYOY_Year,
  grLength=ddG[[1]][[1]]$grNotUse,
  tempStd=ddG[[1]][[1]]$tempStd,
  flowStd=ddG[[1]][[1]]$flowStd,
  countPStd=ddG[[1]][[1]]$countPAllSppStd,

  countPStdBKT=ddG[[1]][[1]]$countPStdBKT,
  countPStdBNT=ddG[[1]][[1]]$countPStdBNT,
  countPStdATS=ddG[[1]][[1]]$countPStdATS
  )

d <- d2 %>% filter(
  #  species == as.numeric(speciesInGr),
    !is.na(grLength)
  )
d <- d %>% mutate( tempStd2 = tempStd^2, flowStd2 = flowStd^2, countPStd2 = countPStd^2, length2 = length^2,
                   countPStdBKT2 = countPStdBKT^2,
                   countPStdBNT2 = countPStdBNT^2,
                   countPStdATS2 = countPStdATS^2,
                   isYOY = as.factor(isYOY), season = as.factor(season), river = as.factor(river), species = as.factor(species)
                 )
d$grLength <- ifelse(d$species == 2 & d$river == 3,NA,d$grLength)

mod <- list(list())
dIn <- list()

bySpecies <- d %>% group_by(species) %>% nest()

Try new, more flexible model structure

2a is best for BKT 2 is best for BNT

#BKT
sppMod <- 1
dIn[[sppMod]] <- d %>% filter(species == sppMod)

mod[[sppMod]][[1]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         isYOY * river * season * ( length * countPStdBKT ) +
                         isYOY * river * season * ( length * countPStdBNT ) +
                         isYOY * river * season * ( length * countPStdATS ) +                

                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )


mod[[sppMod]][[2]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         # isYOY * river * season * ( length * countPStdBKT ) +
                         # isYOY * river * season * ( length * countPStdBNT ) +
                         # isYOY * river * season * ( length * countPStdATS ) +                

                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[3]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         # isYOY * river * season * ( length * countPStdBKT ) +
                         # isYOY * river * season * ( length * countPStdBNT ) +
                         # isYOY * river * season * ( length * countPStdATS ) +                

                         isYOY * river * season * ( tempStd2 * flowStd2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[4]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         # isYOY * river * season * ( length * countPStdBKT ) +
                         # isYOY * river * season * ( length * countPStdBNT ) +
                         # isYOY * river * season * ( length * countPStdATS ) +                

                         isYOY * river * season * ( tempStd2 * flowStd2 ) +
                         isYOY * river * season * ( countPStdBKT2 ) +
                         isYOY * river * season * ( countPStdBNT2 ) +
                         isYOY * river * season * ( countPStdATS2 ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[5]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         # isYOY * river * season * ( length * countPStdBKT ) +
                         # isYOY * river * season * ( length * countPStdBNT ) +
                         # isYOY * river * season * ( length * countPStdATS ) +                

                         isYOY * river * season * ( tempStd2 * flowStd2 ) +
                         isYOY * river * season * ( countPStdBNT2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[6]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         isYOY * river * season * ( length * countPStdBKT ) +
                         isYOY * river * season * ( length * countPStdBNT ) +
                         isYOY * river * season * ( length * countPStdATS ) +                

                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[7]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         isYOY * river * season * ( length * countPStdBKT ) +
                         isYOY * river * season * ( length * countPStdBNT ) +
                         isYOY * river * season * ( length * countPStdATS ) +                

                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[8]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         isYOY * river * season * ( length * countPStdBKT ) +
                         isYOY * river * season * ( length * countPStdBNT ) +
                         isYOY * river * season * ( length * countPStdATS ) +                

                         isYOY * river * season * ( tempStd2 * flowStd2  ) +
                         isYOY * river * season * ( tempStd2 * flowStd2  ) +
                         isYOY * river * season * ( tempStd2 * flowStd2  ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )


mod[[sppMod]][[9]] <- lmer( grLength ~ isYOY * river * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * river * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * river * season * ( tempStd * flowStd * length ) +
                         # isYOY * river * season * ( length * countPStdBKT ) +
                         # isYOY * river * season * ( length * countPStdBNT ) +
                         # isYOY * river * season * ( length * countPStdATS ) +                

                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * river * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * river * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * river * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * river * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * river * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[10]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                      #   isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[11]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )

mod[[sppMod]][[12]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[sppMod]] )


(aic[[sppMod]] <- AIC(mod1,mod2,mod2a,mod2b,mod2c,mod3,mod4,mod4a,mod5,mod5a,mod5b,mod5c) %>% rownames_to_column() %>% arrange(AIC))

For salmon - need to get rid of 'river' mod5 is best

#ATS
sppMod <- 3
dIn[[3]] <- d %>% filter(species == sppMod)

mod[[3]][[1]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         isYOY * season * ( length * countPStdBKT ) +
                         isYOY * season * ( length * countPStdBNT ) +
                         isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         isYOY * season * ( length2 * countPStdBKT2 ) +
                         isYOY * season * ( length2 * countPStdBNT2 ) +
                         isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )


mod[[3]][[2]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[3]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[4]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 ) +
                         isYOY * season * ( countPStdBKT2 ) +
                         isYOY * season * ( countPStdBNT2 ) +
                         isYOY * season * ( countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[5]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 ) +
                         isYOY * season * ( countPStdBNT2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[6]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         isYOY * season * ( length * countPStdBKT ) +
                         isYOY * season * ( length * countPStdBNT ) +
                         isYOY * season * ( length * countPStdATS ) +                

                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         # isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[7]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         isYOY * season * ( length * countPStdBKT ) +
                         isYOY * season * ( length * countPStdBNT ) +
                         isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[8]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         isYOY * season * ( length * countPStdBKT ) +
                         isYOY * season * ( length * countPStdBNT ) +
                         isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2  ) +
                         isYOY * season * ( tempStd2 * flowStd2  ) +
                         isYOY * season * ( tempStd2 * flowStd2  ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )


mod[[3]][[9]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[10]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                      #   isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[11]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )

mod[[3]][[12]] <- lmer( grLength ~ isYOY * season * ( tempStd * flowStd * countPStdBKT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdBNT ) +
                         isYOY * season * ( tempStd * flowStd * countPStdATS ) +
                         isYOY * season * ( tempStd * flowStd * length ) +
                         # isYOY * season * ( length * countPStdBKT ) +
                         # isYOY * season * ( length * countPStdBNT ) +
                         # isYOY * season * ( length * countPStdATS ) +                

                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBKT2 ) +
                       #  isYOY * season * ( tempStd2 * flowStd2 * countPStdBNT2 ) +
                         isYOY * season * ( tempStd2 * flowStd2 * countPStdATS2 ) +
                         # # isYOY * season * ( tempStd2 * flowStd2 * length2 ) + # model error with this line in
                         # isYOY * season * ( length2 * countPStdBKT2 ) +
                         # isYOY * season * ( length2 * countPStdBNT2 ) +
                         # isYOY * season * ( length2 * countPStdATS2 ) + 

                         (1|ind), data = dIn[[3]] )



(aic[[sppMod]] <- AIC(mod1,mod2,mod2a,mod2b,mod2c,mod3,mod4,mod4a,mod5,mod5a,mod5b,mod5c) %>% rownames_to_column() %>% arrange(AIC))


bletcher/linkedModels documentation built on May 14, 2019, 5:24 p.m.