###Load libraries#####

library(tidyverse)
## Warning: package 'tidyverse' was built under R version 3.3.3
## Loading tidyverse: ggplot2
## Loading tidyverse: tibble
## Loading tidyverse: tidyr
## Loading tidyverse: readr
## Loading tidyverse: purrr
## Loading tidyverse: dplyr
## Warning: package 'ggplot2' was built under R version 3.3.3
## Warning: package 'purrr' was built under R version 3.3.3
## Conflicts with tidy packages ----------------------------------------------
## filter(): dplyr, stats
## lag():    dplyr, stats
library(lme4)
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following object is masked from 'package:tidyr':
## 
##     expand
library(knitr)
library(broom)
library(forcats)
library(lmerTest)
## Warning: package 'lmerTest' was built under R version 3.3.3
## 
## Attaching package: 'lmerTest'
## The following object is masked from 'package:lme4':
## 
##     lmer
## The following object is masked from 'package:stats':
## 
##     step
library(MuMIn)
## Warning: package 'MuMIn' was built under R version 3.3.3
library(knitr)
setwd ("P:/MTM2 Oranga Taiao/EMP Data/EMP Data/Biotic Index calculator/Index calculation/MTM new Data")
source('theme_javier.R')
theme_set(theme_javier(8))
options(digits = 3)

###read data#####
all_ind <-
  read_csv('all_indices_truncated.csv', col_types =  cols(Date = 'D')) %>%
  mutate(Type = factor(Type))

dat_mult <-
  all_ind %>%
  dplyr::select(
    Region,
    n,
    council,
    estuary,
    site,
    cesy,
    ces,
    year,
    AMBI:MEDOCC,
    BQI:TBI,
    logN,
    S,
    Type,
    metals,
    sqrtTP,
    sqrtmud
  ) %>%
  drop_na() %>%
  mutate(Region = fct_collapse(
    Region,
    `North Eastern`  = c('North Eastern', 'Western North Island')
  )) %>%
  dplyr::select(-MEDOCC)

dat_mult_centered <-
  dat_mult %>%
  mutate(
    TBI = sqrt(TBI),
    S = sqrt(S),
    BENTIX = sqrt(max(BENTIX) * 1.05 - BENTIX) * -1,
    AMBI = AMBI * -1,
    AMBI_S = AMBI_S * -1
  ) %>%
  gather(index, value, AMBI:S) %>%
  group_by(index) %>%
  mutate(value = scale(value))

ggplot(dat_mult_centered, aes(x = value)) +
  geom_histogram() +
  facet_wrap( ~ index)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

##Data structure####
kable(with(dat_mult_centered, table(council, Region)))
Cook Strait Eastern North Island North Eastern Southern
bayofplentyregionalcouncil 0 0 396 0
environmentcanterbury 0 0 0 27
environmentcanterburyccc 0 0 0 18
environmentsouthland 0 0 0 522
greaterwellington 72 0 0 0
hawkesbayregionalcouncil 0 432 0 0
marlboroughdistrictcouncil 72 0 0 0
nelsoncitycouncil 27 0 0 0
northlandregionalcouncil 0 0 432 0
tasmandistrictcouncil 135 0 0 0
kable(with(dat_mult_centered, table(cesy, Region)))
Cook Strait Eastern North Island North Eastern Southern
bayofplentyregionalcouncil tauranga 1 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 10 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 13 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 14 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 16 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 18 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 2 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 20 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 27 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 28 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 29 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 3 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 32 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 34 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 35 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 37 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 38 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 40 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 42 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 45 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 46 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 47 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 48 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 5 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 50 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 51 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 53 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 55 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 56 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 57 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 60 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 62 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 64 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 66 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 67 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 68 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 69 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 7 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 70 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 71 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 73 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 74 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 75 2011 0 0 9 0
bayofplentyregionalcouncil tauranga 8 2011 0 0 9 0
environmentcanterbury avonheathcote a 2001 0 0 0 9
environmentcanterbury avonheathcote b 2001 0 0 0 9
environmentcanterbury avonheathcote c 2001 0 0 0 9
environmentcanterburyccc avonheathcote dischargepoint 2011 0 0 0 9
environmentcanterburyccc avonheathcote pleasantpointjetty 2011 0 0 0 9
environmentsouthland awarua a 2005 0 0 0 9
environmentsouthland awarua b 2005 0 0 0 9
environmentsouthland bluff a 2005 0 0 0 9
environmentsouthland bluff b 2005 0 0 0 9
environmentsouthland fortrose a 2004 0 0 0 9
environmentsouthland fortrose a 2005 0 0 0 9
environmentsouthland fortrose a 2006 0 0 0 9
environmentsouthland fortrose b 2004 0 0 0 9
environmentsouthland fortrose b 2009 0 0 0 9
environmentsouthland haldane a 2006 0 0 0 9
environmentsouthland haldane a 2009 0 0 0 9
environmentsouthland haldane a 2010 0 0 0 9
environmentsouthland haldane a 2011 0 0 0 9
environmentsouthland haldane b 2013 0 0 0 9
environmentsouthland jacobsriver a 2003 0 0 0 9
environmentsouthland jacobsriver a 2004 0 0 0 9
environmentsouthland jacobsriver a 2005 0 0 0 9
environmentsouthland jacobsriver a 2006 0 0 0 9
environmentsouthland jacobsriver a 2011 0 0 0 9
environmentsouthland jacobsriver b 2003 0 0 0 9
environmentsouthland jacobsriver b 2004 0 0 0 9
environmentsouthland jacobsriver b 2005 0 0 0 9
environmentsouthland jacobsriver b 2006 0 0 0 9
environmentsouthland jacobsriver b 2011 0 0 0 9
environmentsouthland jacobsriver c 2003 0 0 0 9
environmentsouthland jacobsriver c 2004 0 0 0 9
environmentsouthland jacobsriver c 2005 0 0 0 9
environmentsouthland jacobsriver c 2006 0 0 0 9
environmentsouthland jacobsriver c 2011 0 0 0 9
environmentsouthland jacobsriver d 2012 0 0 0 9
environmentsouthland jacobsriver d 2013 0 0 0 9
environmentsouthland jacobsriver e 2012 0 0 0 9
environmentsouthland newriver a 2001 0 0 0 9
environmentsouthland newriver b 2001 0 0 0 9
environmentsouthland newriver b 2003 0 0 0 9
environmentsouthland newriver b 2004 0 0 0 9
environmentsouthland newriver b 2005 0 0 0 9
environmentsouthland newriver b 2010 0 0 0 9
environmentsouthland newriver c 2001 0 0 0 9
environmentsouthland newriver c 2003 0 0 0 9
environmentsouthland newriver c 2004 0 0 0 9
environmentsouthland newriver c 2005 0 0 0 9
environmentsouthland newriver c 2010 0 0 0 9
environmentsouthland newriver d 2001 0 0 0 9
environmentsouthland newriver d 2003 0 0 0 9
environmentsouthland newriver d 2004 0 0 0 9
environmentsouthland newriver d 2005 0 0 0 9
environmentsouthland newriver d 2010 0 0 0 9
environmentsouthland newriver e 2013 0 0 0 9
environmentsouthland newriver f 2013 0 0 0 9
environmentsouthland waikawa a 2005 0 0 0 9
environmentsouthland waikawa a 2006 0 0 0 9
environmentsouthland waikawa a 2007 0 0 0 9
environmentsouthland waikawa a 2008 0 0 0 9
environmentsouthland waikawa b 2005 0 0 0 9
environmentsouthland waikawa b 2006 0 0 0 9
environmentsouthland waikawa b 2007 0 0 0 9
environmentsouthland waikawa b 2008 0 0 0 9
greaterwellington pauatahanui a 2009 9 0 0 0
greaterwellington pauatahanui a 2010 9 0 0 0
greaterwellington pauatahanui b 2009 9 0 0 0
greaterwellington pauatahanui b 2010 9 0 0 0
greaterwellington porirua a 2009 9 0 0 0
greaterwellington porirua a 2010 9 0 0 0
greaterwellington porirua b 2009 9 0 0 0
greaterwellington porirua b 2010 9 0 0 0
hawkesbayregionalcouncil ahuriri a 2006 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2007 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2008 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2009 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2010 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2011 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2012 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2013 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2014 0 9 0 0
hawkesbayregionalcouncil ahuriri a 2015 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2006 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2007 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2008 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2009 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2010 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2011 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2012 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2013 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2014 0 9 0 0
hawkesbayregionalcouncil ahuriri b 2015 0 9 0 0
hawkesbayregionalcouncil ahuriri c 2006 0 9 0 0
hawkesbayregionalcouncil ahuriri c 2007 0 9 0 0
hawkesbayregionalcouncil ahuriri c 2008 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2007 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2008 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2009 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2010 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2011 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2012 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2013 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2014 0 9 0 0
hawkesbayregionalcouncil ahuriri d 2015 0 9 0 0
hawkesbayregionalcouncil ahuriri e 2009 0 9 0 0
hawkesbayregionalcouncil ahuriri e 2010 0 9 0 0
hawkesbayregionalcouncil ahuriri e 2011 0 9 0 0
hawkesbayregionalcouncil ahuriri e 2012 0 9 0 0
hawkesbayregionalcouncil ahuriri e 2013 0 9 0 0
hawkesbayregionalcouncil ahuriri e 2014 0 9 0 0
hawkesbayregionalcouncil ahuriri e 2015 0 9 0 0
hawkesbayregionalcouncil porangahau a 2007 0 9 0 0
hawkesbayregionalcouncil porangahau a 2008 0 9 0 0
hawkesbayregionalcouncil porangahau a 2009 0 9 0 0
hawkesbayregionalcouncil porangahau a 2010 0 9 0 0
hawkesbayregionalcouncil porangahau a 2011 0 9 0 0
hawkesbayregionalcouncil porangahau a 2012 0 9 0 0
hawkesbayregionalcouncil porangahau a 2013 0 9 0 0
hawkesbayregionalcouncil porangahau a 2014 0 9 0 0
hawkesbayregionalcouncil porangahau a 2015 0 9 0 0
marlboroughdistrictcouncil havelock a 2001 9 0 0 0
marlboroughdistrictcouncil havelock a 2014 9 0 0 0
marlboroughdistrictcouncil havelock a 2015 9 0 0 0
marlboroughdistrictcouncil havelock b 2001 9 0 0 0
marlboroughdistrictcouncil havelock b 2014 9 0 0 0
marlboroughdistrictcouncil havelock b 2015 9 0 0 0
marlboroughdistrictcouncil havelock c 2015 9 0 0 0
marlboroughdistrictcouncil havelock d 2015 9 0 0 0
nelsoncitycouncil delaware a 2009 9 0 0 0
nelsoncitycouncil delaware b 2009 9 0 0 0
nelsoncitycouncil delaware c 2009 9 0 0 0
northlandregionalcouncil kaipara a 2001 0 0 9 0
northlandregionalcouncil kaipara b 2001 0 0 9 0
northlandregionalcouncil kaipara c 2001 0 0 9 0
northlandregionalcouncil mangonui man-10 2016 0 0 9 0
northlandregionalcouncil mangonui man-11 2016 0 0 9 0
northlandregionalcouncil mangonui man-15 2016 0 0 9 0
northlandregionalcouncil mangonui man-17 2016 0 0 9 0
northlandregionalcouncil mangonui man-2 2016 0 0 9 0
northlandregionalcouncil mangonui man-20 2016 0 0 9 0
northlandregionalcouncil mangonui man-21 2016 0 0 9 0
northlandregionalcouncil mangonui man-22 2016 0 0 9 0
northlandregionalcouncil mangonui man-3 2016 0 0 9 0
northlandregionalcouncil mangonui man-4 2016 0 0 9 0
northlandregionalcouncil mangonui man-5 2016 0 0 9 0
northlandregionalcouncil mangonui man-7 2016 0 0 9 0
northlandregionalcouncil mangonui man-9 2016 0 0 9 0
northlandregionalcouncil ngunguru 1 2016 0 0 9 0
northlandregionalcouncil ngunguru 10 2016 0 0 9 0
northlandregionalcouncil ngunguru 12 2016 0 0 9 0
northlandregionalcouncil ngunguru 13 2016 0 0 9 0
northlandregionalcouncil ngunguru 14 2016 0 0 9 0
northlandregionalcouncil ngunguru 15 2016 0 0 9 0
northlandregionalcouncil ngunguru 16 2016 0 0 9 0
northlandregionalcouncil ngunguru 17 2016 0 0 9 0
northlandregionalcouncil ngunguru 19 2016 0 0 9 0
northlandregionalcouncil ngunguru 2 2016 0 0 9 0
northlandregionalcouncil ngunguru 20 2016 0 0 9 0
northlandregionalcouncil ngunguru 21 2016 0 0 9 0
northlandregionalcouncil ngunguru 22 2016 0 0 9 0
northlandregionalcouncil ngunguru 3 2016 0 0 9 0
northlandregionalcouncil ngunguru 4 2016 0 0 9 0
northlandregionalcouncil ngunguru 5 2016 0 0 9 0
northlandregionalcouncil ngunguru 6 2016 0 0 9 0
northlandregionalcouncil ngunguru 7 2016 0 0 9 0
northlandregionalcouncil ngunguru 8 2016 0 0 9 0
northlandregionalcouncil ngunguru 9 2016 0 0 9 0
northlandregionalcouncil ruakaka rua 2008 0 0 9 0
northlandregionalcouncil ruakaka tam 2008 0 0 9 0
northlandregionalcouncil whangarei hat 2008 0 0 9 0
northlandregionalcouncil whangarei man 2008 0 0 9 0
northlandregionalcouncil whangarei otk 2008 0 0 9 0
northlandregionalcouncil whangarei ptl 2008 0 0 9 0
northlandregionalcouncil whangaroa kae 2009 0 0 9 0
northlandregionalcouncil whangaroa kae 2010 0 0 9 0
northlandregionalcouncil whangaroa kae 2011 0 0 9 0
northlandregionalcouncil whangaroa kah 2009 0 0 9 0
northlandregionalcouncil whangaroa kah 2010 0 0 9 0
northlandregionalcouncil whangaroa kah 2011 0 0 9 0
tasmandistrictcouncil moutere a 2006 9 0 0 0
tasmandistrictcouncil moutere a 2013 9 0 0 0
tasmandistrictcouncil moutere b 2006 9 0 0 0
tasmandistrictcouncil moutere b 2013 9 0 0 0
tasmandistrictcouncil ruataniwha a 2001 9 0 0 0
tasmandistrictcouncil ruataniwha b 2001 9 0 0 0
tasmandistrictcouncil ruataniwha c 2001 9 0 0 0
tasmandistrictcouncil waimea a 2001 9 0 0 0
tasmandistrictcouncil waimea a 2014 9 0 0 0
tasmandistrictcouncil waimea b 2001 9 0 0 0
tasmandistrictcouncil waimea b 2014 9 0 0 0
tasmandistrictcouncil waimea c 2001 9 0 0 0
tasmandistrictcouncil waimea c 2014 9 0 0 0
tasmandistrictcouncil waimea d 2001 9 0 0 0
tasmandistrictcouncil waimea d 2014 9 0 0 0
kable(with(dat_mult_centered, table(ces, Region)))
Cook Strait Eastern North Island North Eastern Southern
bayofplentyregionalcouncil tauranga 1 0 0 9 0
bayofplentyregionalcouncil tauranga 10 0 0 9 0
bayofplentyregionalcouncil tauranga 13 0 0 9 0
bayofplentyregionalcouncil tauranga 14 0 0 9 0
bayofplentyregionalcouncil tauranga 16 0 0 9 0
bayofplentyregionalcouncil tauranga 18 0 0 9 0
bayofplentyregionalcouncil tauranga 2 0 0 9 0
bayofplentyregionalcouncil tauranga 20 0 0 9 0
bayofplentyregionalcouncil tauranga 27 0 0 9 0
bayofplentyregionalcouncil tauranga 28 0 0 9 0
bayofplentyregionalcouncil tauranga 29 0 0 9 0
bayofplentyregionalcouncil tauranga 3 0 0 9 0
bayofplentyregionalcouncil tauranga 32 0 0 9 0
bayofplentyregionalcouncil tauranga 34 0 0 9 0
bayofplentyregionalcouncil tauranga 35 0 0 9 0
bayofplentyregionalcouncil tauranga 37 0 0 9 0
bayofplentyregionalcouncil tauranga 38 0 0 9 0
bayofplentyregionalcouncil tauranga 40 0 0 9 0
bayofplentyregionalcouncil tauranga 42 0 0 9 0
bayofplentyregionalcouncil tauranga 45 0 0 9 0
bayofplentyregionalcouncil tauranga 46 0 0 9 0
bayofplentyregionalcouncil tauranga 47 0 0 9 0
bayofplentyregionalcouncil tauranga 48 0 0 9 0
bayofplentyregionalcouncil tauranga 5 0 0 9 0
bayofplentyregionalcouncil tauranga 50 0 0 9 0
bayofplentyregionalcouncil tauranga 51 0 0 9 0
bayofplentyregionalcouncil tauranga 53 0 0 9 0
bayofplentyregionalcouncil tauranga 55 0 0 9 0
bayofplentyregionalcouncil tauranga 56 0 0 9 0
bayofplentyregionalcouncil tauranga 57 0 0 9 0
bayofplentyregionalcouncil tauranga 60 0 0 9 0
bayofplentyregionalcouncil tauranga 62 0 0 9 0
bayofplentyregionalcouncil tauranga 64 0 0 9 0
bayofplentyregionalcouncil tauranga 66 0 0 9 0
bayofplentyregionalcouncil tauranga 67 0 0 9 0
bayofplentyregionalcouncil tauranga 68 0 0 9 0
bayofplentyregionalcouncil tauranga 69 0 0 9 0
bayofplentyregionalcouncil tauranga 7 0 0 9 0
bayofplentyregionalcouncil tauranga 70 0 0 9 0
bayofplentyregionalcouncil tauranga 71 0 0 9 0
bayofplentyregionalcouncil tauranga 73 0 0 9 0
bayofplentyregionalcouncil tauranga 74 0 0 9 0
bayofplentyregionalcouncil tauranga 75 0 0 9 0
bayofplentyregionalcouncil tauranga 8 0 0 9 0
environmentcanterbury avonheathcote a 0 0 0 9
environmentcanterbury avonheathcote b 0 0 0 9
environmentcanterbury avonheathcote c 0 0 0 9
environmentcanterburyccc avonheathcote dischargepoint 0 0 0 9
environmentcanterburyccc avonheathcote pleasantpointjetty 0 0 0 9
environmentsouthland awarua a 0 0 0 9
environmentsouthland awarua b 0 0 0 9
environmentsouthland bluff a 0 0 0 9
environmentsouthland bluff b 0 0 0 9
environmentsouthland fortrose a 0 0 0 27
environmentsouthland fortrose b 0 0 0 18
environmentsouthland haldane a 0 0 0 36
environmentsouthland haldane b 0 0 0 9
environmentsouthland jacobsriver a 0 0 0 45
environmentsouthland jacobsriver b 0 0 0 45
environmentsouthland jacobsriver c 0 0 0 45
environmentsouthland jacobsriver d 0 0 0 18
environmentsouthland jacobsriver e 0 0 0 9
environmentsouthland newriver a 0 0 0 9
environmentsouthland newriver b 0 0 0 45
environmentsouthland newriver c 0 0 0 45
environmentsouthland newriver d 0 0 0 45
environmentsouthland newriver e 0 0 0 9
environmentsouthland newriver f 0 0 0 9
environmentsouthland waikawa a 0 0 0 36
environmentsouthland waikawa b 0 0 0 36
greaterwellington pauatahanui a 18 0 0 0
greaterwellington pauatahanui b 18 0 0 0
greaterwellington porirua a 18 0 0 0
greaterwellington porirua b 18 0 0 0
hawkesbayregionalcouncil ahuriri a 0 90 0 0
hawkesbayregionalcouncil ahuriri b 0 90 0 0
hawkesbayregionalcouncil ahuriri c 0 27 0 0
hawkesbayregionalcouncil ahuriri d 0 81 0 0
hawkesbayregionalcouncil ahuriri e 0 63 0 0
hawkesbayregionalcouncil porangahau a 0 81 0 0
marlboroughdistrictcouncil havelock a 27 0 0 0
marlboroughdistrictcouncil havelock b 27 0 0 0
marlboroughdistrictcouncil havelock c 9 0 0 0
marlboroughdistrictcouncil havelock d 9 0 0 0
nelsoncitycouncil delaware a 9 0 0 0
nelsoncitycouncil delaware b 9 0 0 0
nelsoncitycouncil delaware c 9 0 0 0
northlandregionalcouncil kaipara a 0 0 9 0
northlandregionalcouncil kaipara b 0 0 9 0
northlandregionalcouncil kaipara c 0 0 9 0
northlandregionalcouncil mangonui man-10 0 0 9 0
northlandregionalcouncil mangonui man-11 0 0 9 0
northlandregionalcouncil mangonui man-15 0 0 9 0
northlandregionalcouncil mangonui man-17 0 0 9 0
northlandregionalcouncil mangonui man-2 0 0 9 0
northlandregionalcouncil mangonui man-20 0 0 9 0
northlandregionalcouncil mangonui man-21 0 0 9 0
northlandregionalcouncil mangonui man-22 0 0 9 0
northlandregionalcouncil mangonui man-3 0 0 9 0
northlandregionalcouncil mangonui man-4 0 0 9 0
northlandregionalcouncil mangonui man-5 0 0 9 0
northlandregionalcouncil mangonui man-7 0 0 9 0
northlandregionalcouncil mangonui man-9 0 0 9 0
northlandregionalcouncil ngunguru 1 0 0 9 0
northlandregionalcouncil ngunguru 10 0 0 9 0
northlandregionalcouncil ngunguru 12 0 0 9 0
northlandregionalcouncil ngunguru 13 0 0 9 0
northlandregionalcouncil ngunguru 14 0 0 9 0
northlandregionalcouncil ngunguru 15 0 0 9 0
northlandregionalcouncil ngunguru 16 0 0 9 0
northlandregionalcouncil ngunguru 17 0 0 9 0
northlandregionalcouncil ngunguru 19 0 0 9 0
northlandregionalcouncil ngunguru 2 0 0 9 0
northlandregionalcouncil ngunguru 20 0 0 9 0
northlandregionalcouncil ngunguru 21 0 0 9 0
northlandregionalcouncil ngunguru 22 0 0 9 0
northlandregionalcouncil ngunguru 3 0 0 9 0
northlandregionalcouncil ngunguru 4 0 0 9 0
northlandregionalcouncil ngunguru 5 0 0 9 0
northlandregionalcouncil ngunguru 6 0 0 9 0
northlandregionalcouncil ngunguru 7 0 0 9 0
northlandregionalcouncil ngunguru 8 0 0 9 0
northlandregionalcouncil ngunguru 9 0 0 9 0
northlandregionalcouncil ruakaka rua 0 0 9 0
northlandregionalcouncil ruakaka tam 0 0 9 0
northlandregionalcouncil whangarei hat 0 0 9 0
northlandregionalcouncil whangarei man 0 0 9 0
northlandregionalcouncil whangarei otk 0 0 9 0
northlandregionalcouncil whangarei ptl 0 0 9 0
northlandregionalcouncil whangaroa kae 0 0 27 0
northlandregionalcouncil whangaroa kah 0 0 27 0
tasmandistrictcouncil moutere a 18 0 0 0
tasmandistrictcouncil moutere b 18 0 0 0
tasmandistrictcouncil ruataniwha a 9 0 0 0
tasmandistrictcouncil ruataniwha b 9 0 0 0
tasmandistrictcouncil ruataniwha c 9 0 0 0
tasmandistrictcouncil waimea a 18 0 0 0
tasmandistrictcouncil waimea b 18 0 0 0
tasmandistrictcouncil waimea c 18 0 0 0
tasmandistrictcouncil waimea d 18 0 0 0
kable(with(dat_mult_centered, table(estuary, Region)))
Cook Strait Eastern North Island North Eastern Southern
ahuriri 0 351 0 0
avonheathcote 0 0 0 45
awarua 0 0 0 18
bluff 0 0 0 18
delaware 27 0 0 0
fortrose 0 0 0 45
haldane 0 0 0 45
havelock 72 0 0 0
jacobsriver 0 0 0 162
kaipara 0 0 27 0
mangonui 0 0 117 0
moutere 36 0 0 0
newriver 0 0 0 162
ngunguru 0 0 180 0
pauatahanui 36 0 0 0
porangahau 0 81 0 0
porirua 36 0 0 0
ruakaka 0 0 18 0
ruataniwha 27 0 0 0
tauranga 0 0 396 0
waikawa 0 0 0 72
waimea 72 0 0 0
whangarei 0 0 36 0
whangaroa 0 0 54 0
kable(with(dat_mult_centered, table(estuary, year)))
2001 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016
ahuriri 0 0 0 0 27 36 36 36 36 36 36 36 36 36 0
avonheathcote 27 0 0 0 0 0 0 0 0 18 0 0 0 0 0
awarua 0 0 0 18 0 0 0 0 0 0 0 0 0 0 0
bluff 0 0 0 18 0 0 0 0 0 0 0 0 0 0 0
delaware 0 0 0 0 0 0 0 27 0 0 0 0 0 0 0
fortrose 0 0 18 9 9 0 0 9 0 0 0 0 0 0 0
haldane 0 0 0 0 9 0 0 9 9 9 0 9 0 0 0
havelock 18 0 0 0 0 0 0 0 0 0 0 0 18 36 0
jacobsriver 0 27 27 27 27 0 0 0 0 27 18 9 0 0 0
kaipara 27 0 0 0 0 0 0 0 0 0 0 0 0 0 0
mangonui 0 0 0 0 0 0 0 0 0 0 0 0 0 0 117
moutere 0 0 0 0 18 0 0 0 0 0 0 18 0 0 0
newriver 36 27 27 27 0 0 0 0 27 0 0 18 0 0 0
ngunguru 0 0 0 0 0 0 0 0 0 0 0 0 0 0 180
pauatahanui 0 0 0 0 0 0 0 18 18 0 0 0 0 0 0
porangahau 0 0 0 0 0 9 9 9 9 9 9 9 9 9 0
porirua 0 0 0 0 0 0 0 18 18 0 0 0 0 0 0
ruakaka 0 0 0 0 0 0 18 0 0 0 0 0 0 0 0
ruataniwha 27 0 0 0 0 0 0 0 0 0 0 0 0 0 0
tauranga 0 0 0 0 0 0 0 0 0 396 0 0 0 0 0
waikawa 0 0 0 18 18 18 18 0 0 0 0 0 0 0 0
waimea 36 0 0 0 0 0 0 0 0 0 0 0 36 0 0
whangarei 0 0 0 0 0 0 36 0 0 0 0 0 0 0 0
whangaroa 0 0 0 0 0 0 0 18 18 18 0 0 0 0 0
###Linear mixed models using lmer#####
EG_models8 <-
  dat_mult_centered %>%
  do(
    fit_index8 = lmer(
      value ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type + (1 |
                                                                           year) + (1 | Region / estuary),
      data = .,
      ,
      REML = FALSE,
      weights = sqrt(n),
      na.action = "na.fail"
    )
  )

index_coef_all8 <-
  tidy(EG_models8, fit_index8, conf.int = T) %>%
  data.frame(.) %>%
  filter(term != '(Intercept)' &
           term != 'sd_Observation.Residual') %>%
  mutate(term = factor(term))

kable(index_coef_all8)
index term estimate std.error statistic conf.low conf.high group
AMBI scale(metals) -0.134 0.122 -1.103 -0.373 0.104 fixed
AMBI scale(sqrtmud) -0.557 0.115 -4.841 -0.782 -0.331 fixed
AMBI scale(sqrtTP) 0.016 0.146 0.110 -0.271 0.303 fixed
AMBI Type8 -0.461 0.179 -2.573 -0.813 -0.110 fixed
AMBI scale(metals):Type8 -0.054 0.210 -0.257 -0.466 0.358 fixed
AMBI scale(sqrtmud):Type8 0.259 0.165 1.568 -0.065 0.583 fixed
AMBI scale(sqrtTP):Type8 -0.001 0.206 -0.007 -0.404 0.402 fixed
AMBI sd_(Intercept).estuary:Region 0.284 NA NA NA NA estuary:Region
AMBI sd_(Intercept).year 0.000 NA NA NA NA year
AMBI sd_(Intercept).Region 0.000 NA NA NA NA Region
AMBI_S scale(metals) -0.178 0.114 -1.565 -0.401 0.045 fixed
AMBI_S scale(sqrtmud) -0.750 0.108 -6.960 -0.962 -0.539 fixed
AMBI_S scale(sqrtTP) 0.036 0.136 0.263 -0.230 0.302 fixed
AMBI_S Type8 -0.319 0.178 -1.794 -0.668 0.030 fixed
AMBI_S scale(metals):Type8 -0.021 0.194 -0.111 -0.402 0.359 fixed
AMBI_S scale(sqrtmud):Type8 0.392 0.155 2.533 0.089 0.695 fixed
AMBI_S scale(sqrtTP):Type8 -0.066 0.190 -0.348 -0.439 0.307 fixed
AMBI_S sd_(Intercept).estuary:Region 0.305 NA NA NA NA estuary:Region
AMBI_S sd_(Intercept).year 0.050 NA NA NA NA year
AMBI_S sd_(Intercept).Region 0.000 NA NA NA NA Region
BENTIX scale(metals) -0.267 0.126 -2.119 -0.514 -0.020 fixed
BENTIX scale(sqrtmud) -0.500 0.121 -4.132 -0.737 -0.263 fixed
BENTIX scale(sqrtTP) 0.252 0.150 1.682 -0.042 0.546 fixed
BENTIX Type8 -0.492 0.262 -1.881 -1.005 0.021 fixed
BENTIX scale(metals):Type8 0.002 0.213 0.008 -0.417 0.420 fixed
BENTIX scale(sqrtmud):Type8 0.183 0.175 1.046 -0.160 0.526 fixed
BENTIX scale(sqrtTP):Type8 -0.087 0.210 -0.413 -0.498 0.325 fixed
BENTIX sd_(Intercept).estuary:Region 0.540 NA NA NA NA estuary:Region
BENTIX sd_(Intercept).year 0.000 NA NA NA NA year
BENTIX sd_(Intercept).Region 0.000 NA NA NA NA Region
BQI scale(metals) -0.210 0.091 -2.306 -0.388 -0.031 fixed
BQI scale(sqrtmud) -0.213 0.089 -2.399 -0.387 -0.039 fixed
BQI scale(sqrtTP) -0.021 0.107 -0.200 -0.232 0.189 fixed
BQI Type8 -0.276 0.246 -1.123 -0.758 0.206 fixed
BQI scale(metals):Type8 -0.015 0.151 -0.101 -0.312 0.281 fixed
BQI scale(sqrtmud):Type8 -0.130 0.126 -1.030 -0.377 0.117 fixed
BQI scale(sqrtTP):Type8 0.298 0.149 2.004 0.007 0.589 fixed
BQI sd_(Intercept).estuary:Region 0.489 NA NA NA NA estuary:Region
BQI sd_(Intercept).year 0.091 NA NA NA NA year
BQI sd_(Intercept).Region 0.607 NA NA NA NA Region
ITI scale(metals) -0.154 0.123 -1.249 -0.396 0.088 fixed
ITI scale(sqrtmud) -0.220 0.119 -1.857 -0.453 0.012 fixed
ITI scale(sqrtTP) 0.327 0.144 2.266 0.044 0.610 fixed
ITI Type8 -0.451 0.258 -1.748 -0.957 0.055 fixed
ITI scale(metals):Type8 0.190 0.204 0.933 -0.209 0.589 fixed
ITI scale(sqrtmud):Type8 -0.215 0.167 -1.287 -0.544 0.113 fixed
ITI scale(sqrtTP):Type8 -0.018 0.199 -0.090 -0.409 0.373 fixed
ITI sd_(Intercept).estuary:Region 0.535 NA NA NA NA estuary:Region
ITI sd_(Intercept).year 0.199 NA NA NA NA year
ITI sd_(Intercept).Region 0.000 NA NA NA NA Region
logN scale(metals) -0.129 0.095 -1.354 -0.315 0.057 fixed
logN scale(sqrtmud) 0.330 0.094 3.513 0.146 0.514 fixed
logN scale(sqrtTP) -0.128 0.111 -1.155 -0.344 0.089 fixed
logN Type8 -0.802 0.212 -3.787 -1.218 -0.387 fixed
logN scale(metals):Type8 0.109 0.156 0.700 -0.196 0.414 fixed
logN scale(sqrtmud):Type8 -0.441 0.130 -3.380 -0.696 -0.185 fixed
logN scale(sqrtTP):Type8 0.428 0.152 2.809 0.129 0.727 fixed
logN sd_(Intercept).estuary:Region 0.378 NA NA NA NA estuary:Region
logN sd_(Intercept).year 0.162 NA NA NA NA year
logN sd_(Intercept).Region 0.919 NA NA NA NA Region
M_AMBI scale(metals) -0.132 0.103 -1.277 -0.335 0.071 fixed
M_AMBI scale(sqrtmud) -0.455 0.100 -4.535 -0.652 -0.259 fixed
M_AMBI scale(sqrtTP) -0.059 0.122 -0.486 -0.298 0.180 fixed
M_AMBI Type8 -0.184 0.248 -0.740 -0.670 0.303 fixed
M_AMBI scale(metals):Type8 -0.068 0.173 -0.393 -0.406 0.270 fixed
M_AMBI scale(sqrtmud):Type8 0.005 0.143 0.037 -0.275 0.285 fixed
M_AMBI scale(sqrtTP):Type8 0.281 0.169 1.662 -0.051 0.613 fixed
M_AMBI sd_(Intercept).estuary:Region 0.492 NA NA NA NA estuary:Region
M_AMBI sd_(Intercept).year 0.096 NA NA NA NA year
M_AMBI sd_(Intercept).Region 0.338 NA NA NA NA Region
S scale(metals) -0.176 0.091 -1.924 -0.355 0.003 fixed
S scale(sqrtmud) -0.153 0.089 -1.714 -0.328 0.022 fixed
S scale(sqrtTP) -0.059 0.107 -0.549 -0.269 0.151 fixed
S Type8 -0.325 0.236 -1.377 -0.787 0.137 fixed
S scale(metals):Type8 0.008 0.150 0.056 -0.286 0.303 fixed
S scale(sqrtmud):Type8 -0.215 0.126 -1.715 -0.461 0.031 fixed
S scale(sqrtTP):Type8 0.351 0.147 2.383 0.062 0.640 fixed
S sd_(Intercept).estuary:Region 0.460 NA NA NA NA estuary:Region
S sd_(Intercept).year 0.137 NA NA NA NA year
S sd_(Intercept).Region 0.585 NA NA NA NA Region
TBI scale(metals) -0.270 0.087 -3.102 -0.441 -0.099 fixed
TBI scale(sqrtmud) -0.222 0.085 -2.601 -0.389 -0.055 fixed
TBI scale(sqrtTP) 0.086 0.101 0.853 -0.112 0.284 fixed
TBI Type8 0.014 0.215 0.067 -0.406 0.435 fixed
TBI scale(metals):Type8 0.115 0.142 0.811 -0.163 0.392 fixed
TBI scale(sqrtmud):Type8 -0.144 0.118 -1.220 -0.376 0.088 fixed
TBI scale(sqrtTP):Type8 0.199 0.138 1.437 -0.072 0.470 fixed
TBI sd_(Intercept).estuary:Region 0.413 NA NA NA NA estuary:Region
TBI sd_(Intercept).year 0.187 NA NA NA NA year
TBI sd_(Intercept).Region 0.470 NA NA NA NA Region
##Model summary####
index_Summ8  <-
  glance(EG_models8, fit_index8)
kable(index_Summ8)
index sigma logLik AIC BIC deviance df.residual
AMBI 1.383 -310 645 686 621 225
AMBI_S 1.250 -289 602 643 578 225
BENTIX 1.281 -303 629 671 605 225
BQI 0.873 -223 469 511 445 225
ITI 1.203 -292 609 650 585 225
logN 0.922 -235 493 535 469 225
M_AMBI 1.011 -253 529 571 505 225
S 0.869 -222 469 510 445 225
TBI 0.818 -209 442 484 418 225
ggplot(index_coef_all8,
       aes(
         x = estimate,
         y = fct_rev(fct_inorder(term)),
         color = term
       )) +
  geom_point() +
  geom_errorbarh(aes(
    xmin = conf.low,
    xmax = conf.high,
    height = .2
  )) +
  facet_wrap( ~ index) +
  geom_vline(xintercept = 0,
             lty = 2,
             col = 'gray60') +
  ylab('') +
  xlab('Coefficients') +
  scale_color_discrete(guide = F) +
  theme_javier()
## Warning: Removed 27 rows containing missing values (geom_errorbarh).

###residuals
index_residuals8  <-
  augment(EG_models8, fit_index8)

ggplot(index_residuals8) +
  geom_point(aes(x = .fitted, y = .resid), alpha = .3) +
  facet_wrap(~ index, scale = 'free') +
  geom_hline(yintercept = 0,
             lty = 2,
             col = 2)

ggplot(index_residuals8) +
  stat_qq(aes(sample = .wtres), alpha = .3) +
  facet_wrap(~ index, scale = 'free') +
  geom_abline(
    intercept =  0,
    slope = 1,
    lty = 2,
    col = 2
  )

library(MuMIn)
pseudo_rsq <-
  EG_models8 %>%
  ungroup() %>%
  mutate(r_sq = map(fit_index8, r.squaredGLMM),
         R_sq_dat = map(r_sq, data.frame)) %>%
  unnest(R_sq_dat) %>%
  rename(R_sq = .x..i..) %>%
  mutate(Type = rep(c('Marginal', 'Conditional'), 9),
         index = factor(index)) %>%
  print()
## # A tibble: 18 × 3
##     index   R_sq        Type
##    <fctr>  <dbl>       <chr>
## 1    AMBI 0.1332    Marginal
## 2    AMBI 0.1682 Conditional
## 3  AMBI_S 0.2208    Marginal
## 4  AMBI_S 0.2656 Conditional
## 5  BENTIX 0.1201    Marginal
## 6  BENTIX 0.2530 Conditional
## 7     BQI 0.0915    Marginal
## 8     BQI 0.4975 Conditional
## 9     ITI 0.0931    Marginal
## 10    ITI 0.2598 Conditional
## 11   logN 0.1123    Marginal
## 12   logN 0.5950 Conditional
## 13 M_AMBI 0.1548    Marginal
## 14 M_AMBI 0.3774 Conditional
## 15      S 0.0896    Marginal
## 16      S 0.4821 Conditional
## 17    TBI 0.1048    Marginal
## 18    TBI 0.4532 Conditional
ggplot(pseudo_rsq) +
  geom_col(aes(
    x = fct_reorder(index, R_sq),
    y = R_sq,
    fill = Type
  ), position = 'stack') +
  labs(y = 'Pseudo R - square', x = '') +
  coord_flip() +
  theme(legend.position = c(.9, .1))

###Model averaging######
options(na.action = "na.fail")
###AMBI_S#####
global_AMBI_S <-
  lmer(
    AMBI_S ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type + (1|year) + (1|Region/estuary),
    data = dat_mult,
    weights = sqrt(n)
  )
summary(global_AMBI_S)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: 
## AMBI_S ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type +  
##     (1 | year) + (1 | Region/estuary)
##    Data: dat_mult
## Weights: sqrt(n)
## 
## REML criterion at convergence: 246
## 
## Scaled residuals: 
##    Min     1Q Median     3Q    Max 
## -2.493 -0.587 -0.040  0.566  3.520 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  estuary:Region (Intercept) 0.03021  0.1738  
##  year           (Intercept) 0.00202  0.0449  
##  Region         (Intercept) 0.00000  0.0000  
##  Residual                   0.33823  0.5816  
## Number of obs: 237, groups:  estuary:Region, 24; year, 15; Region, 4
## 
## Fixed effects:
##                       Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)            1.88127    0.06351  12.40000   29.62  6.6e-13 ***
## scale(metals)          0.08024    0.05507 136.80000    1.46    0.147    
## scale(sqrtmud)         0.36071    0.05252 115.60000    6.87  3.5e-10 ***
## scale(sqrtTP)         -0.01558    0.06522 166.60000   -0.24    0.811    
## Type8                  0.14220    0.09392  14.10000    1.51    0.152    
## scale(metals):Type8    0.00455    0.09309 184.80000    0.05    0.961    
## scale(sqrtmud):Type8  -0.19354    0.07505 126.80000   -2.58    0.011 *  
## scale(sqrtTP):Type8    0.02872    0.09119 178.80000    0.31    0.753    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) scl(m) scl(s) sc(TP) Type8  scl(m):T8 scl(s):T8
## scale(mtls) -0.038                                                
## scl(sqrtmd)  0.048  0.010                                         
## scl(sqrtTP)  0.018 -0.573 -0.459                                  
## Type8       -0.650  0.026 -0.036 -0.011                           
## scl(mtl):T8  0.023 -0.581 -0.010  0.334  0.115                    
## scl(sqr):T8 -0.034 -0.008 -0.692  0.319 -0.034 -0.137             
## scl(sTP):T8 -0.013  0.401  0.327 -0.710 -0.080 -0.561    -0.438
set_AMBI_S <- dredge(global_AMBI_S, rank = 'AICc') %>% print()
## Warning in dredge(global_AMBI_S, rank = "AICc"): comparing models fitted by
## REML
## Fixed term is "(Intercept)"
## Global model call: lme4::lmer(formula = AMBI_S ~ (scale(metals) + scale(sqrtmud) + 
##     scale(sqrtTP)) * Type + (1 | year) + (1 | Region/estuary), 
##     data = dat_mult, weights = sqrt(n))
## ---
## Model selection table 
##     (Int) scl(mtl) scl(sqr) scl(sTP) Typ scl(mtl):Typ scl(sqr):Typ
## 3    1.93             0.289                                       
## 43   1.89             0.387            +                         +
## 11   1.87             0.284            +                          
## 4    1.93   0.0681    0.259                                       
## 44   1.88   0.0801    0.352            +                         +
## 7    1.92             0.262  0.04221                              
## 12   1.86   0.0772    0.248            +                          
## 47   1.89             0.359  0.04617   +                         +
## 15   1.87             0.256  0.04292   +                          
## 60   1.88   0.0730    0.354            +            +            +
## 8    1.93   0.0658    0.258  0.00371                              
## 48   1.88   0.0797    0.352  0.00039   +                         +
## 28   1.87   0.1007    0.261            +            +             
## 16   1.86   0.0774    0.249 -0.00122   +                          
## 111  1.89             0.363  0.03902   +                         +
## 79   1.88             0.267  0.08800   +                          
## 112  1.88   0.0819    0.360 -0.01667   +                         +
## 64   1.88   0.0734    0.355 -0.00113   +            +            +
## 80   1.87   0.0722    0.259  0.04189   +                          
## 32   1.87   0.0987    0.259  0.00392   +            +             
## 128  1.88   0.0802    0.361 -0.01558   +            +            +
## 96   1.87   0.0809    0.261  0.03528   +            +             
## 5    1.93                    0.20230                              
## 13   1.85                    0.19740   +                          
## 6    1.93   0.0851           0.14810                              
## 14   1.85   0.0964           0.13530   +                          
## 10   1.84   0.2007                     +                          
## 2    1.95   0.2003                                                
## 77   1.86                    0.21820   +                          
## 30   1.85   0.0922           0.13350   +            +             
## 78   1.85   0.0954           0.15240   +                          
## 26   1.84   0.1764                     +            +             
## 94   1.85   0.0741           0.16690   +            +             
## 1    1.96                                                         
## 9    1.85                              +                          
##     scl(sTP):Typ df logLik AICc delta weight
## 3                 6   -119  250  0.00  0.481
## 43                8   -117  252  1.76  0.199
## 11                7   -119  253  3.27  0.094
## 4                 7   -119  253  3.57  0.081
## 44                9   -118  254  4.17  0.060
## 7                 7   -120  255  5.63  0.029
## 12                8   -120  256  6.01  0.024
## 47                9   -119  257  7.17  0.013
## 15                8   -121  259  8.89  0.006
## 60               10   -119  259  9.59  0.004
## 8                 8   -122  260 10.05  0.003
## 48               10   -120  260 10.70  0.002
## 28                9   -121  260 10.73  0.002
## 16                9   -122  262 12.56  0.001
## 111            + 10   -121  262 12.64  0.001
## 79             +  9   -122  263 12.83  0.001
## 112            + 11   -121  266 16.06  0.000
## 64               11   -121  266 16.11  0.000
## 80             + 10   -123  267 16.97  0.000
## 32               10   -123  267 17.24  0.000
## 128            + 12   -123  271 21.19  0.000
## 96             + 11   -124  272 22.02  0.000
## 5                 6   -139  291 41.03  0.000
## 13                7   -139  293 42.98  0.000
## 6                 7   -140  294 44.42  0.000
## 14                8   -139  295 45.51  0.000
## 10                7   -142  298 47.85  0.000
## 2                 6   -143  298 48.33  0.000
## 77             +  8   -141  298 48.51  0.000
## 30                9   -141  301 51.13  0.000
## 78             +  9   -141  301 51.18  0.000
## 26                8   -143  303 52.89  0.000
## 94             + 10   -142  306 55.77  0.000
## 1                 5   -155  320 70.45  0.000
## 9                 6   -154  321 70.93  0.000
## Models ranked by AICc(x) 
## Random terms (all models): 
## '1 | year', '1 | Region/estuary'
top_AMBI_S <- subset(set_AMBI_S, delta < 10) %>% print()
## Global model call: lme4::lmer(formula = AMBI_S ~ (scale(metals) + scale(sqrtmud) + 
##     scale(sqrtTP)) * Type + (1 | year) + (1 | Region/estuary), 
##     data = dat_mult, weights = sqrt(n))
## ---
## Model selection table 
##    (Int) scl(mtl) scl(sqr) scl(sTP) Typ scl(mtl):Typ scl(sqr):Typ df
## 3   1.93             0.289                                         6
## 43  1.89             0.387            +                         +  8
## 11  1.87             0.284            +                            7
## 4   1.93   0.0681    0.259                                         7
## 44  1.88   0.0801    0.352            +                         +  9
## 7   1.92             0.262   0.0422                                7
## 12  1.86   0.0772    0.248            +                            8
## 47  1.89             0.359   0.0462   +                         +  9
## 15  1.87             0.256   0.0429   +                            8
## 60  1.88   0.0730    0.354            +            +            + 10
##    logLik AICc delta weight
## 3    -119  250  0.00  0.486
## 43   -117  252  1.76  0.201
## 11   -119  253  3.27  0.095
## 4    -119  253  3.57  0.082
## 44   -118  254  4.17  0.060
## 7    -120  255  5.63  0.029
## 12   -120  256  6.01  0.024
## 47   -119  257  7.17  0.013
## 15   -121  259  8.89  0.006
## 60   -119  259  9.59  0.004
## Models ranked by AICc(x) 
## Random terms (all models): 
## '1 | year', '1 | Region/estuary'
ave_AMBI_S <- model.avg(top_AMBI_S)
summary(ave_AMBI_S)
## 
## Call:
## model.avg(object = top_AMBI_S)
## Warning in if (!is.na(comcallstr)) {: the condition has length > 1 and only
## the first element will be used
## Component model call: 
## ::(formula = AMBI_S ~ <10 unique rhs>, data = dat_mult, weights = 
##      sqrt(n)) 
##      lme4(formula = AMBI_S ~ <10 unique rhs>, data = dat_mult, weights 
##      = sqrt(n)) 
##      lmer(formula = AMBI_S ~ <10 unique rhs>, data = dat_mult, weights 
##      = sqrt(n))
## 
## Component models: 
##       df logLik AICc delta weight
## 2      6   -119  250  0.00   0.49
## 246    8   -117  252  1.76   0.20
## 24     7   -119  253  3.27   0.09
## 12     7   -119  253  3.57   0.08
## 1246   9   -118  254  4.17   0.06
## 23     7   -120  255  5.63   0.03
## 124    8   -120  256  6.01   0.02
## 2346   9   -119  257  7.17   0.01
## 234    8   -121  259  8.89   0.01
## 12456 10   -119  259  9.59   0.00
## 
## Term codes: 
##       scale(metals)      scale(sqrtmud)       scale(sqrtTP) 
##                   1                   2                   3 
##                Type  scale(metals):Type scale(sqrtmud):Type 
##                   4                   5                   6 
## 
## Model-averaged coefficients:  
## (full average) 
##                       Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)           1.91e+00   5.97e-02    5.99e-02   31.86   <2e-16 ***
## scale(sqrtmud)        3.09e-01   5.67e-02    5.68e-02    5.44   <2e-16 ***
## Type8                 5.13e-02   8.63e-02    8.65e-02    0.59     0.55    
## scale(sqrtmud):Type8 -4.77e-02   8.26e-02    8.26e-02    0.58     0.56    
## scale(metals)         1.26e-02   3.16e-02    3.17e-02    0.40     0.69    
## scale(sqrtTP)         2.09e-03   1.24e-02    1.25e-02    0.17     0.87    
## scale(metals):Type8   8.57e-05   5.02e-03    5.05e-03    0.02     0.99    
##  
## (conditional average) 
##                      Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)            1.9089     0.0597      0.0599   31.86   <2e-16 ***
## scale(sqrtmud)         0.3090     0.0567      0.0568    5.44   <2e-16 ***
## Type8                  0.1272     0.0937      0.0942    1.35    0.177    
## scale(sqrtmud):Type8  -0.1708     0.0582      0.0585    2.92    0.004 ** 
## scale(metals)          0.0738     0.0369      0.0371    1.99    0.047 *  
## scale(sqrtTP)          0.0434     0.0377      0.0379    1.15    0.252    
## scale(metals):Type8    0.0213     0.0762      0.0766    0.28    0.781    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Relative variable importance: 
##                      scale(sqrtmud) Type  scale(sqrtmud):Type
## Importance:              1            0.4  0.28              
## N containing models:    10              7     4              
##                      scale(metals) scale(sqrtTP) scale(metals):Type
## Importance:           0.17          0.05         <0.01             
## N containing models:     4             3             1
confint(ave_AMBI_S)
##                         2.5 %  97.5 %
## (Intercept)           1.79147  2.0264
## scale(sqrtmud)        0.19762  0.4203
## Type8                -0.05748  0.3119
## scale(sqrtmud):Type8 -0.28554 -0.0561
## scale(metals)         0.00111  0.1464
## scale(sqrtTP)        -0.03083  0.1176
## scale(metals):Type8  -0.12893  0.1715
####TBI####
global_TBI <-
  lmer(
    TBI ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type + (1|year) + (1|Region/estuary),
    data = dat_mult,
    weights = sqrt(n)
  )

set_TBI <- dredge(global_TBI, rank = 'AICc')
## Warning in dredge(global_TBI, rank = "AICc"): comparing models fitted by
## REML
## Fixed term is "(Intercept)"
top_TBI <- subset(set_TBI, delta < 10)
kable(top_TBI)
(Intercept) scale(metals) scale(sqrtmud) scale(sqrtTP) Type scale(metals):Type scale(sqrtmud):Type scale(sqrtTP):Type df logLik AICc delta weight
3 0.277 NA -0.030 NA NA NA NA NA 6 272 -531 0.00 0.920
4 0.277 -0.012 -0.024 NA NA NA NA NA 7 269 -524 7.19 0.025
11 0.274 NA -0.030 NA + NA NA NA 7 269 -524 7.32 0.024
7 0.277 NA -0.036 0.009 NA NA NA NA 7 269 -523 8.79 0.011
2 0.273 -0.026 NA NA NA NA NA NA 6 267 -522 8.98 0.010
8 0.276 -0.028 -0.034 0.025 NA NA NA NA 8 269 -522 9.22 0.009
ave_TBI <- model.avg(top_TBI)
summary(ave_TBI)
## 
## Call:
## model.avg(object = top_TBI)
## Warning in if (!is.na(comcallstr)) {: the condition has length > 1 and only
## the first element will be used
## Component model call: 
## ::(formula = TBI ~ <6 unique rhs>, data = dat_mult, weights = 
##      sqrt(n)) 
##      lme4(formula = TBI ~ <6 unique rhs>, data = dat_mult, weights = 
##      sqrt(n)) 
##      lmer(formula = TBI ~ <6 unique rhs>, data = dat_mult, weights = 
##      sqrt(n))
## 
## Component models: 
##     df logLik AICc delta weight
## 2    6    272 -531  0.00   0.92
## 12   7    269 -524  7.19   0.03
## 24   7    269 -524  7.32   0.02
## 23   7    269 -523  8.79   0.01
## 1    6    267 -522  8.98   0.01
## 123  8    269 -522  9.22   0.01
## 
## Term codes: 
##  scale(metals) scale(sqrtmud)  scale(sqrtTP)           Type 
##              1              2              3              4 
## 
## Model-averaged coefficients:  
## (full average) 
##                 Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)     0.276920   0.035453    0.035640    7.77   <2e-16 ***
## scale(sqrtmud) -0.029336   0.006611    0.006638    4.42   <2e-16 ***
## scale(metals)  -0.000831   0.004403    0.004406    0.19     0.85    
## Type8           0.000202   0.004646    0.004668    0.04     0.96    
## scale(sqrtTP)   0.000329   0.002816    0.002819    0.12     0.91    
##  
## (conditional average) 
##                Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)     0.27692    0.03545     0.03564    7.77   <2e-16 ***
## scale(sqrtmud) -0.02964    0.00593     0.00595    4.98   <2e-16 ***
## scale(metals)  -0.01857    0.01019     0.01021    1.82    0.069 .  
## Type8           0.00855    0.02900     0.02915    0.29    0.769    
## scale(sqrtTP)   0.01602    0.01161     0.01164    1.38    0.169    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Relative variable importance: 
##                      scale(sqrtmud) scale(metals) Type scale(sqrtTP)
## Importance:          0.99           0.04          0.02 0.02         
## N containing models:    5              3             1    2
confint(ave_TBI)
##                   2.5 %   97.5 %
## (Intercept)     0.20707  0.34677
## scale(sqrtmud) -0.04131 -0.01797
## scale(metals)  -0.03859  0.00145
## Type8          -0.04858  0.06568
## scale(sqrtTP)  -0.00679  0.03883
###AMBI#####
global_AMBI <-
  lmer(
    AMBI ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type++(1 |
                                                                       year) + (1 | Region / estuary),
    data = dat_mult,
    weights = sqrt(n)
  )
summary(global_AMBI)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: AMBI ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type +  
##     +(1 | year) + (1 | Region/estuary)
##    Data: dat_mult
## Weights: sqrt(n)
## 
## REML criterion at convergence: 414
## 
## Scaled residuals: 
##    Min     1Q Median     3Q    Max 
## -3.044 -0.556 -0.073  0.475  3.555 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  estuary:Region (Intercept) 0.048986 0.2213  
##  year           (Intercept) 0.000888 0.0298  
##  Region         (Intercept) 0.000000 0.0000  
##  Residual                   0.719940 0.8485  
## Number of obs: 237, groups:  estuary:Region, 24; year, 15; Region, 4
## 
## Fixed effects:
##                       Estimate Std. Error        df t value Pr(>|t|)    
## (Intercept)            1.76606    0.08373  10.60000   21.09  5.3e-10 ***
## scale(metals)          0.08404    0.07795 113.10000    1.08    0.283    
## scale(sqrtmud)         0.35698    0.07404  90.90000    4.82  5.7e-06 ***
## scale(sqrtTP)         -0.00983    0.09286 149.10000   -0.11    0.916    
## Type8                  0.27705    0.12559  12.70000    2.21    0.046 *  
## scale(metals):Type8    0.02905    0.13300 166.00000    0.22    0.827    
## scale(sqrtmud):Type8  -0.17800    0.10634 102.30000   -1.67    0.097 .  
## scale(sqrtTP):Type8   -0.00299    0.13031 161.80000   -0.02    0.982    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) scl(m) scl(s) sc(TP) Type8  scl(m):T8 scl(s):T8
## scale(mtls) -0.041                                                
## scl(sqrtmd)  0.053  0.000                                         
## scl(sqrtTP)  0.013 -0.563 -0.457                                  
## Type8       -0.660  0.028 -0.037 -0.009                           
## scl(mtl):T8  0.025 -0.584 -0.001  0.329  0.119                    
## scl(sqr):T8 -0.037  0.000 -0.694  0.318 -0.037 -0.142             
## scl(sTP):T8 -0.010  0.399  0.325 -0.711 -0.084 -0.563    -0.430
set_AMBI <- dredge(global_AMBI, rank = 'AICc') %>% print()
## Warning in dredge(global_AMBI, rank = "AICc"): comparing models fitted by
## REML
## Fixed term is "(Intercept)"
## Global model call: lme4::lmer(formula = AMBI ~ (scale(metals) + scale(sqrtmud) + 
##     scale(sqrtTP)) * Type + +(1 | year) + (1 | Region/estuary), 
##     data = dat_mult, weights = sqrt(n))
## ---
## Model selection table 
##     (Int) scl(mtl) scl(sqr) scl(sTP) Typ scl(mtl):Typ scl(sqr):Typ
## 3    1.87             0.302                                       
## 11   1.75             0.291            +                          
## 43   1.77             0.382            +                         +
## 12   1.75   0.0812    0.255            +                          
## 4    1.88   0.0672    0.273                                       
## 7    1.87             0.275  0.04263                              
## 15   1.75             0.263  0.04406   +                          
## 44   1.76   0.0881    0.348            +                         +
## 47   1.77             0.354  0.04802   +                         +
## 28   1.75   0.1036    0.263            +            +             
## 16   1.75   0.0870    0.259 -0.01080   +                          
## 79   1.76             0.271  0.09028   +                          
## 8    1.87   0.0663    0.272  0.00154                              
## 60   1.76   0.0790    0.351            +            +            +
## 48   1.76   0.0932    0.352 -0.00923   +                         +
## 111  1.77             0.355  0.04791   +                         +
## 80   1.75   0.0849    0.266  0.03501   +                          
## 32   1.75   0.1068    0.266 -0.00613   +            +             
## 64   1.77   0.0847    0.357 -0.01127   +            +            +
## 112  1.76   0.0938    0.356 -0.01637   +                         +
## 96   1.75   0.0845    0.267  0.03559   +            +             
## 128  1.77   0.0840    0.357 -0.00983   +            +            +
## 13   1.74                    0.21090   +                          
## 5    1.87                    0.21790                              
## 10   1.73   0.2135                     +                          
## 14   1.73   0.0993           0.14660   +                          
## 6    1.88   0.0830           0.16510                              
## 77   1.74                    0.23740   +                          
## 2    1.90   0.2125                                                
## 26   1.73   0.1853                     +            +             
## 30   1.73   0.0935           0.14430   +            +             
## 78   1.73   0.0989           0.17190   +                          
## 94   1.74   0.0669           0.19340   +            +             
## 9    1.74                              +                          
## 1    1.90                                                         
##     scl(sTP):Typ df logLik AICc delta weight
## 3                 6   -203  418  0.00  0.373
## 11                7   -202  418  0.20  0.338
## 43                8   -202  421  2.44  0.110
## 12                8   -203  422  3.95  0.052
## 4                 7   -204  423  4.56  0.038
## 7                 7   -205  424  5.52  0.024
## 15                8   -204  424  5.73  0.021
## 44                9   -203  424  5.88  0.020
## 47                9   -204  426  7.83  0.007
## 28                9   -204  427  8.69  0.005
## 16                9   -205  428  9.79  0.003
## 79             +  9   -205  428 10.02  0.002
## 8                 8   -206  429 10.32  0.002
## 60               10   -204  429 10.61  0.002
## 48               10   -204  430 11.69  0.001
## 111            + 10   -205  431 12.65  0.001
## 80             + 10   -206  432 14.21  0.000
## 32               10   -206  433 14.52  0.000
## 64               11   -206  435 16.41  0.000
## 112            + 11   -206  435 16.50  0.000
## 96             + 11   -207  437 18.64  0.000
## 128            + 12   -207  439 20.87  0.000
## 13                7   -213  441 23.05  0.000
## 5                 6   -215  442 23.56  0.000
## 10                7   -215  445 26.36  0.000
## 14                8   -214  445 26.64  0.000
## 6                 7   -216  446 27.80  0.000
## 77             +  8   -215  446 27.97  0.000
## 2                 6   -217  447 28.86  0.000
## 26                8   -216  449 30.95  0.000
## 30                9   -216  450 31.61  0.000
## 78             +  9   -216  450 31.61  0.000
## 94             + 10   -216  454 35.50  0.000
## 9                 6   -222  457 38.66  0.000
## 1                 5   -224  458 40.16  0.000
## Models ranked by AICc(x) 
## Random terms (all models): 
## '1 | year', '1 | Region/estuary'
top_AMBI <- subset(set_AMBI, delta < 10) %>% print()
## Global model call: lme4::lmer(formula = AMBI ~ (scale(metals) + scale(sqrtmud) + 
##     scale(sqrtTP)) * Type + +(1 | year) + (1 | Region/estuary), 
##     data = dat_mult, weights = sqrt(n))
## ---
## Model selection table 
##    (Int) scl(mtl) scl(sqr) scl(sTP) Typ scl(mtl):Typ scl(sqr):Typ df
## 3   1.87             0.302                                         6
## 11  1.75             0.291            +                            7
## 43  1.77             0.382            +                         +  8
## 12  1.75   0.0812    0.255            +                            8
## 4   1.88   0.0672    0.273                                         7
## 7   1.87             0.275   0.0426                                7
## 15  1.75             0.263   0.0441   +                            8
## 44  1.76   0.0881    0.348            +                         +  9
## 47  1.77             0.354   0.0480   +                         +  9
## 28  1.75   0.1036    0.263            +            +               9
## 16  1.75   0.0870    0.259  -0.0108   +                            9
##    logLik AICc delta weight
## 3    -203  418  0.00  0.376
## 11   -202  418  0.20  0.341
## 43   -202  421  2.44  0.111
## 12   -203  422  3.95  0.052
## 4    -204  423  4.56  0.039
## 7    -205  424  5.52  0.024
## 15   -204  424  5.73  0.021
## 44   -203  424  5.88  0.020
## 47   -204  426  7.83  0.007
## 28   -204  427  8.69  0.005
## 16   -205  428  9.79  0.003
## Models ranked by AICc(x) 
## Random terms (all models): 
## '1 | year', '1 | Region/estuary'
ave_AMBI <- model.avg(top_AMBI)
summary(ave_AMBI_S)
## 
## Call:
## model.avg(object = top_AMBI_S)
## Warning in if (!is.na(comcallstr)) {: the condition has length > 1 and only
## the first element will be used
## Component model call: 
## ::(formula = AMBI_S ~ <10 unique rhs>, data = dat_mult, weights = 
##      sqrt(n)) 
##      lme4(formula = AMBI_S ~ <10 unique rhs>, data = dat_mult, weights 
##      = sqrt(n)) 
##      lmer(formula = AMBI_S ~ <10 unique rhs>, data = dat_mult, weights 
##      = sqrt(n))
## 
## Component models: 
##       df logLik AICc delta weight
## 2      6   -119  250  0.00   0.49
## 246    8   -117  252  1.76   0.20
## 24     7   -119  253  3.27   0.09
## 12     7   -119  253  3.57   0.08
## 1246   9   -118  254  4.17   0.06
## 23     7   -120  255  5.63   0.03
## 124    8   -120  256  6.01   0.02
## 2346   9   -119  257  7.17   0.01
## 234    8   -121  259  8.89   0.01
## 12456 10   -119  259  9.59   0.00
## 
## Term codes: 
##       scale(metals)      scale(sqrtmud)       scale(sqrtTP) 
##                   1                   2                   3 
##                Type  scale(metals):Type scale(sqrtmud):Type 
##                   4                   5                   6 
## 
## Model-averaged coefficients:  
## (full average) 
##                       Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)           1.91e+00   5.97e-02    5.99e-02   31.86   <2e-16 ***
## scale(sqrtmud)        3.09e-01   5.67e-02    5.68e-02    5.44   <2e-16 ***
## Type8                 5.13e-02   8.63e-02    8.65e-02    0.59     0.55    
## scale(sqrtmud):Type8 -4.77e-02   8.26e-02    8.26e-02    0.58     0.56    
## scale(metals)         1.26e-02   3.16e-02    3.17e-02    0.40     0.69    
## scale(sqrtTP)         2.09e-03   1.24e-02    1.25e-02    0.17     0.87    
## scale(metals):Type8   8.57e-05   5.02e-03    5.05e-03    0.02     0.99    
##  
## (conditional average) 
##                      Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)            1.9089     0.0597      0.0599   31.86   <2e-16 ***
## scale(sqrtmud)         0.3090     0.0567      0.0568    5.44   <2e-16 ***
## Type8                  0.1272     0.0937      0.0942    1.35    0.177    
## scale(sqrtmud):Type8  -0.1708     0.0582      0.0585    2.92    0.004 ** 
## scale(metals)          0.0738     0.0369      0.0371    1.99    0.047 *  
## scale(sqrtTP)          0.0434     0.0377      0.0379    1.15    0.252    
## scale(metals):Type8    0.0213     0.0762      0.0766    0.28    0.781    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Relative variable importance: 
##                      scale(sqrtmud) Type  scale(sqrtmud):Type
## Importance:              1            0.4  0.28              
## N containing models:    10              7     4              
##                      scale(metals) scale(sqrtTP) scale(metals):Type
## Importance:           0.17          0.05         <0.01             
## N containing models:     4             3             1
confint(ave_AMBI_S)
##                         2.5 %  97.5 %
## (Intercept)           1.79147  2.0264
## scale(sqrtmud)        0.19762  0.4203
## Type8                -0.05748  0.3119
## scale(sqrtmud):Type8 -0.28554 -0.0561
## scale(metals)         0.00111  0.1464
## scale(sqrtTP)        -0.03083  0.1176
## scale(metals):Type8  -0.12893  0.1715
###BQI#####
global_BQI <-
  lmer(
    BQI ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type + (1|year) + (1|Region/estuary),
    data = dat_mult,
    weights = sqrt(n)
  )
summary(global_BQI)
## Linear mixed model fit by REML t-tests use Satterthwaite approximations
##   to degrees of freedom [lmerMod]
## Formula: BQI ~ (scale(metals) + scale(sqrtmud) + scale(sqrtTP)) * Type +  
##     (1 | year) + (1 | Region/estuary)
##    Data: dat_mult
## Weights: sqrt(n)
## 
## REML criterion at convergence: 688
## 
## Scaled residuals: 
##     Min      1Q  Median      3Q     Max 
## -2.8073 -0.6246  0.0042  0.6746  2.2035 
## 
## Random effects:
##  Groups         Name        Variance Std.Dev.
##  estuary:Region (Intercept) 0.6921   0.832   
##  year           (Intercept) 0.0235   0.153   
##  Region         (Intercept) 1.4180   1.191   
##  Residual                   2.0693   1.438   
## Number of obs: 237, groups:  estuary:Region, 24; year, 15; Region, 4
## 
## Fixed effects:
##                      Estimate Std. Error       df t value Pr(>|t|)   
## (Intercept)            5.0245     0.6529   3.0000    7.70   0.0044 **
## scale(metals)         -0.3404     0.1505 205.1000   -2.26   0.0247 * 
## scale(sqrtmud)        -0.3366     0.1468 210.7000   -2.29   0.0229 * 
## scale(sqrtTP)         -0.0379     0.1777 219.3000   -0.21   0.8311   
## Type8                 -0.4843     0.4177  20.4000   -1.16   0.2597   
## scale(metals):Type8   -0.0332     0.2503 222.4000   -0.13   0.8947   
## scale(sqrtmud):Type8  -0.2201     0.2084 226.8000   -1.06   0.2920   
## scale(sqrtTP):Type8    0.4905     0.2459 218.0000    1.99   0.0473 * 
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Correlation of Fixed Effects:
##             (Intr) scl(m) scl(s) sc(TP) Type8  scl(m):T8 scl(s):T8
## scale(mtls) -0.024                                                
## scl(sqrtmd) -0.001  0.052                                         
## scl(sqrtTP)  0.021 -0.611 -0.463                                  
## Type8       -0.248  0.021 -0.081 -0.015                           
## scl(mtl):T8  0.002 -0.574 -0.039  0.350  0.121                    
## scl(sqr):T8 -0.004 -0.038 -0.698  0.325  0.037 -0.106             
## scl(sTP):T8 -0.005  0.423  0.337 -0.710 -0.081 -0.565    -0.469
set_BQI <- dredge(global_BQI, rank = 'AICc')
## Warning in dredge(global_BQI, rank = "AICc"): comparing models fitted by
## REML
## Fixed term is "(Intercept)"
top_BQI <- subset(set_BQI, delta < 10)
kable(top_BQI)
(Intercept) scale(metals) scale(sqrtmud) scale(sqrtTP) Type scale(metals):Type scale(sqrtmud):Type scale(sqrtTP):Type df logLik AICc delta weight
4 4.87 -0.252 -0.334 NA NA NA NA NA 7 -346 706 0.00 0.227
12 5.01 -0.257 -0.327 NA + NA NA NA 8 -345 708 1.24 0.122
3 4.88 NA -0.453 NA NA NA NA NA 6 -348 708 1.38 0.114
8 4.86 -0.378 -0.421 0.217 NA NA NA NA 8 -346 708 1.50 0.107
80 5.02 -0.369 -0.449 0.040 + NA NA + 10 -344 708 1.95 0.086
16 5.04 -0.392 -0.418 0.230 + NA NA NA 9 -345 709 2.43 0.067
28 5.01 -0.350 -0.369 NA + + NA NA 9 -345 709 2.80 0.056
11 4.99 NA -0.447 NA + NA NA NA 7 -347 709 2.89 0.053
112 5.03 -0.352 -0.338 -0.030 + NA + + 11 -344 711 4.32 0.026
32 5.03 -0.463 -0.449 0.213 + + NA NA 10 -345 711 4.49 0.024
44 5.01 -0.263 -0.387 NA + NA + NA 9 -346 711 4.80 0.021
96 5.02 -0.348 -0.445 0.024 + + NA + 11 -344 711 5.03 0.018
48 5.03 -0.394 -0.467 0.226 + NA + NA 10 -346 712 6.14 0.011
79 4.97 NA -0.475 -0.205 + NA NA + 9 -347 713 6.19 0.010
7 4.88 NA -0.447 -0.008 NA NA NA NA 7 -349 713 6.21 0.010
60 5.01 -0.353 -0.359 NA + + + NA 10 -346 713 6.50 0.009
43 4.99 NA -0.489 NA + NA + NA 8 -348 713 6.67 0.008
2 4.81 -0.438 NA NA NA NA NA NA 6 -350 713 6.99 0.007
128 5.02 -0.340 -0.337 -0.038 + + + + 12 -344 714 7.45 0.005
10 5.00 -0.438 NA NA + NA NA NA 7 -350 714 7.67 0.005
111 4.98 NA -0.326 -0.283 + NA + + 10 -347 714 7.71 0.005
15 4.99 NA -0.443 -0.006 + NA NA NA 8 -349 714 7.74 0.005
64 5.03 -0.467 -0.437 0.213 + + + NA 11 -346 715 8.21 0.004
ave_BQI <- model.avg(top_BQI)
summary(ave_BQI)
## 
## Call:
## model.avg(object = top_BQI)
## Warning in if (!is.na(comcallstr)) {: the condition has length > 1 and only
## the first element will be used
## Component model call: 
## ::(formula = BQI ~ <23 unique rhs>, data = dat_mult, weights = 
##      sqrt(n)) 
##      lme4(formula = BQI ~ <23 unique rhs>, data = dat_mult, weights = 
##      sqrt(n)) 
##      lmer(formula = BQI ~ <23 unique rhs>, data = dat_mult, weights = 
##      sqrt(n))
## 
## Component models: 
##         df logLik AICc delta weight
## 12       7   -346  706  0.00   0.23
## 124      8   -345  708  1.24   0.12
## 2        6   -348  708  1.38   0.11
## 123      8   -346  708  1.50   0.11
## 12347   10   -344  708  1.95   0.09
## 1234     9   -345  709  2.43   0.07
## 1245     9   -345  709  2.80   0.06
## 24       7   -347  709  2.89   0.05
## 123467  11   -344  711  4.32   0.03
## 12345   10   -345  711  4.49   0.02
## 1246     9   -346  711  4.80   0.02
## 123457  11   -344  711  5.03   0.02
## 12346   10   -346  712  6.14   0.01
## 2347     9   -347  713  6.19   0.01
## 23       7   -349  713  6.21   0.01
## 12456   10   -346  713  6.50   0.01
## 246      8   -348  713  6.67   0.01
## 1        6   -350  713  6.99   0.01
## 1234567 12   -344  714  7.45   0.01
## 14       7   -350  714  7.67   0.00
## 23467   10   -347  714  7.71   0.00
## 234      8   -349  714  7.74   0.00
## 123456  11   -346  715  8.21   0.00
## 
## Term codes: 
##       scale(metals)      scale(sqrtmud)       scale(sqrtTP) 
##                   1                   2                   3 
##                Type  scale(metals):Type scale(sqrtmud):Type 
##                   4                   5                   6 
##  scale(sqrtTP):Type 
##                   7 
## 
## Model-averaged coefficients:  
## (full average) 
##                      Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)           4.94596    0.60385     0.60701    8.15   <2e-16 ***
## scale(metals)        -0.25478    0.17397     0.17428    1.46    0.144    
## scale(sqrtmud)       -0.38797    0.11916     0.11959    3.24    0.001 ***
## Type8                -0.21270    0.37030     0.37169    0.57    0.567    
## scale(sqrtTP)         0.04638    0.12829     0.12859    0.36    0.718    
## scale(sqrtTP):Type8   0.05693    0.15382     0.15399    0.37    0.712    
## scale(metals):Type8   0.02276    0.10192     0.10216    0.22    0.824    
## scale(sqrtmud):Type8 -0.00508    0.07295     0.07317    0.07    0.945    
##  
## (conditional average) 
##                      Estimate Std. Error Adjusted SE z value Pr(>|z|)    
## (Intercept)            4.9460     0.6038      0.6070    8.15   <2e-16 ***
## scale(metals)         -0.3206     0.1304      0.1309    2.45    0.014 *  
## scale(sqrtmud)        -0.3926     0.1120      0.1125    3.49   <2e-16 ***
## Type8                 -0.3975     0.4276      0.4298    0.92    0.355    
## scale(sqrtTP)          0.1225     0.1848      0.1853    0.66    0.509    
## scale(sqrtTP):Type8    0.3775     0.1894      0.1903    1.98    0.047 *  
## scale(metals):Type8    0.1958     0.2355      0.2364    0.83    0.407    
## scale(sqrtmud):Type8  -0.0576     0.2394      0.2401    0.24    0.810    
## ---
## Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
## 
## Relative variable importance: 
##                      scale(sqrtmud) scale(metals) Type scale(sqrtTP)
## Importance:          0.99           0.79          0.54 0.38         
## N containing models:   21             16            18   13         
##                      scale(sqrtTP):Type scale(metals):Type
## Importance:          0.15               0.12              
## N containing models:    6                  6              
##                      scale(sqrtmud):Type
## Importance:          0.09               
## N containing models:    8
confint(ave_BQI)
##                         2.5 %  97.5 %
## (Intercept)           3.75625  6.1357
## scale(metals)        -0.57707 -0.0641
## scale(sqrtmud)       -0.61309 -0.1721
## Type8                -1.23986  0.4449
## scale(sqrtTP)        -0.24076  0.4857
## scale(sqrtTP):Type8   0.00442  0.7505
## scale(metals):Type8  -0.26753  0.6592
## scale(sqrtmud):Type8 -0.52828  0.4130