gf <-
  gradientForest(
    cbind(mean_env, mean_fauna),
    predictor.vars = colnames(mean_env),
    response.vars = colnames(mean_fauna),
    ntree = 500,
    transform = NULL,
    compact = T,
    nbin = 201,
    maxLevel = lev,
    corr.threshold = 0.5
  )

gf
## A forest of 500 regression trees for each of 59 species
## 
## Call:
## 
## gradientForest(data = cbind(mean_env, mean_fauna), predictor.vars = colnames(mean_env), 
##     response.vars = colnames(mean_fauna), ntree = 500, transform = NULL, 
##     maxLevel = lev, corr.threshold = 0.5, compact = T, nbin = 201)
## 
## 
## 
## Important variables:
## [1] mud  AFDW Pb   TP   Cu
gf$result %>% 
  data.frame()
##                                                    .
## glyceridae                               0.102260724
## goniadidae                               0.030215161
## nephtyidae                               0.228548127
## nereididae                               0.129890309
## syllidae                                 0.154807850
## owenia                                   0.093362531
## sabellidae                               0.213561262
## magelona                                 0.165026628
## aonides                                  0.332308205
## polydorid complex                        0.017294828
## prionospio                               0.255902773
## scolecolepides                           0.231008147
## microspio                                0.164708610
## spionidae                                0.233519612
## heteromastusfiliformisandbarantollalepte 0.165409162
## capitella                                0.065745229
## maldanidae                               0.212437136
## orbiniidae                               0.120670263
## paraonidae                               0.188053327
## scalibregmatidae                         0.105007266
## amphipoda                                0.269030031
## cumacea                                  0.254137568
## halicarcinus                             0.148599733
## hemiplax hirtipes                        0.088186626
## palaemonidae                             0.177142200
## hemigrapsus                              0.048913078
## isopoda                                  0.030978366
## tanaidacea                               0.090693819
## ostracoda                                0.257318847
## copepoda                                 0.186336373
## actiniidae                               0.233260190
## edwardsia                                0.307865544
## anthozoa                                 0.012994504
## hiatula                                  0.160359116
## mytilidae                                0.011719877
## nuculidae                                0.276481474
## arthritica bifurca                       0.172376721
## lasaea                                   0.282957566
## diplodonta                               0.226335900
## zeacumantus                              0.190148899
## amphibola crenata                        0.081504490
## potamopyrgus                             0.096387491
## notoacmea                                0.133970411
## diloma                                   0.008723071
## nemertea                                 0.170600815
## sipuncula                                0.002587112
## oligochaeta                              0.246524698
## scolelepis                               0.029710189
## scoloplos cylindrifer                    0.182271422
## orbinia papillosa                        0.216949832
## austrohelice crassa                      0.349386705
## macomona liliana                         0.326257595
## austrovenus stutchburyi                  0.323894877
## paphies australis                        0.260029620
## melanopsis                               0.044753969
## halopyrgus pupoides                      0.096256532
## cominella glandiformis                   0.015123378
## nematoda                                 0.202207047
## nicona estuariensis                      0.261942642
gf$overall.imp %>% 
  data.frame()
##               .
## AFDW 0.04093269
## Cu   0.02355860
## mud  0.04502443
## Pb   0.03312813
## TN   0.02325936
## TP   0.03027223
## Zn   0.02056801
gf$overall.imp2 %>% 
  data.frame()
##             .
## AFDW 17.29308
## Cu   11.76664
## mud  18.35672
## Pb   15.93648
## TN   11.24796
## TP   15.93607
## Zn   14.76125
gf$species.pos.rsq
## [1] 59
##Plot predictors overall importance
plot(gf, plot.type = "O")

most_important <-
  names(importance(gf))[1:6]##get most important predictors names
###Split density plot
par(mgp = c(2, 0.75, 0))
plot(
  gf,
  plot.type = "S",
  imp.vars = most_important,
  leg.posn = "topright",
  cex.legend = 0.8,
  cex.axis = 0.9,
  cex.lab = 0.9,
  line.ylab = 0.9,
  par.args = list(mgp = c(1.5, 0.5, 0), mar = c(3.1, 1.5, 0.1, 1))
)

##Species cummulative plot
plot(
  gf,
  plot.type = "C",
  imp.vars = most_important,
  show.overall = F,
  legend = T,
  leg.posn = "topleft",
  leg.nspecies = 5,
  cex.lab = 1,
  cex.legend = 1,
  cex.axis = 1,
  line.ylab = 1,
  par.args = list(
    mgp = c(1.5, 0.5, 0),
    mar = c(2.5, 1, 0.1, 0.5),
    omi = c(0, 0.3, 0, 0)
  )
)

##Predictor cummulative plot across all species
plot(
  gf,
  plot.type = "C",
  imp.vars = most_important,
  show.species = F,
  common.scale = T,
  cex.axis = 1,
  cex.lab = 1,
  line.ylab = 0.9,
  par.args = list(
    mgp = c(1.5, 0.5, 0),
    mar = c(2.5, 1, 0.1, 0.5),
    omi = c(0, 0.3, 0, 0)
  )
)

Boosted regression tress on selected taxa shown as important in the gradient forest analysis

Macomona liliana

###gbm macomona #####
par(
  mfrow = c(2, 4),
  mgp = c(1.5, .5, 0),
  mar = c(2.5, 1.5, 0.5, 0.5),
  omi = c(.2, 0.1, 0, 0)
)

summary(gbm_maco,n.trees=best.iter)
##       var   rel.inf
## mud   mud 47.712980
## AFDW AFDW 25.800480
## TP     TP 11.169760
## Pb     Pb  5.487283
## Zn     Zn  4.431558
## TN     TN  3.713017
## Cu     Cu  1.684922
plot(gbm_maco, 1, best.iter)
plot(gbm_maco, 2, best.iter)
plot(gbm_maco, 3, best.iter)
plot(gbm_maco, 4, best.iter)
plot(gbm_maco, 5, best.iter)
plot(gbm_maco, 6, best.iter)
plot(gbm_maco, 7, best.iter)

Paphies australis

par(
  mfrow = c(2, 4),
  mgp = c(1.5, .5, 0),
  mar = c(2.5, 1.5, 0.5, 0.5),
  omi = c(.2, 0.1, 0, 0)
)
summary(gbm_pipi,n.trees=best.iter)
##       var    rel.inf
## mud   mud 43.6866225
## AFDW AFDW 26.2150916
## TP     TP 14.7807624
## Zn     Zn  9.1099272
## Pb     Pb  4.5143656
## TN     TN  1.3215681
## Cu     Cu  0.3716628
plot(gbm_pipi,1,best.iter)
plot(gbm_pipi,2,best.iter)
plot(gbm_pipi,3,best.iter)
plot(gbm_pipi,4,best.iter)
plot(gbm_pipi,5,best.iter)
plot(gbm_pipi,6,best.iter)
plot(gbm_pipi,7,best.iter)

Heteromastus filiformis

par(
  mfrow = c(2, 4),
  mgp = c(1.5, .5, 0),
  mar = c(2.5, 1.5, 0.5, 0.5),
  omi = c(.2, 0.1, 0, 0)
)
summary(gbm_hetero,n.trees=best.iter)
##       var   rel.inf
## AFDW AFDW 29.697820
## mud   mud 26.072365
## Zn     Zn 14.950192
## TP     TP 11.169351
## Pb     Pb  9.541188
## TN     TN  4.596076
## Cu     Cu  3.973008
plot(gbm_hetero,1,best.iter)
plot(gbm_hetero,2,best.iter)
plot(gbm_hetero,3,best.iter)
plot(gbm_hetero,4,best.iter)
plot(gbm_hetero,5,best.iter)
plot(gbm_hetero,6,best.iter)
plot(gbm_hetero,7,best.iter)

Oligochaeta

par(
  mfrow = c(2, 4),
  mgp = c(1.5, .5, 0),
  mar = c(2.5, 1.5, 0.5, 0.5),
  omi = c(.2, 0.1, 0, 0)
)
summary(gbm_oligo,n.trees=best.iter)
##       var   rel.inf
## AFDW AFDW 50.271477
## TP     TP 34.096233
## mud   mud  8.054585
## Pb     Pb  3.053457
## Cu     Cu  2.578858
## Zn     Zn  1.945389
## TN     TN  0.000000
plot(gbm_oligo,1,best.iter)
plot(gbm_oligo,2,best.iter)
plot(gbm_oligo,3,best.iter)
plot(gbm_oligo,4,best.iter)
plot(gbm_oligo,5,best.iter)
plot(gbm_oligo,6,best.iter)
plot(gbm_oligo,7,best.iter)

Austrovenus stutchburyi

par(
  mfrow = c(2, 4),
  mgp = c(1.5, .5, 0),
  mar = c(2.5, 1.5, 0.5, 0.5),
  omi = c(.2, 0.1, 0, 0)
)
summary(gbm_cockle,best.iter)
##       var   rel.inf
## mud   mud 36.211703
## AFDW AFDW 34.640564
## Pb     Pb  8.591573
## Zn     Zn  8.348554
## TP     TP  8.241761
## TN     TN  2.429671
## Cu     Cu  1.536173
plot(gbm_cockle,1,best.iter)
plot(gbm_cockle,2,best.iter)
plot(gbm_cockle,3,best.iter)
plot(gbm_cockle,4,best.iter)
plot(gbm_cockle,5,best.iter)
plot(gbm_cockle,6,best.iter)
plot(gbm_cockle,7,best.iter)