###load libraries and read truncated indices data####
suppressPackageStartupMessages(library(tidyverse))
## Warning: package 'tidyverse' was built under R version 3.3.3
## Warning: package 'purrr' was built under R version 3.3.3
library(broom)
library(readr)
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)

all_ind<- read_csv('all_indices_truncated.csv',col_types =  cols(Date = 'D')) %>% 
  mutate(Type = factor(Type),
         logTOC = log(TOC+1))
dat_simple <- 
  all_ind %>%
  gather(index, value,AMBI:MEDOCC,BQI:TBI,logN,S) 

###Mud simple regression
simple_mud <- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index2 = lm(value ~ sqrtmud,data = .,weights = sqrt(n)))

coef_mud <- tidy(simple_mud, fit_index2,conf.int = T)
summ_mud <- glance(simple_mud, fit_index2)
kable(coef_mud)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.378 0.051 27.25 0 1.279 1.478
AMBI sqrtmud 0.170 0.012 14.61 0 0.147 0.193
AMBI_S (Intercept) 1.446 0.036 39.75 0 1.374 1.517
AMBI_S sqrtmud 0.162 0.008 19.45 0 0.146 0.179
BENTIX (Intercept) 5.204 0.078 66.63 0 5.051 5.358
BENTIX sqrtmud -0.232 0.018 -12.93 0 -0.267 -0.197
BQI (Intercept) 6.394 0.112 57.19 0 6.175 6.614
BQI sqrtmud -0.335 0.026 -13.03 0 -0.385 -0.284
ITI (Intercept) 34.826 1.122 31.03 0 32.622 37.031
ITI sqrtmud -1.360 0.258 -5.28 0 -1.866 -0.853
logN (Intercept) 4.613 0.067 68.48 0 4.480 4.745
logN sqrtmud -0.085 0.015 -5.49 0 -0.115 -0.055
M_AMBI (Intercept) 0.646 0.008 81.34 0 0.630 0.662
M_AMBI sqrtmud -0.027 0.002 -14.91 0 -0.031 -0.024
MEDOCC (Intercept) 1.857 0.066 28.25 0 1.728 1.986
MEDOCC sqrtmud 0.209 0.015 13.87 0 0.180 0.239
S (Intercept) 14.590 0.327 44.62 0 13.948 15.232
S sqrtmud -0.865 0.075 -11.52 0 -1.012 -0.717
TBI (Intercept) 0.391 0.010 40.77 0 0.372 0.410
TBI sqrtmud -0.023 0.002 -10.40 0 -0.027 -0.019
kable(summ_mud)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.284 0.283 1.013 213.3 0 2 -504 1014 1027 551.6 537
AMBI_S 0.413 0.412 0.729 378.3 0 2 -326 658 671 285.0 537
BENTIX 0.237 0.236 1.565 167.2 0 2 -738 1482 1495 1314.9 537
BQI 0.240 0.239 2.240 169.8 0 2 -931 1869 1882 2694.2 537
ITI 0.049 0.047 22.484 27.8 0 2 -2174 4355 4368 271458.9 537
logN 0.053 0.051 1.349 30.1 0 2 -658 1323 1335 977.9 537
M_AMBI 0.293 0.292 0.159 222.4 0 2 494 -982 -969 13.6 537
MEDOCC 0.264 0.262 1.316 192.4 0 2 -645 1296 1309 930.6 537
S 0.198 0.197 6.551 132.6 0 2 -1510 3026 3038 23042.7 537
TBI 0.168 0.166 0.192 108.1 0 2 392 -778 -765 19.8 537
###Metals simple regression
simple_metals <- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index1 = lm(value ~ metals,data = .,weights = sqrt(n)))

coef_metals <- tidy(simple_metals, fit_index1,conf.int = T)
summ_metals <- glance(simple_metals, fit_index1)
kable(coef_metals)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.852 0.038 48.65 0.000 1.777 1.927
AMBI metals 0.063 0.014 4.44 0.000 0.035 0.090
AMBI_S (Intercept) 1.929 0.028 68.68 0.000 1.874 1.985
AMBI_S metals 0.065 0.010 6.30 0.000 0.045 0.086
BENTIX (Intercept) 4.598 0.058 78.76 0.000 4.483 4.713
BENTIX metals -0.073 0.022 -3.38 0.001 -0.116 -0.030
BQI (Intercept) 4.869 0.089 54.90 0.000 4.695 5.044
BQI metals -0.162 0.033 -4.95 0.000 -0.227 -0.098
ITI (Intercept) 31.610 0.788 40.13 0.000 30.059 33.160
ITI metals 0.332 0.291 1.14 0.255 -0.241 0.906
logN (Intercept) 4.231 0.056 75.96 0.000 4.122 4.341
logN metals -0.062 0.021 -3.00 0.003 -0.102 -0.021
M_AMBI (Intercept) 0.538 0.006 91.65 0.000 0.526 0.549
M_AMBI metals -0.013 0.002 -6.05 0.000 -0.017 -0.009
MEDOCC (Intercept) 2.426 0.049 49.36 0.000 2.329 2.523
MEDOCC metals 0.068 0.018 3.73 0.000 0.032 0.104
S (Intercept) 10.745 0.249 43.16 0.000 10.255 11.235
S metals -0.465 0.092 -5.04 0.000 -0.646 -0.283
TBI (Intercept) 0.278 0.007 42.05 0.000 0.265 0.292
TBI metals -0.011 0.002 -4.68 0.000 -0.016 -0.007
kable(coef_metals)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.852 0.038 48.65 0.000 1.777 1.927
AMBI metals 0.063 0.014 4.44 0.000 0.035 0.090
AMBI_S (Intercept) 1.929 0.028 68.68 0.000 1.874 1.985
AMBI_S metals 0.065 0.010 6.30 0.000 0.045 0.086
BENTIX (Intercept) 4.598 0.058 78.76 0.000 4.483 4.713
BENTIX metals -0.073 0.022 -3.38 0.001 -0.116 -0.030
BQI (Intercept) 4.869 0.089 54.90 0.000 4.695 5.044
BQI metals -0.162 0.033 -4.95 0.000 -0.227 -0.098
ITI (Intercept) 31.610 0.788 40.13 0.000 30.059 33.160
ITI metals 0.332 0.291 1.14 0.255 -0.241 0.906
logN (Intercept) 4.231 0.056 75.96 0.000 4.122 4.341
logN metals -0.062 0.021 -3.00 0.003 -0.102 -0.021
M_AMBI (Intercept) 0.538 0.006 91.65 0.000 0.526 0.549
M_AMBI metals -0.013 0.002 -6.05 0.000 -0.017 -0.009
MEDOCC (Intercept) 2.426 0.049 49.36 0.000 2.329 2.523
MEDOCC metals 0.068 0.018 3.73 0.000 0.032 0.104
S (Intercept) 10.745 0.249 43.16 0.000 10.255 11.235
S metals -0.465 0.092 -5.04 0.000 -0.646 -0.283
TBI (Intercept) 0.278 0.007 42.05 0.000 0.265 0.292
TBI metals -0.011 0.002 -4.68 0.000 -0.016 -0.007
###sqrtTP simple regression
simple_sqrtTP<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index3 = lm(value ~ sqrtTP,data = .,weights = sqrt(n)))

coef_sqrtTP <- tidy(simple_sqrtTP, fit_index3,conf.int = T)
summ_sqrtTP <-  glance(simple_sqrtTP, fit_index3)
kable(coef_sqrtTP)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.044 0.165 6.33 0.000 0.719 1.369
AMBI sqrtTP 0.044 0.009 5.04 0.000 0.027 0.061
AMBI_S (Intercept) 1.111 0.121 9.20 0.000 0.873 1.349
AMBI_S sqrtTP 0.044 0.006 6.95 0.000 0.032 0.057
BENTIX (Intercept) 5.372 0.258 20.81 0.000 4.864 5.881
BENTIX sqrtTP -0.040 0.014 -2.96 0.003 -0.067 -0.013
BQI (Intercept) 6.345 0.415 15.28 0.000 5.527 7.164
BQI sqrtTP -0.083 0.022 -3.80 0.000 -0.126 -0.040
ITI (Intercept) 25.438 3.384 7.52 0.000 18.772 32.104
ITI sqrtTP 0.394 0.177 2.22 0.027 0.045 0.744
logN (Intercept) 4.663 0.269 17.36 0.000 4.134 5.192
logN sqrtTP -0.025 0.014 -1.81 0.071 -0.053 0.002
M_AMBI (Intercept) 0.670 0.027 24.84 0.000 0.616 0.723
M_AMBI sqrtTP -0.007 0.001 -5.07 0.000 -0.010 -0.004
MEDOCC (Intercept) 1.482 0.215 6.88 0.000 1.058 1.906
MEDOCC sqrtTP 0.051 0.011 4.52 0.000 0.029 0.073
S (Intercept) 14.908 1.172 12.72 0.000 12.599 17.217
S sqrtTP -0.230 0.061 -3.74 0.000 -0.351 -0.109
TBI (Intercept) 0.373 0.030 12.32 0.000 0.313 0.432
TBI sqrtTP -0.006 0.002 -3.47 0.001 -0.009 -0.002
kable(summ_sqrtTP)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.096 0.092 0.972 25.44 0.000 2 -222 450 461 226.94 240
AMBI_S 0.168 0.164 0.712 48.30 0.000 2 -147 299 310 121.60 240
BENTIX 0.035 0.031 1.521 8.76 0.003 2 -330 667 677 555.20 240
BQI 0.057 0.053 2.448 14.41 0.000 2 -446 897 908 1437.92 240
ITI 0.020 0.016 19.940 4.94 0.027 2 -953 1912 1923 95426.55 240
logN 0.013 0.009 1.582 3.28 0.071 2 -340 686 697 600.94 240
M_AMBI 0.097 0.093 0.159 25.69 0.000 2 216 -427 -416 6.05 240
MEDOCC 0.079 0.075 1.269 20.45 0.000 2 -287 579 590 386.22 240
S 0.055 0.051 6.908 14.02 0.000 2 -697 1399 1410 11451.69 240
TBI 0.048 0.044 0.178 12.02 0.001 2 188 -371 -360 7.63 240
###Region simple regression
simple_region<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index4 = lm(value ~ Region,data = .,weights = sqrt(n)))

coef_region <- tidy(simple_region, fit_index4,conf.int = T)
summ_region <- glance(simple_region, fit_index4)
kable(coef_region)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.884 0.090 20.952 0.000 1.707 2.061
AMBI RegionEastern North Island -0.024 0.134 -0.178 0.858 -0.288 0.240
AMBI RegionNorth Eastern 0.140 0.101 1.387 0.166 -0.058 0.338
AMBI RegionSouthern 0.305 0.114 2.669 0.008 0.081 0.530
AMBI RegionWestern North Island 0.061 0.120 0.510 0.610 -0.174 0.296
AMBI_S (Intercept) 1.947 0.071 27.380 0.000 1.807 2.087
AMBI_S RegionEastern North Island 0.048 0.106 0.447 0.655 -0.161 0.256
AMBI_S RegionNorth Eastern 0.130 0.080 1.625 0.105 -0.027 0.286
AMBI_S RegionSouthern 0.253 0.090 2.798 0.005 0.075 0.431
AMBI_S RegionWestern North Island -0.041 0.095 -0.437 0.663 -0.227 0.145
BENTIX (Intercept) 4.547 0.133 34.310 0.000 4.287 4.807
BENTIX RegionEastern North Island 0.405 0.198 2.044 0.041 0.016 0.794
BENTIX RegionNorth Eastern -0.226 0.149 -1.522 0.129 -0.518 0.066
BENTIX RegionSouthern -0.437 0.169 -2.596 0.010 -0.768 -0.106
BENTIX RegionWestern North Island -0.412 0.176 -2.335 0.020 -0.758 -0.065
BQI (Intercept) 5.128 0.166 30.934 0.000 4.803 5.454
BQI RegionEastern North Island -1.788 0.248 -7.220 0.000 -2.275 -1.302
BQI RegionNorth Eastern 0.427 0.186 2.298 0.022 0.062 0.792
BQI RegionSouthern -0.815 0.211 -3.868 0.000 -1.229 -0.401
BQI RegionWestern North Island 0.975 0.221 4.422 0.000 0.542 1.408
ITI (Intercept) 29.885 1.646 18.155 0.000 26.651 33.119
ITI RegionEastern North Island 13.064 2.460 5.312 0.000 8.233 17.896
ITI RegionNorth Eastern -0.916 1.845 -0.496 0.620 -4.541 2.709
ITI RegionSouthern -0.303 2.093 -0.145 0.885 -4.414 3.809
ITI RegionWestern North Island -5.897 2.190 -2.693 0.007 -10.199 -1.596
logN (Intercept) 3.993 0.094 42.648 0.000 3.809 4.177
logN RegionEastern North Island -0.755 0.140 -5.394 0.000 -1.029 -0.480
logN RegionNorth Eastern 0.504 0.105 4.800 0.000 0.298 0.710
logN RegionSouthern 0.514 0.119 4.317 0.000 0.280 0.748
logN RegionWestern North Island 0.334 0.125 2.679 0.008 0.089 0.578
M_AMBI (Intercept) 0.554 0.013 41.533 0.000 0.528 0.580
M_AMBI RegionEastern North Island -0.085 0.020 -4.287 0.000 -0.125 -0.046
M_AMBI RegionNorth Eastern 0.011 0.015 0.731 0.465 -0.018 0.040
M_AMBI RegionSouthern -0.067 0.017 -3.940 0.000 -0.100 -0.034
M_AMBI RegionWestern North Island 0.040 0.018 2.276 0.023 0.006 0.075
MEDOCC (Intercept) 2.488 0.115 21.674 0.000 2.263 2.714
MEDOCC RegionEastern North Island -0.141 0.172 -0.824 0.411 -0.478 0.196
MEDOCC RegionNorth Eastern 0.165 0.129 1.280 0.201 -0.088 0.417
MEDOCC RegionSouthern 0.398 0.146 2.726 0.007 0.111 0.685
MEDOCC RegionWestern North Island 0.089 0.153 0.585 0.559 -0.211 0.389
S (Intercept) 11.085 0.496 22.366 0.000 10.111 12.059
S RegionEastern North Island -4.596 0.741 -6.206 0.000 -6.051 -3.141
S RegionNorth Eastern 1.410 0.556 2.538 0.011 0.319 2.502
S RegionSouthern -1.340 0.630 -2.126 0.034 -2.578 -0.102
S RegionWestern North Island 2.173 0.659 3.295 0.001 0.878 3.468
TBI (Intercept) 0.302 0.014 22.167 0.000 0.275 0.328
TBI RegionEastern North Island -0.138 0.020 -6.806 0.000 -0.178 -0.098
TBI RegionNorth Eastern 0.049 0.015 3.188 0.002 0.019 0.079
TBI RegionSouthern -0.072 0.017 -4.189 0.000 -0.106 -0.039
TBI RegionWestern North Island 0.058 0.018 3.203 0.001 0.022 0.094
kable(summ_region)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.021 0.014 1.189 2.86 0.023 5 -588 1189 1214 754.5 534
AMBI_S 0.029 0.021 0.940 3.92 0.004 5 -462 936 962 472.0 534
BENTIX 0.050 0.042 1.752 6.95 0.000 5 -797 1607 1633 1639.0 534
BQI 0.277 0.271 2.192 51.09 0.000 5 -918 1848 1874 2564.6 534
ITI 0.114 0.108 21.760 17.25 0.000 5 -2155 4323 4348 252856.9 534
logN 0.208 0.202 1.238 35.07 0.000 5 -610 1232 1258 817.9 534
M_AMBI 0.136 0.130 0.176 21.02 0.000 5 440 -868 -842 16.6 534
MEDOCC 0.027 0.020 1.517 3.73 0.005 5 -720 1452 1478 1229.7 534
S 0.202 0.196 6.552 33.84 0.000 5 -1508 3029 3054 22922.3 534
TBI 0.275 0.269 0.180 50.62 0.000 5 429 -847 -821 17.3 534
###AFDW simple regression
simple_logAFDW<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index5 = lm(value ~ logAFDW,data = .,weights = sqrt(n)))

coef_logAFDW <- tidy(simple_logAFDW, fit_index5,conf.int = T)
summ_logAFDW <- glance(simple_logAFDW, fit_index5)
kable(coef_logAFDW)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.738 0.036 48.881 0.000 1.668 1.808
AMBI logAFDW 0.342 0.044 7.798 0.000 0.256 0.429
AMBI_S (Intercept) 1.776 0.026 67.280 0.000 1.724 1.828
AMBI_S logAFDW 0.372 0.033 11.406 0.000 0.308 0.436
BENTIX (Intercept) 4.669 0.058 80.191 0.000 4.554 4.783
BENTIX logAFDW -0.447 0.072 -6.214 0.000 -0.588 -0.305
BQI (Intercept) 5.617 0.089 62.953 0.000 5.442 5.793
BQI logAFDW -0.468 0.110 -4.251 0.000 -0.685 -0.252
ITI (Intercept) 31.128 0.858 36.301 0.000 29.442 32.814
ITI logAFDW -2.164 1.059 -2.043 0.042 -4.246 -0.082
logN (Intercept) 4.286 0.048 89.957 0.000 4.193 4.380
logN logAFDW 0.020 0.059 0.342 0.733 -0.096 0.136
M_AMBI (Intercept) 0.586 0.006 97.208 0.000 0.574 0.598
M_AMBI logAFDW -0.045 0.007 -6.076 0.000 -0.060 -0.031
MEDOCC (Intercept) 2.296 0.046 50.326 0.000 2.206 2.386
MEDOCC logAFDW 0.414 0.056 7.347 0.000 0.303 0.525
S (Intercept) 12.413 0.260 47.659 0.000 11.901 12.925
S logAFDW -0.949 0.322 -2.951 0.003 -1.582 -0.317
TBI (Intercept) 0.342 0.008 44.489 0.000 0.327 0.357
TBI logAFDW -0.025 0.010 -2.682 0.008 -0.044 -0.007
kable(summ_logAFDW)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.133 0.131 0.948 60.805 0.000 2 -357 721 733 356.9 397
AMBI_S 0.247 0.245 0.704 130.093 0.000 2 -239 483 495 196.9 397
BENTIX 0.089 0.086 1.553 38.609 0.000 2 -554 1115 1126 957.2 397
BQI 0.044 0.041 2.380 18.069 0.000 2 -725 1455 1467 2248.5 397
ITI 0.010 0.008 22.871 4.175 0.042 2 -1627 3261 3273 207663.7 397
logN 0.000 -0.002 1.271 0.117 0.733 2 -474 955 967 641.2 397
M_AMBI 0.085 0.083 0.161 36.915 0.000 2 350 -695 -683 10.3 397
MEDOCC 0.120 0.117 1.217 53.982 0.000 2 -457 920 932 587.8 397
S 0.021 0.019 6.946 8.710 0.003 2 -1152 2310 2322 19156.4 397
TBI 0.018 0.015 0.205 7.196 0.008 2 253 -500 -488 16.7 397
###logPb simple regression
simple_logPb<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index6 = lm(value ~ logPb,data = .,weights = sqrt(n)))

coef_logPb <- tidy(simple_logPb, fit_index6,conf.int = T)
summ_logPb <- glance(simple_logPb, fit_index6)
kable(coef_logPb)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.449 0.098 14.71 0.000 1.255 1.643
AMBI logPb 0.224 0.049 4.57 0.000 0.127 0.320
AMBI_S (Intercept) 1.515 0.073 20.83 0.000 1.372 1.658
AMBI_S logPb 0.231 0.036 6.37 0.000 0.159 0.302
BENTIX (Intercept) 5.024 0.152 33.11 0.000 4.725 5.323
BENTIX logPb -0.238 0.076 -3.15 0.002 -0.386 -0.089
BQI (Intercept) 5.883 0.230 25.58 0.000 5.430 6.336
BQI logPb -0.564 0.114 -4.93 0.000 -0.789 -0.339
ITI (Intercept) 28.553 2.037 14.02 0.000 24.544 32.562
ITI logPb 1.684 1.014 1.66 0.098 -0.311 3.679
logN (Intercept) 4.825 0.141 34.14 0.000 4.547 5.103
logN logPb -0.327 0.070 -4.64 0.000 -0.465 -0.188
M_AMBI (Intercept) 0.620 0.015 40.81 0.000 0.590 0.650
M_AMBI logPb -0.046 0.008 -6.08 0.000 -0.061 -0.031
MEDOCC (Intercept) 1.993 0.127 15.66 0.000 1.742 2.243
MEDOCC logPb 0.241 0.063 3.80 0.000 0.116 0.366
S (Intercept) 14.096 0.636 22.16 0.000 12.844 15.348
S logPb -1.857 0.317 -5.87 0.000 -2.481 -1.234
TBI (Intercept) 0.356 0.017 20.90 0.000 0.323 0.390
TBI logPb -0.043 0.008 -5.10 0.000 -0.060 -0.027
kable(summ_logPb)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.070 0.066 1.041 20.87 0.000 2 -274 555 566 3.01e+02 278
AMBI_S 0.128 0.124 0.769 40.63 0.000 2 -189 385 396 1.64e+02 278
BENTIX 0.034 0.031 1.604 9.90 0.002 2 -395 797 808 7.15e+02 278
BQI 0.080 0.077 2.432 24.29 0.000 2 -512 1030 1041 1.64e+03 278
ITI 0.010 0.006 21.532 2.76 0.098 2 -1122 2251 2262 1.29e+05 278
logN 0.072 0.069 1.494 21.58 0.000 2 -375 757 768 6.21e+02 278
M_AMBI 0.117 0.114 0.161 37.00 0.000 2 249 -492 -481 7.18e+00 278
MEDOCC 0.049 0.046 1.346 14.45 0.000 2 -346 698 709 5.03e+02 278
S 0.110 0.107 6.725 34.43 0.000 2 -797 1599 1610 1.26e+04 278
TBI 0.086 0.082 0.180 26.02 0.000 2 217 -427 -416 9.04e+00 278
###logCu simple regression#####
simple_logCu<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index7 = lm(value ~ logCu,data = .,weights = sqrt(n)))

coef_logCu <- tidy(simple_logCu, fit_index7,conf.int = T)
summ_logCu <- glance(simple_logCu, fit_index7)
kable(coef_logCu)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.507 0.079 18.991 0.000 1.350 1.663
AMBI logCu 0.206 0.040 5.119 0.000 0.127 0.285
AMBI_S (Intercept) 1.587 0.058 27.149 0.000 1.472 1.702
AMBI_S logCu 0.205 0.030 6.908 0.000 0.146 0.263
BENTIX (Intercept) 5.042 0.122 41.482 0.000 4.803 5.282
BENTIX logCu -0.264 0.062 -4.286 0.000 -0.385 -0.143
BQI (Intercept) 5.874 0.182 32.336 0.000 5.517 6.232
BQI logCu -0.597 0.092 -6.484 0.000 -0.778 -0.416
ITI (Intercept) 30.715 1.662 18.479 0.000 27.443 33.988
ITI logCu 0.553 0.842 0.656 0.512 -1.105 2.210
logN (Intercept) 4.647 0.116 40.190 0.000 4.420 4.875
logN logCu -0.246 0.059 -4.206 0.000 -0.362 -0.131
M_AMBI (Intercept) 0.607 0.012 49.833 0.000 0.583 0.631
M_AMBI logCu -0.042 0.006 -6.748 0.000 -0.054 -0.030
MEDOCC (Intercept) 2.023 0.102 19.783 0.000 1.822 2.224
MEDOCC logCu 0.240 0.052 4.627 0.000 0.138 0.342
S (Intercept) 13.433 0.514 26.121 0.000 12.421 14.446
S logCu -1.600 0.261 -6.141 0.000 -2.113 -1.087
TBI (Intercept) 0.349 0.014 25.623 0.000 0.322 0.376
TBI logCu -0.042 0.007 -6.070 0.000 -0.055 -0.028
kable(summ_logCu)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.086 0.083 1.032 26.209 0.000 2 -272 550 561 2.96e+02 278
AMBI_S 0.147 0.143 0.760 47.727 0.000 2 -186 379 389 1.61e+02 278
BENTIX 0.062 0.059 1.581 18.367 0.000 2 -391 789 800 6.95e+02 278
BQI 0.131 0.128 2.363 42.045 0.000 2 -504 1014 1025 1.55e+03 278
ITI 0.002 -0.002 21.622 0.431 0.512 2 -1124 2253 2264 1.30e+05 278
logN 0.060 0.056 1.504 17.691 0.000 2 -377 761 772 6.29e+02 278
M_AMBI 0.141 0.138 0.159 45.533 0.000 2 253 -499 -488 6.99e+00 278
MEDOCC 0.071 0.068 1.330 21.406 0.000 2 -343 692 703 4.92e+02 278
S 0.119 0.116 6.690 37.713 0.000 2 -795 1596 1607 1.24e+04 278
TBI 0.117 0.114 0.177 36.851 0.000 2 222 -437 -426 8.73e+00 278
###sqrtZn simple regression####
simple_sqrtZn<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index8 = lm(value ~ sqrtZn,data = .,weights = sqrt(n)))

coef_sqrtZn <- tidy(simple_sqrtZn, fit_index8,conf.int = T)
summ_sqrtZn<- glance(simple_sqrtZn, fit_index8)
kable(coef_sqrtZn)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.460 0.104 14.00 0.000 1.255 1.666
AMBI sqrtZn 0.063 0.015 4.16 0.000 0.033 0.093
AMBI_S (Intercept) 1.516 0.077 19.63 0.000 1.364 1.668
AMBI_S sqrtZn 0.066 0.011 5.93 0.000 0.044 0.088
BENTIX (Intercept) 5.052 0.160 31.62 0.000 4.737 5.366
BENTIX sqrtZn -0.073 0.023 -3.15 0.002 -0.118 -0.027
BQI (Intercept) 5.870 0.244 24.10 0.000 5.391 6.350
BQI sqrtZn -0.161 0.035 -4.56 0.000 -0.230 -0.091
ITI (Intercept) 29.465 2.150 13.70 0.000 25.232 33.698
ITI sqrtZn 0.344 0.311 1.10 0.270 -0.269 0.957
logN (Intercept) 4.590 0.153 30.07 0.000 4.289 4.890
logN sqrtZn -0.058 0.022 -2.61 0.010 -0.101 -0.014
M_AMBI (Intercept) 0.620 0.016 38.48 0.000 0.589 0.652
M_AMBI sqrtZn -0.013 0.002 -5.69 0.000 -0.018 -0.009
MEDOCC (Intercept) 2.006 0.135 14.90 0.000 1.741 2.271
MEDOCC sqrtZn 0.067 0.019 3.46 0.001 0.029 0.106
S (Intercept) 13.601 0.684 19.88 0.000 12.255 14.948
S sqrtZn -0.459 0.099 -4.63 0.000 -0.654 -0.264
TBI (Intercept) 0.349 0.018 19.18 0.000 0.313 0.385
TBI sqrtZn -0.011 0.003 -4.29 0.000 -0.016 -0.006
kable(summ_sqrtZn)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.059 0.055 1.047 17.32 0.000 2 -276 558 569 3.05e+02 278
AMBI_S 0.112 0.109 0.775 35.17 0.000 2 -192 390 400 1.67e+02 278
BENTIX 0.034 0.031 1.604 9.93 0.002 2 -395 797 808 7.15e+02 278
BQI 0.070 0.066 2.446 20.78 0.000 2 -513 1033 1044 1.66e+03 278
ITI 0.004 0.001 21.591 1.22 0.270 2 -1123 2253 2263 1.30e+05 278
logN 0.024 0.020 1.533 6.81 0.010 2 -383 771 782 6.53e+02 278
M_AMBI 0.104 0.101 0.162 32.42 0.000 2 247 -488 -477 7.28e+00 278
MEDOCC 0.041 0.038 1.352 11.98 0.001 2 -347 701 712 5.08e+02 278
S 0.072 0.068 6.869 21.46 0.000 2 -803 1611 1622 1.31e+04 278
TBI 0.062 0.059 0.183 18.43 0.000 2 213 -420 -409 9.27e+00 278
###logTOC simple regression#####
simple_logTOC<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index9 = lm(value ~ logTOC,data = .,weights = sqrt(n)))

coef_logTOC <- tidy(simple_logTOC, fit_index9,conf.int = T) 
summ_logTOC<- glance(simple_logTOC, fit_index9) 
kable(coef_logTOC)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.808 0.114 15.827 0.000 1.581 2.035
AMBI logTOC 0.565 0.236 2.395 0.019 0.096 1.033
AMBI_S (Intercept) 1.785 0.089 20.115 0.000 1.608 1.961
AMBI_S logTOC 0.758 0.183 4.138 0.000 0.393 1.122
BENTIX (Intercept) 4.830 0.185 26.071 0.000 4.461 5.198
BENTIX logTOC -0.683 0.382 -1.787 0.078 -1.443 0.077
BQI (Intercept) 5.564 0.309 18.003 0.000 4.949 6.179
BQI logTOC -1.914 0.638 -3.001 0.004 -3.182 -0.645
ITI (Intercept) 35.553 2.491 14.273 0.000 30.599 40.507
ITI logTOC -6.299 5.140 -1.226 0.224 -16.522 3.924
logN (Intercept) 4.369 0.218 20.036 0.000 3.935 4.803
logN logTOC -0.308 0.450 -0.685 0.495 -1.203 0.587
M_AMBI (Intercept) 0.592 0.020 29.183 0.000 0.552 0.632
M_AMBI logTOC -0.146 0.042 -3.489 0.001 -0.229 -0.063
MEDOCC (Intercept) 2.370 0.143 16.535 0.000 2.085 2.655
MEDOCC logTOC 0.703 0.296 2.376 0.020 0.115 1.291
S (Intercept) 12.948 0.901 14.374 0.000 11.156 14.739
S logTOC -5.490 1.859 -2.954 0.004 -9.187 -1.793
TBI (Intercept) 0.301 0.020 14.881 0.000 0.261 0.341
TBI logTOC -0.100 0.042 -2.398 0.019 -0.183 -0.017
kable(summ_logTOC)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.065 0.053 0.963 5.737 0.019 2 -69.4 145 152 77.04 83
AMBI_S 0.171 0.161 0.748 17.123 0.000 2 -48.0 102 109 46.49 83
BENTIX 0.037 0.025 1.562 3.194 0.078 2 -110.5 227 234 202.61 83
BQI 0.098 0.087 2.607 9.005 0.004 2 -154.0 314 321 563.95 83
ITI 0.018 0.006 21.008 1.502 0.224 2 -331.4 669 676 36631.73 83
logN 0.006 -0.006 1.839 0.469 0.495 2 -124.4 255 262 280.75 83
M_AMBI 0.128 0.117 0.171 12.171 0.001 2 77.5 -149 -142 2.43 83
MEDOCC 0.064 0.052 1.209 5.648 0.020 2 -88.7 183 191 121.27 83
S 0.095 0.084 7.597 8.725 0.004 2 -244.9 496 503 4790.21 83
TBI 0.065 0.054 0.171 5.750 0.019 2 77.8 -150 -142 2.41 83
###sqrtTN simple regression#####
simple_sqrtTN <- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index10 = lm(value ~ sqrtTN ,data = .,weights = sqrt(n)))

coef_sqrtTN  <- tidy(simple_sqrtTN , fit_index10,conf.int = T)
summ_sqrtTN <- glance(simple_sqrtTN , fit_index10)
kable(coef_sqrtTN)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.677 0.049 34.541 0.000 1.582 1.773
AMBI sqrtTN 0.015 0.002 6.186 0.000 0.010 0.020
AMBI_S (Intercept) 1.750 0.035 49.973 0.000 1.681 1.819
AMBI_S sqrtTN 0.015 0.002 8.178 0.000 0.011 0.018
BENTIX (Intercept) 4.862 0.075 64.700 0.000 4.714 5.010
BENTIX sqrtTN -0.020 0.004 -5.098 0.000 -0.027 -0.012
BQI (Intercept) 5.012 0.128 39.270 0.000 4.760 5.263
BQI sqrtTN -0.005 0.007 -0.836 0.404 -0.018 0.007
ITI (Intercept) 32.522 1.028 31.639 0.000 30.498 34.546
ITI sqrtTN -0.009 0.053 -0.164 0.870 -0.112 0.095
logN (Intercept) 4.224 0.080 52.982 0.000 4.067 4.381
logN sqrtTN 0.004 0.004 0.901 0.368 -0.004 0.012
M_AMBI (Intercept) 0.563 0.008 67.726 0.000 0.546 0.579
M_AMBI sqrtTN -0.001 0.000 -3.335 0.001 -0.002 -0.001
MEDOCC (Intercept) 2.216 0.063 34.917 0.000 2.091 2.340
MEDOCC sqrtTN 0.019 0.003 5.867 0.000 0.013 0.025
S (Intercept) 11.223 0.365 30.770 0.000 10.505 11.942
S sqrtTN -0.012 0.019 -0.621 0.535 -0.048 0.025
TBI (Intercept) 0.279 0.009 30.406 0.000 0.261 0.297
TBI sqrtTN 0.000 0.000 -0.132 0.895 -0.001 0.001
kable(summ_sqrtTN)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.127 0.123 0.972 38.271 0.000 2 -241 488 499 2.49e+02 264
AMBI_S 0.202 0.199 0.701 66.874 0.000 2 -154 314 325 1.30e+02 264
BENTIX 0.090 0.086 1.504 25.988 0.000 2 -357 721 731 5.97e+02 264
BQI 0.003 -0.001 2.554 0.699 0.404 2 -498 1002 1013 1.72e+03 264
ITI 0.000 -0.004 20.572 0.027 0.870 2 -1053 2112 2123 1.12e+05 264
logN 0.003 -0.001 1.595 0.813 0.368 2 -373 752 763 6.72e+02 264
M_AMBI 0.040 0.037 0.166 11.121 0.001 2 229 -451 -440 7.30e+00 264
MEDOCC 0.115 0.112 1.270 34.421 0.000 2 -312 631 641 4.26e+02 264
S 0.001 -0.002 7.300 0.385 0.535 2 -778 1561 1572 1.41e+04 264
TBI 0.000 -0.004 0.183 0.017 0.895 2 202 -399 -388 8.88e+00 264
###Type simple regression####
simple_type<- 
  dat_simple %>%
  group_by(index) %>%
  do(fit_index11 = lm(value ~ Region,data = .,weights = sqrt(n)))

coef_type<- tidy(simple_type, fit_index11,conf.int = T)
summ_type <- glance(simple_type, fit_index11)
kable(coef_type)
index term estimate std.error statistic p.value conf.low conf.high
AMBI (Intercept) 1.884 0.090 20.952 0.000 1.707 2.061
AMBI RegionEastern North Island -0.024 0.134 -0.178 0.858 -0.288 0.240
AMBI RegionNorth Eastern 0.140 0.101 1.387 0.166 -0.058 0.338
AMBI RegionSouthern 0.305 0.114 2.669 0.008 0.081 0.530
AMBI RegionWestern North Island 0.061 0.120 0.510 0.610 -0.174 0.296
AMBI_S (Intercept) 1.947 0.071 27.380 0.000 1.807 2.087
AMBI_S RegionEastern North Island 0.048 0.106 0.447 0.655 -0.161 0.256
AMBI_S RegionNorth Eastern 0.130 0.080 1.625 0.105 -0.027 0.286
AMBI_S RegionSouthern 0.253 0.090 2.798 0.005 0.075 0.431
AMBI_S RegionWestern North Island -0.041 0.095 -0.437 0.663 -0.227 0.145
BENTIX (Intercept) 4.547 0.133 34.310 0.000 4.287 4.807
BENTIX RegionEastern North Island 0.405 0.198 2.044 0.041 0.016 0.794
BENTIX RegionNorth Eastern -0.226 0.149 -1.522 0.129 -0.518 0.066
BENTIX RegionSouthern -0.437 0.169 -2.596 0.010 -0.768 -0.106
BENTIX RegionWestern North Island -0.412 0.176 -2.335 0.020 -0.758 -0.065
BQI (Intercept) 5.128 0.166 30.934 0.000 4.803 5.454
BQI RegionEastern North Island -1.788 0.248 -7.220 0.000 -2.275 -1.302
BQI RegionNorth Eastern 0.427 0.186 2.298 0.022 0.062 0.792
BQI RegionSouthern -0.815 0.211 -3.868 0.000 -1.229 -0.401
BQI RegionWestern North Island 0.975 0.221 4.422 0.000 0.542 1.408
ITI (Intercept) 29.885 1.646 18.155 0.000 26.651 33.119
ITI RegionEastern North Island 13.064 2.460 5.312 0.000 8.233 17.896
ITI RegionNorth Eastern -0.916 1.845 -0.496 0.620 -4.541 2.709
ITI RegionSouthern -0.303 2.093 -0.145 0.885 -4.414 3.809
ITI RegionWestern North Island -5.897 2.190 -2.693 0.007 -10.199 -1.596
logN (Intercept) 3.993 0.094 42.648 0.000 3.809 4.177
logN RegionEastern North Island -0.755 0.140 -5.394 0.000 -1.029 -0.480
logN RegionNorth Eastern 0.504 0.105 4.800 0.000 0.298 0.710
logN RegionSouthern 0.514 0.119 4.317 0.000 0.280 0.748
logN RegionWestern North Island 0.334 0.125 2.679 0.008 0.089 0.578
M_AMBI (Intercept) 0.554 0.013 41.533 0.000 0.528 0.580
M_AMBI RegionEastern North Island -0.085 0.020 -4.287 0.000 -0.125 -0.046
M_AMBI RegionNorth Eastern 0.011 0.015 0.731 0.465 -0.018 0.040
M_AMBI RegionSouthern -0.067 0.017 -3.940 0.000 -0.100 -0.034
M_AMBI RegionWestern North Island 0.040 0.018 2.276 0.023 0.006 0.075
MEDOCC (Intercept) 2.488 0.115 21.674 0.000 2.263 2.714
MEDOCC RegionEastern North Island -0.141 0.172 -0.824 0.411 -0.478 0.196
MEDOCC RegionNorth Eastern 0.165 0.129 1.280 0.201 -0.088 0.417
MEDOCC RegionSouthern 0.398 0.146 2.726 0.007 0.111 0.685
MEDOCC RegionWestern North Island 0.089 0.153 0.585 0.559 -0.211 0.389
S (Intercept) 11.085 0.496 22.366 0.000 10.111 12.059
S RegionEastern North Island -4.596 0.741 -6.206 0.000 -6.051 -3.141
S RegionNorth Eastern 1.410 0.556 2.538 0.011 0.319 2.502
S RegionSouthern -1.340 0.630 -2.126 0.034 -2.578 -0.102
S RegionWestern North Island 2.173 0.659 3.295 0.001 0.878 3.468
TBI (Intercept) 0.302 0.014 22.167 0.000 0.275 0.328
TBI RegionEastern North Island -0.138 0.020 -6.806 0.000 -0.178 -0.098
TBI RegionNorth Eastern 0.049 0.015 3.188 0.002 0.019 0.079
TBI RegionSouthern -0.072 0.017 -4.189 0.000 -0.106 -0.039
TBI RegionWestern North Island 0.058 0.018 3.203 0.001 0.022 0.094
kable(summ_type)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.021 0.014 1.189 2.86 0.023 5 -588 1189 1214 754.5 534
AMBI_S 0.029 0.021 0.940 3.92 0.004 5 -462 936 962 472.0 534
BENTIX 0.050 0.042 1.752 6.95 0.000 5 -797 1607 1633 1639.0 534
BQI 0.277 0.271 2.192 51.09 0.000 5 -918 1848 1874 2564.6 534
ITI 0.114 0.108 21.760 17.25 0.000 5 -2155 4323 4348 252856.9 534
logN 0.208 0.202 1.238 35.07 0.000 5 -610 1232 1258 817.9 534
M_AMBI 0.136 0.130 0.176 21.02 0.000 5 440 -868 -842 16.6 534
MEDOCC 0.027 0.020 1.517 3.73 0.005 5 -720 1452 1478 1229.7 534
S 0.202 0.196 6.552 33.84 0.000 5 -1508 3029 3054 22922.3 534
TBI 0.275 0.269 0.180 50.62 0.000 5 429 -847 -821 17.3 534