###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))

all_ind<- read_csv('data_multiple_regression.csv',col_types =  cols(Date = 'D')) %>% 
  mutate(Type = factor(Type),
         logTOC = log(TOC+1))
options(digits = 3)

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.325 0.076 17.357 0.000 1.175 1.476
AMBI sqrtmud 0.140 0.018 7.791 0.000 0.105 0.176
AMBI_S (Intercept) 1.426 0.054 26.593 0.000 1.321 1.532
AMBI_S sqrtmud 0.133 0.013 10.513 0.000 0.108 0.158
BENTIX (Intercept) 5.207 0.123 42.472 0.000 4.965 5.449
BENTIX sqrtmud -0.156 0.029 -5.386 0.000 -0.213 -0.099
BQI (Intercept) 6.010 0.192 31.332 0.000 5.632 6.388
BQI sqrtmud -0.321 0.045 -7.095 0.000 -0.410 -0.232
ITI (Intercept) 33.011 1.678 19.676 0.000 29.706 36.316
ITI sqrtmud -0.132 0.395 -0.333 0.739 -0.911 0.647
logN (Intercept) 4.628 0.129 35.808 0.000 4.373 4.883
logN sqrtmud -0.112 0.030 -3.677 0.000 -0.172 -0.052
M_AMBI (Intercept) 0.631 0.012 51.840 0.000 0.607 0.655
M_AMBI sqrtmud -0.025 0.003 -8.748 0.000 -0.031 -0.019
MEDOCC (Intercept) 1.779 0.100 17.802 0.000 1.582 1.976
MEDOCC sqrtmud 0.172 0.024 7.327 0.000 0.126 0.219
S (Intercept) 14.122 0.539 26.208 0.000 13.060 15.183
S sqrtmud -0.922 0.127 -7.264 0.000 -1.172 -0.672
TBI (Intercept) 0.350 0.014 24.707 0.000 0.322 0.378
TBI sqrtmud -0.021 0.003 -6.322 0.000 -0.028 -0.015
kable(summ_mud)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.205 0.202 0.916 60.705 0.000 2 -204 414 424 196.98 235
AMBI_S 0.320 0.317 0.643 110.519 0.000 2 -120 246 257 97.17 235
BENTIX 0.110 0.106 1.470 29.014 0.000 2 -316 638 648 507.81 235
BQI 0.176 0.173 2.300 50.337 0.000 2 -422 850 861 1242.98 235
ITI 0.000 -0.004 20.116 0.111 0.739 2 -936 1878 1889 95092.31 235
logN 0.054 0.050 1.550 13.519 0.000 2 -329 663 674 564.34 235
M_AMBI 0.246 0.242 0.146 76.526 0.000 2 232 -457 -447 5.00 235
MEDOCC 0.186 0.182 1.198 53.679 0.000 2 -268 541 552 337.28 235
S 0.183 0.180 6.461 52.770 0.000 2 -667 1340 1350 9809.30 235
TBI 0.145 0.142 0.170 39.964 0.000 2 196 -385 -375 6.77 235
###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.865 0.040 46.89 0.000 1.787 1.943
AMBI metals 0.065 0.015 4.19 0.000 0.034 0.095
AMBI_S (Intercept) 1.940 0.029 66.72 0.000 1.882 1.997
AMBI_S metals 0.069 0.011 6.12 0.000 0.047 0.091
BENTIX (Intercept) 4.613 0.062 74.48 0.000 4.491 4.736
BENTIX metals -0.052 0.024 -2.15 0.033 -0.099 -0.004
BQI (Intercept) 4.757 0.095 50.06 0.000 4.570 4.945
BQI metals -0.216 0.037 -5.86 0.000 -0.289 -0.144
ITI (Intercept) 32.844 0.782 42.03 0.000 31.304 34.383
ITI metals 1.215 0.304 4.00 0.000 0.617 1.813
logN (Intercept) 4.186 0.062 67.49 0.000 4.064 4.308
logN metals -0.093 0.024 -3.88 0.000 -0.141 -0.046
M_AMBI (Intercept) 0.533 0.006 85.13 0.000 0.521 0.546
M_AMBI metals -0.015 0.002 -6.10 0.000 -0.020 -0.010
MEDOCC (Intercept) 2.439 0.052 46.85 0.000 2.337 2.542
MEDOCC metals 0.068 0.020 3.36 0.001 0.028 0.108
S (Intercept) 10.528 0.269 39.08 0.000 9.997 11.059
S metals -0.589 0.105 -5.63 0.000 -0.795 -0.383
TBI (Intercept) 0.267 0.007 39.06 0.000 0.253 0.280
TBI metals -0.016 0.003 -6.21 0.000 -0.022 -0.011
kable(summ_metals)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.069 0.065 0.991 17.53 0.000 2 -223 451 461 230.65 235
AMBI_S 0.137 0.134 0.724 37.42 0.000 2 -148 303 313 123.24 235
BENTIX 0.019 0.015 1.543 4.61 0.033 2 -328 661 671 559.53 235
BQI 0.127 0.124 2.367 34.32 0.000 2 -429 864 874 1316.88 235
ITI 0.064 0.060 19.468 16.02 0.000 2 -928 1863 1873 89067.46 235
logN 0.060 0.056 1.545 15.02 0.000 2 -328 662 672 560.95 235
M_AMBI 0.137 0.133 0.156 37.18 0.000 2 216 -425 -415 5.72 235
MEDOCC 0.046 0.042 1.297 11.28 0.001 2 -286 579 589 395.36 235
S 0.119 0.115 6.712 31.66 0.000 2 -676 1358 1368 10586.03 235
TBI 0.141 0.137 0.170 38.59 0.000 2 195 -384 -374 6.81 235
###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.037 0.167 6.21 0.000 0.708 1.366
AMBI sqrtTP 0.044 0.009 5.00 0.000 0.027 0.061
AMBI_S (Intercept) 1.106 0.122 9.10 0.000 0.866 1.345
AMBI_S sqrtTP 0.044 0.006 6.90 0.000 0.032 0.057
BENTIX (Intercept) 5.404 0.261 20.69 0.000 4.889 5.919
BENTIX sqrtTP -0.042 0.014 -3.06 0.002 -0.069 -0.015
BQI (Intercept) 6.390 0.420 15.21 0.000 5.562 7.217
BQI sqrtTP -0.085 0.022 -3.85 0.000 -0.129 -0.042
ITI (Intercept) 25.808 3.410 7.57 0.000 19.089 32.527
ITI sqrtTP 0.364 0.180 2.02 0.044 0.010 0.718
logN (Intercept) 4.619 0.271 17.04 0.000 4.084 5.153
logN sqrtTP -0.022 0.014 -1.55 0.123 -0.050 0.006
M_AMBI (Intercept) 0.673 0.027 24.70 0.000 0.619 0.726
M_AMBI sqrtTP -0.007 0.001 -5.12 0.000 -0.010 -0.005
MEDOCC (Intercept) 1.475 0.218 6.76 0.000 1.045 1.904
MEDOCC sqrtTP 0.051 0.011 4.47 0.000 0.029 0.074
S (Intercept) 14.909 1.189 12.54 0.000 12.566 17.252
S sqrtTP -0.229 0.063 -3.65 0.000 -0.352 -0.106
TBI (Intercept) 0.375 0.031 12.25 0.000 0.315 0.435
TBI sqrtTP -0.006 0.002 -3.49 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.976 24.95 0.000 2 -219 444 455 224.07 235
AMBI_S 0.168 0.165 0.711 47.59 0.000 2 -144 294 304 118.81 235
BENTIX 0.038 0.034 1.528 9.35 0.002 2 -325 656 667 548.67 235
BQI 0.059 0.055 2.458 14.85 0.000 2 -438 882 892 1419.52 235
ITI 0.017 0.013 19.948 4.10 0.044 2 -934 1874 1885 93507.20 235
logN 0.010 0.006 1.586 2.39 0.123 2 -334 674 684 590.79 235
M_AMBI 0.100 0.096 0.159 26.20 0.000 2 211 -415 -405 5.96 235
MEDOCC 0.078 0.074 1.275 19.96 0.000 2 -282 571 581 381.89 235
S 0.054 0.050 6.955 13.35 0.000 2 -684 1375 1385 11366.50 235
TBI 0.049 0.045 0.179 12.18 0.001 2 183 -360 -349 7.53 235
###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) 2.070 0.097 21.236 0.000 1.878 2.262
AMBI RegionEastern North Island -0.210 0.129 -1.630 0.104 -0.463 0.044
AMBI RegionNorth Eastern -0.232 0.124 -1.876 0.062 -0.477 0.012
AMBI RegionSouthern -0.378 0.121 -3.139 0.002 -0.616 -0.141
AMBI RegionWestern North Island 0.522 0.325 1.605 0.110 -0.119 1.163
AMBI_S (Intercept) 2.050 0.074 27.800 0.000 1.905 2.195
AMBI_S RegionEastern North Island -0.055 0.097 -0.570 0.569 -0.247 0.136
AMBI_S RegionNorth Eastern -0.168 0.094 -1.792 0.074 -0.353 0.017
AMBI_S RegionSouthern -0.250 0.091 -2.740 0.007 -0.430 -0.070
AMBI_S RegionWestern North Island 0.518 0.246 2.105 0.036 0.033 1.003
BENTIX (Intercept) 4.375 0.147 29.789 0.000 4.086 4.665
BENTIX RegionEastern North Island 0.576 0.194 2.973 0.003 0.194 0.958
BENTIX RegionNorth Eastern 0.151 0.187 0.810 0.419 -0.217 0.519
BENTIX RegionSouthern 0.311 0.182 1.714 0.088 -0.047 0.669
BENTIX RegionWestern North Island -1.117 0.490 -2.280 0.024 -2.083 -0.152
BQI (Intercept) 5.102 0.196 26.029 0.000 4.715 5.488
BQI RegionEastern North Island -1.762 0.259 -6.809 0.000 -2.272 -1.252
BQI RegionNorth Eastern 0.921 0.249 3.698 0.000 0.431 1.412
BQI RegionSouthern -0.432 0.242 -1.781 0.076 -0.909 0.046
BQI RegionWestern North Island -0.140 0.654 -0.214 0.831 -1.428 1.149
ITI (Intercept) 30.490 1.747 17.454 0.000 27.048 33.932
ITI RegionEastern North Island 12.459 2.306 5.403 0.000 7.916 17.003
ITI RegionNorth Eastern -1.680 2.221 -0.756 0.450 -6.056 2.696
ITI RegionSouthern -0.636 2.160 -0.295 0.769 -4.892 3.620
ITI RegionWestern North Island -7.671 5.828 -1.316 0.189 -19.153 3.812
logN (Intercept) 3.762 0.118 31.923 0.000 3.530 3.994
logN RegionEastern North Island -0.524 0.156 -3.367 0.001 -0.830 -0.217
logN RegionNorth Eastern 1.120 0.150 7.477 0.000 0.825 1.415
logN RegionSouthern 0.805 0.146 5.525 0.000 0.518 1.092
logN RegionWestern North Island 0.410 0.393 1.042 0.298 -0.365 1.184
M_AMBI (Intercept) 0.551 0.015 36.933 0.000 0.521 0.580
M_AMBI RegionEastern North Island -0.082 0.020 -4.165 0.000 -0.121 -0.043
M_AMBI RegionNorth Eastern 0.040 0.019 2.124 0.035 0.003 0.078
M_AMBI RegionSouthern -0.016 0.018 -0.863 0.389 -0.052 0.020
M_AMBI RegionWestern North Island -0.055 0.050 -1.099 0.273 -0.153 0.043
MEDOCC (Intercept) 2.738 0.126 21.760 0.000 2.490 2.986
MEDOCC RegionEastern North Island -0.391 0.166 -2.355 0.019 -0.718 -0.064
MEDOCC RegionNorth Eastern -0.295 0.160 -1.843 0.067 -0.610 0.020
MEDOCC RegionSouthern -0.500 0.156 -3.211 0.002 -0.806 -0.193
MEDOCC RegionWestern North Island 0.643 0.420 1.532 0.127 -0.184 1.470
S (Intercept) 10.878 0.556 19.569 0.000 9.782 11.973
S RegionEastern North Island -4.389 0.734 -5.981 0.000 -5.834 -2.943
S RegionNorth Eastern 3.191 0.707 4.515 0.000 1.799 4.583
S RegionSouthern -0.160 0.687 -0.233 0.816 -1.514 1.194
S RegionWestern North Island -1.128 1.854 -0.608 0.544 -4.781 2.526
TBI (Intercept) 0.291 0.013 21.730 0.000 0.265 0.318
TBI RegionEastern North Island -0.128 0.018 -7.236 0.000 -0.163 -0.093
TBI RegionNorth Eastern 0.081 0.017 4.755 0.000 0.047 0.115
TBI RegionSouthern -0.038 0.017 -2.322 0.021 -0.071 -0.006
TBI RegionWestern North Island -0.065 0.045 -1.445 0.150 -0.153 0.024
kable(summ_region)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.064 0.048 1.000 3.96 0.004 5 -223 458 479 232.01 232
AMBI_S 0.070 0.054 0.757 4.38 0.002 5 -157 326 347 132.83 232
BENTIX 0.076 0.060 1.507 4.79 0.001 5 -320 653 674 526.98 232
BQI 0.378 0.368 2.011 35.29 0.000 5 -389 790 810 938.29 232
ITI 0.217 0.203 17.924 16.03 0.000 5 -907 1826 1847 74536.73 232
logN 0.432 0.422 1.209 44.05 0.000 5 -268 548 569 339.19 232
M_AMBI 0.181 0.166 0.153 12.78 0.000 5 222 -431 -411 5.43 232
MEDOCC 0.067 0.051 1.291 4.15 0.003 5 -284 580 600 386.67 232
S 0.372 0.361 5.703 34.32 0.000 5 -636 1284 1305 7546.78 232
TBI 0.446 0.436 0.138 46.65 0.000 5 247 -482 -461 4.39 232
###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.629 0.065 25.032 0.000 1.500 1.757
AMBI logAFDW 0.309 0.074 4.200 0.000 0.164 0.454
AMBI_S (Intercept) 1.717 0.047 36.733 0.000 1.624 1.809
AMBI_S logAFDW 0.282 0.053 5.328 0.000 0.177 0.386
BENTIX (Intercept) 4.873 0.098 49.804 0.000 4.680 5.066
BENTIX logAFDW -0.406 0.111 -3.666 0.000 -0.624 -0.187
BQI (Intercept) 4.852 0.161 30.068 0.000 4.534 5.171
BQI logAFDW 0.145 0.183 0.792 0.430 -0.216 0.505
ITI (Intercept) 33.028 1.354 24.385 0.000 30.357 35.700
ITI logAFDW -0.901 1.533 -0.588 0.558 -3.924 2.123
logN (Intercept) 4.139 0.096 43.313 0.000 3.951 4.328
logN logAFDW 0.158 0.108 1.465 0.145 -0.055 0.372
M_AMBI (Intercept) 0.555 0.011 52.560 0.000 0.534 0.576
M_AMBI logAFDW -0.016 0.012 -1.302 0.195 -0.039 0.008
MEDOCC (Intercept) 2.150 0.085 25.425 0.000 1.983 2.316
MEDOCC logAFDW 0.381 0.096 3.986 0.000 0.193 0.570
S (Intercept) 10.808 0.453 23.848 0.000 9.914 11.702
S logAFDW 0.378 0.513 0.736 0.463 -0.634 1.389
TBI (Intercept) 0.269 0.012 22.683 0.000 0.246 0.293
TBI logAFDW 0.022 0.013 1.612 0.109 -0.005 0.048
kable(summ_logAFDW)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.085 0.081 1.008 17.641 0.000 2 -186 379 388 191.94 189
AMBI_S 0.131 0.126 0.724 28.386 0.000 2 -123 252 262 99.04 189
BENTIX 0.066 0.061 1.516 13.438 0.000 2 -264 535 544 434.14 189
BQI 0.003 -0.002 2.500 0.627 0.430 2 -360 726 735 1181.00 189
ITI 0.002 -0.003 20.980 0.345 0.558 2 -766 1538 1548 83193.74 189
logN 0.011 0.006 1.480 2.145 0.145 2 -260 526 535 414.20 189
M_AMBI 0.009 0.004 0.163 1.694 0.195 2 161 -316 -306 5.05 189
MEDOCC 0.078 0.073 1.310 15.889 0.000 2 -236 479 488 324.17 189
S 0.003 -0.002 7.020 0.542 0.463 2 -557 1120 1130 9314.76 189
TBI 0.014 0.008 0.184 2.599 0.109 2 138 -271 -261 6.40 189
###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.486 0.102 14.55 0.000 1.285 1.688
AMBI logPb 0.213 0.056 3.84 0.000 0.104 0.323
AMBI_S (Intercept) 1.539 0.075 20.45 0.000 1.390 1.687
AMBI_S logPb 0.226 0.041 5.52 0.000 0.145 0.306
BENTIX (Intercept) 4.830 0.159 30.35 0.000 4.516 5.143
BENTIX logPb -0.119 0.086 -1.38 0.168 -0.290 0.051
BQI (Intercept) 6.179 0.241 25.61 0.000 5.704 6.655
BQI logPb -0.805 0.131 -6.14 0.000 -1.063 -0.547
ITI (Intercept) 22.947 1.949 11.78 0.000 19.108 26.787
ITI logPb 5.649 1.059 5.33 0.000 3.562 7.736
logN (Intercept) 5.000 0.154 32.56 0.000 4.698 5.303
logN logPb -0.466 0.083 -5.58 0.000 -0.630 -0.301
M_AMBI (Intercept) 0.629 0.016 39.39 0.000 0.597 0.660
M_AMBI logPb -0.054 0.009 -6.22 0.000 -0.071 -0.037
MEDOCC (Intercept) 2.052 0.134 15.36 0.000 1.789 2.315
MEDOCC logPb 0.218 0.073 3.00 0.003 0.075 0.361
S (Intercept) 14.864 0.671 22.16 0.000 13.543 16.186
S logPb -2.466 0.365 -6.76 0.000 -3.184 -1.748
TBI (Intercept) 0.386 0.017 22.70 0.000 0.352 0.419
TBI logPb -0.068 0.009 -7.32 0.000 -0.086 -0.049
kable(summ_logPb)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.059 0.055 0.996 14.75 0.000 2 -224 454 464 233.22 235
AMBI_S 0.115 0.111 0.734 30.50 0.000 2 -151 309 319 126.45 235
BENTIX 0.008 0.004 1.552 1.91 0.168 2 -329 664 674 565.91 235
BQI 0.138 0.135 2.353 37.70 0.000 2 -427 861 871 1300.58 235
ITI 0.108 0.104 19.004 28.44 0.000 2 -923 1851 1862 84867.09 235
logN 0.117 0.113 1.497 31.14 0.000 2 -320 647 657 526.96 235
M_AMBI 0.141 0.138 0.156 38.70 0.000 2 216 -426 -416 5.69 235
MEDOCC 0.037 0.033 1.303 9.00 0.003 2 -287 581 591 399.04 235
S 0.163 0.159 6.541 45.75 0.000 2 -670 1346 1356 10054.72 235
TBI 0.186 0.182 0.166 53.57 0.000 2 201 -397 -386 6.45 235
###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.558 0.077 20.11 0.000 1.406 1.711
AMBI logCu 0.176 0.040 4.34 0.000 0.096 0.255
AMBI_S (Intercept) 1.623 0.057 28.58 0.000 1.511 1.734
AMBI_S logCu 0.181 0.030 6.11 0.000 0.123 0.240
BENTIX (Intercept) 4.958 0.120 41.48 0.000 4.723 5.194
BENTIX logCu -0.201 0.062 -3.22 0.001 -0.324 -0.078
BQI (Intercept) 5.851 0.182 32.06 0.000 5.492 6.211
BQI logCu -0.629 0.095 -6.60 0.000 -0.816 -0.441
ITI (Intercept) 29.915 1.565 19.11 0.000 26.832 32.998
ITI logCu 1.581 0.817 1.93 0.054 -0.029 3.191
logN (Intercept) 4.634 0.121 38.37 0.000 4.396 4.871
logN logCu -0.257 0.063 -4.07 0.000 -0.381 -0.132
M_AMBI (Intercept) 0.603 0.012 49.56 0.000 0.579 0.627
M_AMBI logCu -0.040 0.006 -6.31 0.000 -0.053 -0.028
MEDOCC (Intercept) 2.087 0.101 20.67 0.000 1.888 2.286
MEDOCC logCu 0.203 0.053 3.84 0.000 0.099 0.307
S (Intercept) 13.368 0.522 25.60 0.000 12.339 14.397
S logCu -1.628 0.273 -5.97 0.000 -2.165 -1.091
TBI (Intercept) 0.346 0.013 26.20 0.000 0.320 0.372
TBI logCu -0.046 0.007 -6.61 0.000 -0.059 -0.032
kable(summ_logCu)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.074 0.070 0.988 18.85 0.000 2 -222 450 460 229.46 235
AMBI_S 0.137 0.133 0.724 37.33 0.000 2 -148 303 313 123.28 235
BENTIX 0.042 0.038 1.525 10.35 0.001 2 -325 655 666 546.45 235
BQI 0.156 0.153 2.328 43.52 0.000 2 -425 856 866 1273.40 235
ITI 0.016 0.011 19.962 3.74 0.054 2 -934 1875 1885 93646.40 235
logN 0.066 0.062 1.540 16.55 0.000 2 -327 660 671 557.54 235
M_AMBI 0.145 0.141 0.155 39.85 0.000 2 217 -427 -417 5.66 235
MEDOCC 0.059 0.055 1.288 14.78 0.000 2 -285 575 586 389.82 235
S 0.132 0.128 6.662 35.64 0.000 2 -674 1354 1365 10430.35 235
TBI 0.157 0.153 0.169 43.66 0.000 2 197 -388 -378 6.68 235
###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.451 0.107 13.54 0.000 1.240 1.662
AMBI sqrtZn 0.066 0.017 3.98 0.000 0.033 0.099
AMBI_S (Intercept) 1.495 0.079 19.03 0.000 1.341 1.650
AMBI_S sqrtZn 0.071 0.012 5.83 0.000 0.047 0.095
BENTIX (Intercept) 4.933 0.167 29.60 0.000 4.604 5.261
BENTIX sqrtZn -0.051 0.026 -1.97 0.050 -0.102 0.000
BQI (Intercept) 6.115 0.258 23.74 0.000 5.608 6.622
BQI sqrtZn -0.217 0.040 -5.43 0.000 -0.296 -0.138
ITI (Intercept) 24.783 2.101 11.80 0.000 20.645 28.922
ITI sqrtZn 1.291 0.326 3.96 0.000 0.650 1.933
logN (Intercept) 4.760 0.167 28.42 0.000 4.430 5.090
logN sqrtZn -0.092 0.026 -3.53 0.001 -0.143 -0.040
M_AMBI (Intercept) 0.627 0.017 36.99 0.000 0.594 0.661
M_AMBI sqrtZn -0.015 0.003 -5.73 0.000 -0.020 -0.010
MEDOCC (Intercept) 2.010 0.140 14.33 0.000 1.733 2.286
MEDOCC sqrtZn 0.069 0.022 3.16 0.002 0.026 0.112
S (Intercept) 14.211 0.730 19.46 0.000 12.773 15.650
S sqrtZn -0.589 0.113 -5.20 0.000 -0.812 -0.365
TBI (Intercept) 0.370 0.019 19.96 0.000 0.334 0.407
TBI sqrtZn -0.017 0.003 -5.74 0.000 -0.022 -0.011
kable(summ_sqrtZn)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.063 0.059 0.994 15.86 0.000 2 -223 453 463 232.19 235
AMBI_S 0.126 0.123 0.729 34.01 0.000 2 -150 306 316 124.81 235
BENTIX 0.016 0.012 1.545 3.89 0.050 2 -328 662 672 561.21 235
BQI 0.112 0.108 2.389 29.52 0.000 2 -431 868 879 1340.80 235
ITI 0.063 0.059 19.480 15.72 0.000 2 -928 1863 1873 89172.16 235
logN 0.050 0.046 1.553 12.45 0.001 2 -329 664 675 566.78 235
M_AMBI 0.123 0.119 0.157 32.83 0.000 2 214 -421 -411 5.81 235
MEDOCC 0.041 0.037 1.300 9.98 0.002 2 -287 580 590 397.44 235
S 0.103 0.099 6.771 27.03 0.000 2 -678 1362 1372 10772.96 235
TBI 0.123 0.119 0.172 32.97 0.000 2 193 -379 -369 6.95 235
###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.681 0.122 13.818 0.000 1.436 1.925
AMBI logTOC 0.573 0.221 2.594 0.013 0.128 1.018
AMBI_S (Intercept) 1.680 0.100 16.862 0.000 1.480 1.881
AMBI_S logTOC 0.786 0.181 4.343 0.000 0.422 1.150
BENTIX (Intercept) 4.912 0.214 22.950 0.000 4.482 5.343
BENTIX logTOC -0.440 0.389 -1.130 0.264 -1.222 0.343
BQI (Intercept) 5.021 0.377 13.317 0.000 4.262 5.780
BQI logTOC -1.698 0.685 -2.479 0.017 -3.077 -0.319
ITI (Intercept) 34.938 2.803 12.464 0.000 29.296 40.581
ITI logTOC -0.257 5.093 -0.051 0.960 -10.508 9.994
logN (Intercept) 3.923 0.306 12.824 0.000 3.307 4.539
logN logTOC 0.236 0.556 0.424 0.673 -0.883 1.354
M_AMBI (Intercept) 0.568 0.024 23.413 0.000 0.519 0.616
M_AMBI logTOC -0.141 0.044 -3.202 0.002 -0.230 -0.052
MEDOCC (Intercept) 2.191 0.151 14.550 0.000 1.888 2.494
MEDOCC logTOC 0.733 0.274 2.682 0.010 0.183 1.284
S (Intercept) 11.384 1.061 10.728 0.000 9.248 13.520
S logTOC -4.961 1.928 -2.574 0.013 -8.842 -1.081
TBI (Intercept) 0.272 0.023 11.935 0.000 0.226 0.318
TBI logTOC -0.107 0.041 -2.579 0.013 -0.190 -0.023
kable(summ_logTOC)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.128 0.109 0.798 6.727 0.013 2 -29.9 65.8 71.4 29.26 46
AMBI_S 0.291 0.275 0.653 18.858 0.000 2 -20.3 46.7 52.3 19.64 46
BENTIX 0.027 0.006 1.404 1.278 0.264 2 -57.0 120.1 125.7 90.62 46
BQI 0.118 0.099 2.472 6.146 0.017 2 -84.2 174.4 180.0 281.17 46
ITI 0.000 -0.022 18.382 0.003 0.960 2 -180.5 367.0 372.6 15543.02 46
logN 0.004 -0.018 2.006 0.180 0.673 2 -74.2 154.4 160.0 185.10 46
M_AMBI 0.182 0.164 0.159 10.251 0.002 2 47.5 -89.0 -83.4 1.16 46
MEDOCC 0.135 0.116 0.987 7.192 0.010 2 -40.1 86.3 91.9 44.83 46
S 0.126 0.107 6.958 6.623 0.013 2 -133.9 273.8 279.4 2227.34 46
TBI 0.126 0.107 0.150 6.651 0.013 2 50.4 -94.8 -89.2 1.03 46
###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.617 0.050 32.064 0.000 1.518 1.716
AMBI sqrtTN 0.018 0.003 6.894 0.000 0.013 0.023
AMBI_S (Intercept) 1.707 0.036 46.950 0.000 1.635 1.778
AMBI_S sqrtTN 0.016 0.002 8.858 0.000 0.013 0.020
BENTIX (Intercept) 4.906 0.079 61.979 0.000 4.750 5.061
BENTIX sqrtTN -0.022 0.004 -5.336 0.000 -0.029 -0.014
BQI (Intercept) 4.931 0.136 36.238 0.000 4.662 5.199
BQI sqrtTN -0.009 0.007 -1.236 0.218 -0.022 0.005
ITI (Intercept) 32.333 1.083 29.847 0.000 30.198 34.467
ITI sqrtTN 0.012 0.055 0.212 0.833 -0.097 0.120
logN (Intercept) 4.133 0.085 48.357 0.000 3.965 4.301
logN sqrtTN 0.006 0.004 1.405 0.161 -0.002 0.015
M_AMBI (Intercept) 0.560 0.009 64.014 0.000 0.543 0.578
M_AMBI sqrtTN -0.002 0.000 -3.994 0.000 -0.003 -0.001
MEDOCC (Intercept) 2.135 0.066 32.494 0.000 2.005 2.264
MEDOCC sqrtTN 0.022 0.003 6.579 0.000 0.015 0.029
S (Intercept) 10.963 0.384 28.535 0.000 10.206 11.720
S sqrtTN -0.021 0.020 -1.051 0.294 -0.059 0.018
TBI (Intercept) 0.277 0.010 28.107 0.000 0.258 0.297
TBI sqrtTN 0.000 0.001 -0.825 0.410 -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.169 0.165 0.938 47.525 0.000 2 -209 423 434 205.79 234
AMBI_S 0.251 0.248 0.676 78.465 0.000 2 -131 269 279 106.95 234
BENTIX 0.108 0.105 1.472 28.475 0.000 2 -315 636 647 506.96 234
BQI 0.006 0.002 2.530 1.528 0.218 2 -443 892 902 1498.12 234
ITI 0.000 -0.004 20.145 0.045 0.833 2 -933 1871 1882 94965.37 234
logN 0.008 0.004 1.589 1.974 0.161 2 -333 672 683 591.12 234
M_AMBI 0.064 0.060 0.163 15.951 0.000 2 205 -403 -393 6.20 234
MEDOCC 0.156 0.153 1.222 43.288 0.000 2 -271 548 559 349.24 234
S 0.005 0.000 7.145 1.104 0.294 2 -688 1382 1392 11945.92 234
TBI 0.003 -0.001 0.183 0.681 0.410 2 176 -347 -336 7.87 234
###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) 2.070 0.097 21.236 0.000 1.878 2.262
AMBI RegionEastern North Island -0.210 0.129 -1.630 0.104 -0.463 0.044
AMBI RegionNorth Eastern -0.232 0.124 -1.876 0.062 -0.477 0.012
AMBI RegionSouthern -0.378 0.121 -3.139 0.002 -0.616 -0.141
AMBI RegionWestern North Island 0.522 0.325 1.605 0.110 -0.119 1.163
AMBI_S (Intercept) 2.050 0.074 27.800 0.000 1.905 2.195
AMBI_S RegionEastern North Island -0.055 0.097 -0.570 0.569 -0.247 0.136
AMBI_S RegionNorth Eastern -0.168 0.094 -1.792 0.074 -0.353 0.017
AMBI_S RegionSouthern -0.250 0.091 -2.740 0.007 -0.430 -0.070
AMBI_S RegionWestern North Island 0.518 0.246 2.105 0.036 0.033 1.003
BENTIX (Intercept) 4.375 0.147 29.789 0.000 4.086 4.665
BENTIX RegionEastern North Island 0.576 0.194 2.973 0.003 0.194 0.958
BENTIX RegionNorth Eastern 0.151 0.187 0.810 0.419 -0.217 0.519
BENTIX RegionSouthern 0.311 0.182 1.714 0.088 -0.047 0.669
BENTIX RegionWestern North Island -1.117 0.490 -2.280 0.024 -2.083 -0.152
BQI (Intercept) 5.102 0.196 26.029 0.000 4.715 5.488
BQI RegionEastern North Island -1.762 0.259 -6.809 0.000 -2.272 -1.252
BQI RegionNorth Eastern 0.921 0.249 3.698 0.000 0.431 1.412
BQI RegionSouthern -0.432 0.242 -1.781 0.076 -0.909 0.046
BQI RegionWestern North Island -0.140 0.654 -0.214 0.831 -1.428 1.149
ITI (Intercept) 30.490 1.747 17.454 0.000 27.048 33.932
ITI RegionEastern North Island 12.459 2.306 5.403 0.000 7.916 17.003
ITI RegionNorth Eastern -1.680 2.221 -0.756 0.450 -6.056 2.696
ITI RegionSouthern -0.636 2.160 -0.295 0.769 -4.892 3.620
ITI RegionWestern North Island -7.671 5.828 -1.316 0.189 -19.153 3.812
logN (Intercept) 3.762 0.118 31.923 0.000 3.530 3.994
logN RegionEastern North Island -0.524 0.156 -3.367 0.001 -0.830 -0.217
logN RegionNorth Eastern 1.120 0.150 7.477 0.000 0.825 1.415
logN RegionSouthern 0.805 0.146 5.525 0.000 0.518 1.092
logN RegionWestern North Island 0.410 0.393 1.042 0.298 -0.365 1.184
M_AMBI (Intercept) 0.551 0.015 36.933 0.000 0.521 0.580
M_AMBI RegionEastern North Island -0.082 0.020 -4.165 0.000 -0.121 -0.043
M_AMBI RegionNorth Eastern 0.040 0.019 2.124 0.035 0.003 0.078
M_AMBI RegionSouthern -0.016 0.018 -0.863 0.389 -0.052 0.020
M_AMBI RegionWestern North Island -0.055 0.050 -1.099 0.273 -0.153 0.043
MEDOCC (Intercept) 2.738 0.126 21.760 0.000 2.490 2.986
MEDOCC RegionEastern North Island -0.391 0.166 -2.355 0.019 -0.718 -0.064
MEDOCC RegionNorth Eastern -0.295 0.160 -1.843 0.067 -0.610 0.020
MEDOCC RegionSouthern -0.500 0.156 -3.211 0.002 -0.806 -0.193
MEDOCC RegionWestern North Island 0.643 0.420 1.532 0.127 -0.184 1.470
S (Intercept) 10.878 0.556 19.569 0.000 9.782 11.973
S RegionEastern North Island -4.389 0.734 -5.981 0.000 -5.834 -2.943
S RegionNorth Eastern 3.191 0.707 4.515 0.000 1.799 4.583
S RegionSouthern -0.160 0.687 -0.233 0.816 -1.514 1.194
S RegionWestern North Island -1.128 1.854 -0.608 0.544 -4.781 2.526
TBI (Intercept) 0.291 0.013 21.730 0.000 0.265 0.318
TBI RegionEastern North Island -0.128 0.018 -7.236 0.000 -0.163 -0.093
TBI RegionNorth Eastern 0.081 0.017 4.755 0.000 0.047 0.115
TBI RegionSouthern -0.038 0.017 -2.322 0.021 -0.071 -0.006
TBI RegionWestern North Island -0.065 0.045 -1.445 0.150 -0.153 0.024
kable(summ_type)
index r.squared adj.r.squared sigma statistic p.value df logLik AIC BIC deviance df.residual
AMBI 0.064 0.048 1.000 3.96 0.004 5 -223 458 479 232.01 232
AMBI_S 0.070 0.054 0.757 4.38 0.002 5 -157 326 347 132.83 232
BENTIX 0.076 0.060 1.507 4.79 0.001 5 -320 653 674 526.98 232
BQI 0.378 0.368 2.011 35.29 0.000 5 -389 790 810 938.29 232
ITI 0.217 0.203 17.924 16.03 0.000 5 -907 1826 1847 74536.73 232
logN 0.432 0.422 1.209 44.05 0.000 5 -268 548 569 339.19 232
M_AMBI 0.181 0.166 0.153 12.78 0.000 5 222 -431 -411 5.43 232
MEDOCC 0.067 0.051 1.291 4.15 0.003 5 -284 580 600 386.67 232
S 0.372 0.361 5.703 34.32 0.000 5 -636 1284 1305 7546.78 232
TBI 0.446 0.436 0.138 46.65 0.000 5 247 -482 -461 4.39 232