-
Notifications
You must be signed in to change notification settings - Fork 0
/
structural-stability-keystone.Rmd
1656 lines (1386 loc) · 87.5 KB
/
structural-stability-keystone.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
---
title: "Bayesian MAR(1) models and structural stability"
author: "Matthew A. Barbour"
date: "`r Sys.Date()`"
output: workflowr::wflow_html
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE}
# set knitr options
knitr::opts_chunk$set(autodep = TRUE, message = FALSE)
# load required libraries:
library(RCurl)
library(brms)
library(tidyverse)
library(cowplot)
library(matlib) # for calculating matrix inverse
library(tidybayes)
library(knitr)
library(rgl)
# these options help Stan run faster:
rstan::rstan_options(auto_write = TRUE)
options(mc.cores = parallel::detectCores())
# set ggplot theme
theme_set(theme_cowplot())
# for interactive rgl plot
knit_hooks$set(webgl = hook_webgl)
```
# Setup
```{r load-time-series}
# load data
timeseries_df <- read_csv("output/timeseries_df.csv") %>%
mutate(# this makes the intercept correspond to rich = 1, rather
# than the biologically implausible rich = 0
rich = rich - 1,
# now rich and temp coefficients will correspond to +1 genotype and +1 C
temp = ifelse(temp == "20 C", 0, 3),
uniq = paste(Cage, temp, com, Week_match, sep = "-"),
Week_match.1p = 1 + Week_match) # analysis doesn't like initial Week_match = 0, so I just added 1
# filter dataset for multivariate analysis.
# I only retain data for which all species had positive abundances at the previous time step
full_df <- filter(timeseries_df, BRBR_t > 0, LYER_t > 0, Ptoid_t > 0) %>%
mutate(aop2_genotypes = Col + gsm1, # corresponds to average effect of genotype with a null AOP2- allele
AOP2_genotypes = AOP2 + AOP2.gsoh) # correspond to average effect of genotype with a functional AOP2+ allele
```
```{r}
## source in useful functions
# functions for plotting feasibility domains and calculating normalized angles from critical boundary
source("code/plot-feasibility-domain.R")
# functions for non-equilibrium simulation
source("code/simulate-community-dynamics.R")
# general functions for evaluating what percentage of posterior is aop2 > AOP2 for the LYER-Ptoid boundary. these functions were important for guiding my model selection
source("code/AOP2-LYER-Ptoid-persistence.R")
```
# Full model
This model corresponds to equation 1 in the Supplementary Material of the paper. Note that `BRBR` = aphid *Brevicoryne brassicae*, `LYER` = aphid *Lipaphis erysimi*, and `Ptoid` = parasitoid *Diaeretiella rapae*.
```{r full-mv-norm-formulas}
# BRBR
full.mv.norm.BRBR.bf <- bf(log1p(BRBR_t1) ~
0 + intercept + offset(log1p(BRBR_t)) +
(log1p(BRBR_t) + log1p(LYER_t) + log1p(Ptoid_t))*(temp + aop2_genotypes + AOP2_genotypes) +
log(Biomass_g_t1) +
(1 | Cage) +
ar(time = Week_match.1p, gr = Cage, p = 1, cov = FALSE))
# LYER
full.mv.norm.LYER.bf <- bf(log1p(LYER_t1) ~
0 + intercept + offset(log1p(LYER_t)) +
(log1p(BRBR_t) + log1p(LYER_t) + log1p(Ptoid_t))*(temp + aop2_genotypes + AOP2_genotypes) +
log(Biomass_g_t1) +
(1 | Cage) +
ar(time = Week_match.1p, gr = Cage, p = 1, cov = FALSE))
# Ptoid
full.mv.norm.Ptoid.bf <- bf(log1p(Ptoid_t1) ~
0 + intercept + offset(log1p(Ptoid_t)) +
(log1p(BRBR_t) + log1p(LYER_t) + log1p(Ptoid_t))*(temp + aop2_genotypes + AOP2_genotypes) +
log(Biomass_g_t1) +
(1 | Cage) +
ar(time = Week_match.1p, gr = Cage, p = 1, cov = FALSE))
```
## Set priors
### Intrinsic growth rates
```{r r-priors}
# from Jahan et al. 2014, Journal of Insect Science
# Table 4 lambda (finite rate of increase, discrete time analogue of intrinsic growth rate)
# calculated on a per-day basis and not logged. This is why I multiply by 7 and then take the natural logarithm
Jahan.r.BRBR <- log(c(1.42, 1.36, 1.32, 1.35, 1.40, 1.33, 1.38, 1.37) * 7)
mean(Jahan.r.BRBR) # 2.26
sd(Jahan.r.BRBR) # 0.02
# visualize prior
hist(rnorm(1000, mean(Jahan.r.BRBR), sd = 1))
prior.r.BRBR <- "normal(2.26, 1)"
# from Taghizadeh 2019, J. Agr. Sci. Tech.
# Table 2 lambda (finite rate of increase, discrete time analogue of intrinsic growth rate)
# calculated on a per-day basis and not logged. This is why I multiply by 7 and then take the natural logarithm
Tag.r.LYER <- log(c(1.35, 1.30, 1.26, 1.23) * 7)
mean(Tag.r.LYER) # 2.20
sd(Tag.r.LYER) # 0.04
# visualize prior
hist(rnorm(1000, mean(Tag.r.LYER), sd = 1))
prior.r.LYER <- "normal(2.20, 1)"
# random effects prior based on variance among cultivars
# I'm just going to use this for all of them
mean.r.sd <- mean(c(sd(Jahan.r.BRBR), sd(Tag.r.LYER)))
# visualize prior
hist(rnorm(1000, mean = mean.r.sd, sd = 0.5))
prior.random.effects <- "normal(0.03, 0.5)"
# I don't have a great sense for the growth rate of the parasitoid, other than that it should be negative
# this seems like a reasonable starting point
# visualize prior
hist(rnorm(1000, mean = -1.5, sd = 1))
prior.r.Ptoid <- "normal(-1.5, 1)"
```
### Intra- and interspecific interactions
I assume they are weak, i.e. much less than $|1|$. I also assume that all species exhibit intraspecific competition, aphids have negative interspecific effects with each other, but positive interspecific effects on the parasitoid. I also assume parasitoids have negative interspecific effects on the aphids.
```{r interaction-priors}
## intraspecific, 0 = no density dependence. this occurs because of offset in model.
# visualize prior
hist(rnorm(1000, mean = -0.1, sd = 0.5))
prior.intra.BRBR <- "normal(-0.1, 0.5)"
prior.intra.LYER <- "normal(-0.1, 0.5)"
prior.intra.Ptoid <- "normal(-0.1, 0.5)"
## negative interspecific, 0 = no interaction
# visualize prior
hist(rnorm(1000, mean = -0.1, sd = 0.5))
# most of these values are less than 1, which
# is indicative of saturating effects
prior.LYERonBRBR <- "normal(-0.1, 0.5)"
prior.PtoidonBRBR <- "normal(-0.1, 0.5)"
prior.BRBRonLYER <- "normal(-0.1, 0.5)"
prior.PtoidonLYER <- "normal(-0.1, 0.5)"
## positive interspecific
# visualize prior
hist(rnorm(1000, mean = 0.1, sd = 0.5))
# most of these values are less than 1, which
# is indicative of saturating effects
prior.BRBRonPtoid <- "normal(0.1, 0.5)"
prior.LYERonPtoid <- "normal(0.1, 0.5)"
```
### AOP2 effects
It was unclear to me *a priori* exactly how allelic differences at *AOP2* would affect species' growth rates or intra- and interspecific interactions. Therefore, I assumed these effects on specific rates could be positive or negative, but would likely be between -1 and 1 (i.e., not ridiculously large).
```{r rich-priors}
prior.rich <- "normal(0, 0.5)"
```
Note that in a previous version of this analysis I assessed the effects of genetic diversity, which is why this is called `prior.rich`. The prior remains the same though, as including both *AOP2*$-$ and *AOP2*$+$ in the same model corresponds to the effect of genetic diversity (i.e. average effect of adding one genotype to the population).
### Temperature effects
As with *AOP2* it was unclear to me *a priori* how warming would affect species' growth rates or intra- and interspecific interactions; therefore, I used the same prior as for *AOP2*.
```{r temp-priors}
prior.temp <- "normal(0, 0.5)"
```
### Biomass effects
For both aphids, I thought that increasing biomass would increase their intrinsic growth rates, but only weakly, because I didn't expect biomass to be limiting.
```{r aphid-biomass-priors}
# visualize prior
hist(rnorm(1000, mean = 0.1, sd = 0.5))
prior.AphidBiomass <- "normal(0.1, 0.5)"
```
For the parasitoid, it was unclear to me whether increasing biomass would have positive or negative effects. I could imagine both, as increasing biomass may increase the search effort of parasitoids, resulting in a negative effect on their growth rate. Alternatively, more biomass may increase the quality of aphids, which could increase the parasitoid's growth rate. Therefore, I specified a normal prior with mean = 0 and SD = 0.5, so that most of the distribution lied between -1 and 1 (i.e. saturating negative or positive effects).
```{r ptoid-biomass-prior}
# visualize prior
hist(rnorm(1000, mean = 0, sd = 0.5))
prior.PtoidBiomass <- "normal(0, 0.5)"
```
## Analysis
I first fit a complete model with *AOP2*$-$ (`aop2_genotypes`), *AOP2*$+$ (`AOP2_genotypes`), and temperature (`temp`) effects.
```{r full-mv-norm-brm}
full.mv.norm.brm <- brm(
data = full_df,
formula = mvbf(full.mv.norm.BRBR.bf, full.mv.norm.LYER.bf, full.mv.norm.Ptoid.bf),
iter = 4000,
prior = c(# growth rates
set_prior(prior.r.BRBR, class = "b", coef = "intercept", resp = "log1pBRBRt1"),
set_prior(prior.r.LYER, class = "b", coef = "intercept", resp = "log1pLYERt1"),
set_prior(prior.r.Ptoid, class = "b", coef = "intercept", resp = "log1pPtoidt1"),
# intraspecific effects
set_prior(prior.intra.BRBR, class = "b", coef = "log1pBRBR_t", resp = "log1pBRBRt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pLYER_t", resp = "log1pLYERt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pPtoid_t", resp = "log1pPtoidt1"),
# negative interspecific effects
set_prior(prior.LYERonBRBR, class = "b", coef = "log1pLYER_t", resp = "log1pBRBRt1"),
set_prior(prior.BRBRonLYER, class = "b", coef = "log1pBRBR_t", resp = "log1pLYERt1"),
set_prior(prior.PtoidonBRBR, class = "b", coef = "log1pPtoid_t", resp = "log1pBRBRt1"),
set_prior(prior.PtoidonLYER, class = "b", coef = "log1pPtoid_t", resp = "log1pLYERt1"),
# positive interspecific effects
set_prior(prior.BRBRonPtoid, class = "b", coef = "log1pBRBR_t", resp = "log1pPtoidt1"),
set_prior(prior.LYERonPtoid, class = "b", coef = "log1pLYER_t", resp = "log1pPtoidt1"),
# aop2 effects
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pPtoidt1"),
# AOP2 effects
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pPtoidt1"),
# temp effects
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pBRBRt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pBRBRt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pBRBRt1"),
set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pBRBRt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pPtoidt1"),
# biomass effects
set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pBRBRt1"),
set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pLYERt1"),
set_prior(prior.PtoidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pPtoidt1"),
# random effects
set_prior(prior.random.effects, class = "sd", resp = "log1pBRBRt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pLYERt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pPtoidt1")),
file = "output/full.mv.norm.brm.keystone.rds")
# print summary
summary(full.mv.norm.brm)
```
## Inspect credible intervals
Below, I inspect which parameters may be safely omitted from the model. It seemed reasonable that if 90% of the posterior probability distribution of the parameter included zero, then I could safely drop it from the model. Therefore, I proceeded with this criteria, starting with the highest-order terms:
```{r full-mv-norm-highest-order}
# higher-order temperature effects
bayesplot::mcmc_intervals(full.mv.norm.brm, regex_pars = "_t:temp$", prob = 0.66, prob_outer = 0.90) # suggests dropping all, but temp effect on reciprocoal BRBR-Ptoid interaction
# higher-order aop2 effects
bayesplot::mcmc_intervals(full.mv.norm.brm, regex_pars = "_t:aop2_genotypes$", prob = 0.66, prob_outer = 0.90) # suggests dropping all but AOP2- effects on Ptoid interactions with LYER and BRBR.
# check biomass effects
bayesplot::mcmc_intervals(full.mv.norm.brm, regex_pars = "_logBiomass_g_t1$", prob = 0.66, prob_outer = 0.90) # drop biomass effect on BRBR and LYER
# other terms currently have higher-order effects with temp and AOP2 present,
# need to drop these higher-order terms before examining these main effects
```
I focus on `aop2_genotypes` effects, but I make sure to always include `AOP2_genotypes` in the model. That way, I'm estimating the effect of genotypes with null *AOP2*$-$ allele after controlling for the effect of genotypes with a functional *AOP2*$+$ allele.
Let's check how the full model does in reproducing the observed effects of the null *AOP2*$-$ in increasing LYER-Ptoid persistence.
```{r warning=F}
pp_aop2_LP_persist(full.mv.norm.brm)
```
`aop2_LPbound_BayesP` calculates the percentage of posterior samples where the null *AOP2*$-$ allele increases LYER-Ptoid persistence relative to the functional *AOP2*$+$ allele (as inferred by an increase in its normalized angle). `aop2_LPbound_effect` calculates the change in the normalized angle from the LYER-Ptoid feasibility boundary for *AOP2*$-$ relative to *AOP2*$+$. As you can see, the full model is unable to reproduce the observed effects of the null *AOP2*$-$ allele in increasing LYER-Ptoid persistence.
# Model selection
## Reduced model 1
### Drop terms
Based on the above plots, I dropped the following higher-order terms:
Effects on **BRBR_t1**:
- `(log1p(LYER_t) + log1p(BRBR_t)):temp`
- `(log1p(LYER_t) + log1p(BRBR_t)):aop2`
- `log(Biomass_g_t1)`
Effects on **LYER_t1**:
- `(log1p(LYER_t) + log1p(BRBR_t) + log1p(Ptoid_t)):temp`
- `(log1p(LYER_t) + log1p(BRBR_t)):aop2`
- `log(Biomass_g_t1)`
Effects on **Ptoid_t1**
- `(log1p(LYER_t) + log1p(Ptoid_t)):temp`
- `(log1p(LYER_t) + log1p(BRBR_t) + log1p(Ptoid_t)):aop2`
### Refit model
```{r reduced-1-brm}
# update formulas
reduced.1.BRBR.bf <- update(full.mv.norm.BRBR.bf, .~.
-(log1p(LYER_t) + log1p(BRBR_t)):aop2_genotypes
-(log1p(LYER_t) + log1p(BRBR_t)):AOP2_genotypes
-(log1p(LYER_t) + log1p(BRBR_t)):temp
-log(Biomass_g_t1))
reduced.1.LYER.bf <- update(full.mv.norm.LYER.bf, .~.
-(log1p(LYER_t) + log1p(BRBR_t) + log1p(Ptoid_t)):temp
-(log1p(LYER_t) + log1p(BRBR_t)):aop2_genotypes
-(log1p(LYER_t) + log1p(BRBR_t)):AOP2_genotypes
-log(Biomass_g_t1))
reduced.1.Ptoid.bf <- update(full.mv.norm.Ptoid.bf, .~.
-(log1p(LYER_t) + log1p(Ptoid_t)):temp
-(log1p(LYER_t) + log1p(BRBR_t) + log1p(Ptoid_t)):aop2_genotypes
-(log1p(LYER_t) + log1p(BRBR_t) + log1p(Ptoid_t)):AOP2_genotypes)
# fit update model
reduced.1.brm <- brm(
data = full_df,
formula = mvbf(reduced.1.BRBR.bf, reduced.1.LYER.bf, reduced.1.Ptoid.bf),
iter = 4000,
prior = c(# growth rates
set_prior(prior.r.BRBR, class = "b", coef = "intercept", resp = "log1pBRBRt1"),
set_prior(prior.r.LYER, class = "b", coef = "intercept", resp = "log1pLYERt1"),
set_prior(prior.r.Ptoid, class = "b", coef = "intercept", resp = "log1pPtoidt1"),
# intraspecific effects
set_prior(prior.intra.BRBR, class = "b", coef = "log1pBRBR_t", resp = "log1pBRBRt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pLYER_t", resp = "log1pLYERt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pPtoid_t", resp = "log1pPtoidt1"),
# negative interspecific effects
set_prior(prior.LYERonBRBR, class = "b", coef = "log1pLYER_t", resp = "log1pBRBRt1"),
set_prior(prior.BRBRonLYER, class = "b", coef = "log1pBRBR_t", resp = "log1pLYERt1"),
set_prior(prior.PtoidonBRBR, class = "b", coef = "log1pPtoid_t", resp = "log1pBRBRt1"),
set_prior(prior.PtoidonLYER, class = "b", coef = "log1pPtoid_t", resp = "log1pLYERt1"),
# positive interspecific effects
set_prior(prior.BRBRonPtoid, class = "b", coef = "log1pBRBR_t", resp = "log1pPtoidt1"),
set_prior(prior.LYERonPtoid, class = "b", coef = "log1pLYER_t", resp = "log1pPtoidt1"),
# aop2 effects
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pPtoidt1"),
# AOP2 effects
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pPtoidt1"),
# temp effects
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pBRBRt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pPtoidt1"),
# biomass effects
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pBRBRt1"),
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pLYERt1"),
set_prior(prior.PtoidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pPtoidt1"),
# random effects
set_prior(prior.random.effects, class = "sd", resp = "log1pBRBRt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pLYERt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pPtoidt1")),
file = "output/reduced.1.brm.keystone.rds")
# print model summary
summary(reduced.1.brm)
```
### Inspect credible intervals
```{r reduced-1-highest-order}
# higher-order temperature effects
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_t:temp$", prob = 0.66, prob_outer = 0.90) # retain these higher-order effects
# higher-order aop2 effects
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_t:aop2_genotypes$", prob = 0.66, prob_outer = 0.90)
# lower-order temp effects
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_temp$", prob = 0.66, prob_outer = 0.90) # drop temp on LYER as there are no higher-order terms
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_aop2_genotypes$", prob = 0.66, prob_outer = 0.90) # retain all, because of higher-order terms for BRBR and LYER
# check biomass effects
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_logBiomass_g_t1$", prob = 0.66, prob_outer = 0.90)
# check other interaction terms
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_log1pPtoid_t$", prob = 0.80, prob_outer = 0.90) # drop intraspecific effect of Ptoid
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_log1pLYER_t$", prob = 0.80, prob_outer = 0.90) # drop LYER effect on BRBR
bayesplot::mcmc_intervals(reduced.1.brm, regex_pars = "_log1pBRBR_t$", prob = 0.80, prob_outer = 0.90) # drop intraspecific effect of BRBR
```
Since there are still terms to drop based on my 90% criteria, Reduced model 1 is an intermediate model that I don't use in my model comparison.
## Reduced model 2
### Drop terms
Based on the above plots, I dropped the following terms:
Effects on **BRBR_t1**:
- `log1p(BRBR_t)`
- `log1p(LYER_t)`
Effects on **LYER_t1**:
- `temp`
Effects on **Ptoid_t1**:
- `log1p(Ptoid_t)`
### Refit model
```{r reduced-2-brm}
# update formulas
reduced.2.BRBR.bf <- update(reduced.1.BRBR.bf, .~. -log1p(BRBR_t) -log1p(LYER_t))
reduced.2.LYER.bf <- update(reduced.1.LYER.bf, .~. -temp)
reduced.2.Ptoid.bf <- update(reduced.1.Ptoid.bf, .~. -log1p(Ptoid_t))
# fit new model
reduced.2.brm <- brm(
data = full_df,
formula = mvbf(reduced.2.BRBR.bf, reduced.2.LYER.bf, reduced.2.Ptoid.bf),
iter = 4000,
prior = c(# growth rates
set_prior(prior.r.BRBR, class = "b", coef = "intercept", resp = "log1pBRBRt1"),
set_prior(prior.r.LYER, class = "b", coef = "intercept", resp = "log1pLYERt1"),
set_prior(prior.r.Ptoid, class = "b", coef = "intercept", resp = "log1pPtoidt1"),
# intraspecific effects
#set_prior(prior.intra.BRBR, class = "b", coef = "log1pBRBR_t", resp = "log1pBRBRt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pLYER_t", resp = "log1pLYERt1"),
#set_prior(prior.intra.LYER, class = "b", coef = "log1pPtoid_t", resp = "log1pPtoidt1"),
# negative interspecific effects
#set_prior(prior.LYERonBRBR, class = "b", coef = "log1pLYER_t", resp = "log1pBRBRt1"),
set_prior(prior.BRBRonLYER, class = "b", coef = "log1pBRBR_t", resp = "log1pLYERt1"),
set_prior(prior.PtoidonBRBR, class = "b", coef = "log1pPtoid_t", resp = "log1pBRBRt1"),
set_prior(prior.PtoidonLYER, class = "b", coef = "log1pPtoid_t", resp = "log1pLYERt1"),
# positive interspecific effects
set_prior(prior.BRBRonPtoid, class = "b", coef = "log1pBRBR_t", resp = "log1pPtoidt1"),
set_prior(prior.LYERonPtoid, class = "b", coef = "log1pLYER_t", resp = "log1pPtoidt1"),
# aop2 effects
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pPtoidt1"),
# AOP2 effects
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pPtoidt1"),
# temp effects
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pPtoidt1"),
# biomass effects
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pBRBRt1"),
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pLYERt1"),
set_prior(prior.PtoidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pPtoidt1"),
# random effects
set_prior(prior.random.effects, class = "sd", resp = "log1pBRBRt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pLYERt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pPtoidt1")),
file = "output/reduced.2.brm.keystone.rds")
# print model summary
summary(reduced.2.brm)
```
### Inspect credible intervals
```{r reduced-2-plots, warning=F}
# higher-order aop2 effects
bayesplot::mcmc_intervals(reduced.2.brm, regex_pars = "_t:aop2_genotypes$", prob = 0.66, prob_outer = 0.90)
# note that one of these intervals doesn't quite meet our 90% criteria and is right on the edge.
broom.mixed::tidy(reduced.2.brm, parameters = "b_log1pLYERt1_log1pPtoid_t:aop2_genotypes", conf.level = 0.90)
# but since the 90% interval is admittedly a bit arbitrary, we can explore effect effect of retaining all terms in this model.
bayesplot::mcmc_intervals(reduced.2.brm, regex_pars = "_aop2_genotypes$", prob = 0.66, prob_outer = 0.90) # retain all because of presence of higher-order terms
```
Now let's check how well the model performed in capturing the effect of *AOP2$-$* on LYER-Ptoid persistence.
```{r warning=F}
pp_aop2_LP_persist(reduced.2.brm, temp.cond = 1.5, aop2.cond = 2)
```
Only 73% of the posterior samples support a positive effect of *AOP2$-$* relative to *AOP2$+$* on LYER-Ptoid persistence. Note that we are still on our way to identify a model based on the 90% cutoff, but I show it above to show that this model still doesn't appear to adequately capture the effect of AOP2.
## Reduced model 3
### Drop terms
Based on the above plots, we will drop the following term:
Effects on **BRBR_t1**:
- keep all
Effects on **LYER_t1**:
- `log1p(Ptoid_t):aop2_genotypes`
Effects on **Ptoid_t1**:
- keep all
### Refit model
```{r reduced-3-brm}
# update formulas
reduced.3.BRBR.bf <- reduced.2.BRBR.bf
reduced.3.LYER.bf <- update(reduced.2.LYER.bf, .~. -log1p(Ptoid_t):aop2_genotypes -log1p(Ptoid_t):AOP2_genotypes)
reduced.3.Ptoid.bf <- reduced.2.Ptoid.bf
# fit new model
reduced.3.brm <- brm(
data = full_df,
formula = mvbf(reduced.3.BRBR.bf, reduced.3.LYER.bf, reduced.3.Ptoid.bf),
iter = 4000,
prior = c(# growth rates
set_prior(prior.r.BRBR, class = "b", coef = "intercept", resp = "log1pBRBRt1"),
set_prior(prior.r.LYER, class = "b", coef = "intercept", resp = "log1pLYERt1"),
set_prior(prior.r.Ptoid, class = "b", coef = "intercept", resp = "log1pPtoidt1"),
# intraspecific effects
#set_prior(prior.intra.BRBR, class = "b", coef = "log1pBRBR_t", resp = "log1pBRBRt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pLYER_t", resp = "log1pLYERt1"),
#set_prior(prior.intra.LYER, class = "b", coef = "log1pPtoid_t", resp = "log1pPtoidt1"),
# negative interspecific effects
#set_prior(prior.LYERonBRBR, class = "b", coef = "log1pLYER_t", resp = "log1pBRBRt1"),
set_prior(prior.BRBRonLYER, class = "b", coef = "log1pBRBR_t", resp = "log1pLYERt1"),
set_prior(prior.PtoidonBRBR, class = "b", coef = "log1pPtoid_t", resp = "log1pBRBRt1"),
set_prior(prior.PtoidonLYER, class = "b", coef = "log1pPtoid_t", resp = "log1pLYERt1"),
# positive interspecific effects
set_prior(prior.BRBRonPtoid, class = "b", coef = "log1pBRBR_t", resp = "log1pPtoidt1"),
set_prior(prior.LYERonPtoid, class = "b", coef = "log1pLYER_t", resp = "log1pPtoidt1"),
# aop2 effects
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pPtoidt1"),
# AOP2 effects
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pPtoidt1"),
set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pPtoidt1"),
# temp effects
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pPtoidt1"),
# biomass effects
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pBRBRt1"),
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pLYERt1"),
set_prior(prior.PtoidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pPtoidt1"),
# random effects
set_prior(prior.random.effects, class = "sd", resp = "log1pBRBRt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pLYERt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pPtoidt1")),
file = "output/reduced.3.brm.keystone.rds")
# print model summary
summary(reduced.3.brm)
```
### Inspect credible intervals
```{r reduced-3-summary}
# check highest-order aop2 effects
bayesplot::mcmc_intervals(reduced.3.brm, regex_pars = "_t:aop2_genotypes$", prob = 0.66, prob_outer = 0.90) # now it appears we should drop the Ptoid:aop2 effect on BRBR.
```
This is still an intermediate model because not all terms meet our 90% criteria.
## Reduced model 4
### Drop terms
Based on the above plots, I dropped the following terms:
Effects on **BRBR_t1**:
- `log1p(Ptoid_t):aop2_genotypes`
Effects on **LYER_t1**:
- keep all
Effects on **Ptoid_t1**:
- keep all
### Refit model
```{r reduced-4-brm}
# update formulas
reduced.4.BRBR.bf <- update(reduced.3.BRBR.bf, .~. -log1p(Ptoid_t):aop2_genotypes -log1p(Ptoid_t):AOP2_genotypes)
reduced.4.LYER.bf <- reduced.3.LYER.bf
reduced.4.Ptoid.bf <- reduced.3.Ptoid.bf
# fit new model
reduced.4.brm <- brm(
data = full_df,
formula = mvbf(reduced.4.BRBR.bf, reduced.4.LYER.bf, reduced.4.Ptoid.bf),
iter = 4000,
prior = c(# growth rates
set_prior(prior.r.BRBR, class = "b", coef = "intercept", resp = "log1pBRBRt1"),
set_prior(prior.r.LYER, class = "b", coef = "intercept", resp = "log1pLYERt1"),
set_prior(prior.r.Ptoid, class = "b", coef = "intercept", resp = "log1pPtoidt1"),
# intraspecific effects
#set_prior(prior.intra.BRBR, class = "b", coef = "log1pBRBR_t", resp = "log1pBRBRt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pLYER_t", resp = "log1pLYERt1"),
#set_prior(prior.intra.LYER, class = "b", coef = "log1pPtoid_t", resp = "log1pPtoidt1"),
# negative interspecific effects
#set_prior(prior.LYERonBRBR, class = "b", coef = "log1pLYER_t", resp = "log1pBRBRt1"),
set_prior(prior.BRBRonLYER, class = "b", coef = "log1pBRBR_t", resp = "log1pLYERt1"),
set_prior(prior.PtoidonBRBR, class = "b", coef = "log1pPtoid_t", resp = "log1pBRBRt1"),
set_prior(prior.PtoidonLYER, class = "b", coef = "log1pPtoid_t", resp = "log1pLYERt1"),
# positive interspecific effects
set_prior(prior.BRBRonPtoid, class = "b", coef = "log1pBRBR_t", resp = "log1pPtoidt1"),
set_prior(prior.LYERonPtoid, class = "b", coef = "log1pLYER_t", resp = "log1pPtoidt1"),
# aop2 effects
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pPtoidt1"),
# AOP2 effects
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pPtoidt1"),
# temp effects
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pPtoidt1"),
# biomass effects
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pBRBRt1"),
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pLYERt1"),
set_prior(prior.PtoidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pPtoidt1"),
# random effects
set_prior(prior.random.effects, class = "sd", resp = "log1pBRBRt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pLYERt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pPtoidt1")),
file = "output/reduced.4.brm.keystone.rds")
# print model summary
summary(reduced.4.brm)
```
### Inspect credible intervals
```{r reduced-4-summary}
# check aop2 effects on growth rates
bayesplot::mcmc_intervals(reduced.4.brm, regex_pars = "_aop2_genotypes$", prob = 0.66, prob_outer = 0.90) # drop aop2 effect on BRBR
```
Again, this model is still an intermediate one because not all terms meet the 90% criteria.
## Reduced model 5
### Drop terms
Based on the above plots, I dropped the following terms:
Effects on **BRBR_t1**:
- `aop2_genotypes`
Effects on **LYER_t1**:
- keep all
Effects on **Ptoid_t1**:
- keep all
### Refit model
```{r reduced-5-brm}
# update formulas
reduced.5.BRBR.bf <- update(reduced.4.BRBR.bf, .~. -aop2_genotypes -AOP2_genotypes)
reduced.5.LYER.bf <- reduced.4.LYER.bf
reduced.5.Ptoid.bf <- reduced.4.Ptoid.bf
# fit new model
reduced.5.brm <- brm(
data = full_df,
formula = mvbf(reduced.5.BRBR.bf, reduced.5.LYER.bf, reduced.5.Ptoid.bf),
iter = 4000,
prior = c(# growth rates
set_prior(prior.r.BRBR, class = "b", coef = "intercept", resp = "log1pBRBRt1"),
set_prior(prior.r.LYER, class = "b", coef = "intercept", resp = "log1pLYERt1"),
set_prior(prior.r.Ptoid, class = "b", coef = "intercept", resp = "log1pPtoidt1"),
# intraspecific effects
#set_prior(prior.intra.BRBR, class = "b", coef = "log1pBRBR_t", resp = "log1pBRBRt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pLYER_t", resp = "log1pLYERt1"),
#set_prior(prior.intra.LYER, class = "b", coef = "log1pPtoid_t", resp = "log1pPtoidt1"),
# negative interspecific effects
#set_prior(prior.LYERonBRBR, class = "b", coef = "log1pLYER_t", resp = "log1pBRBRt1"),
set_prior(prior.BRBRonLYER, class = "b", coef = "log1pBRBR_t", resp = "log1pLYERt1"),
set_prior(prior.PtoidonBRBR, class = "b", coef = "log1pPtoid_t", resp = "log1pBRBRt1"),
set_prior(prior.PtoidonLYER, class = "b", coef = "log1pPtoid_t", resp = "log1pLYERt1"),
# positive interspecific effects
set_prior(prior.BRBRonPtoid, class = "b", coef = "log1pBRBR_t", resp = "log1pPtoidt1"),
set_prior(prior.LYERonPtoid, class = "b", coef = "log1pLYER_t", resp = "log1pPtoidt1"),
# aop2 effects
#set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pPtoidt1"),
# AOP2 effects
#set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pLYERt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pPtoidt1"),
# temp effects
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pPtoidt1"),
set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pPtoid_t:temp", resp = "log1pPtoidt1"),
# biomass effects
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pBRBRt1"),
#set_prior(prior.AphidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pLYERt1"),
set_prior(prior.PtoidBiomass, class = "b", coef = "logBiomass_g_t1", resp = "log1pPtoidt1"),
# random effects
set_prior(prior.random.effects, class = "sd", resp = "log1pBRBRt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pLYERt1"),
set_prior(prior.random.effects, class = "sd", resp = "log1pPtoidt1")),
file = "output/reduced.5.brm.keystone.rds")
# print model summary
summary(reduced.5.brm)
```
### Inspect credible intervals
```{r reduced-5-summary}
# no more higher-order terms, so check aop2 effects on growth rates
bayesplot::mcmc_intervals(reduced.5.brm, regex_pars = "_aop2_genotypes$", prob = 0.66, prob_outer = 0.90)
```
Now, we have a model where all terms meet our 90% criteria. Let's evaluate it's effect on LYER-Ptoid persistence.
```{r warning=F}
pp_aop2_LP_persist(reduced.5.brm, temp.cond = 1.5, aop2.cond = 2)
```
There is clear evidence that *AOP2$-$* promotes LYER-Ptoid persistence relative to *AOP2$+$* in this model.
## Reduced model 6
What about a model where we use a 95% cutoff?
```{r}
bayesplot::mcmc_intervals(reduced.5.brm, regex_pars = "_aop2_genotypes$", prob = 0.66, prob_outer = 0.95) # suggest dropping aop2 effect on Ptoid.
```
### Drop terms
Based on the above plots, I dropped the following terms:
Effects on **BRBR_t1**:
- keep all
Effects on **LYER_t1**:
- keep all
Effects on **Ptoid_t1**:
- `aop2_genotypes`
### Refit model
```{r reduced-6-brm}
# update formulas
reduced.6.BRBR.bf <- reduced.5.BRBR.bf
reduced.6.LYER.bf <- reduced.5.LYER.bf
reduced.6.Ptoid.bf <- update(reduced.5.Ptoid.bf, .~. -aop2_genotypes -AOP2_genotypes)
# fit new model
reduced.6.brm <- brm(
data = full_df,
formula = mvbf(reduced.6.BRBR.bf, reduced.6.LYER.bf, reduced.6.Ptoid.bf),
iter = 4000,
prior = c(# growth rates
set_prior(prior.r.BRBR, class = "b", coef = "intercept", resp = "log1pBRBRt1"),
set_prior(prior.r.LYER, class = "b", coef = "intercept", resp = "log1pLYERt1"),
set_prior(prior.r.Ptoid, class = "b", coef = "intercept", resp = "log1pPtoidt1"),
# intraspecific effects
#set_prior(prior.intra.BRBR, class = "b", coef = "log1pBRBR_t", resp = "log1pBRBRt1"),
set_prior(prior.intra.LYER, class = "b", coef = "log1pLYER_t", resp = "log1pLYERt1"),
#set_prior(prior.intra.LYER, class = "b", coef = "log1pPtoid_t", resp = "log1pPtoidt1"),
# negative interspecific effects
#set_prior(prior.LYERonBRBR, class = "b", coef = "log1pLYER_t", resp = "log1pBRBRt1"),
set_prior(prior.BRBRonLYER, class = "b", coef = "log1pBRBR_t", resp = "log1pLYERt1"),
set_prior(prior.PtoidonBRBR, class = "b", coef = "log1pPtoid_t", resp = "log1pBRBRt1"),
set_prior(prior.PtoidonLYER, class = "b", coef = "log1pPtoid_t", resp = "log1pLYERt1"),
# positive interspecific effects
set_prior(prior.BRBRonPtoid, class = "b", coef = "log1pBRBR_t", resp = "log1pPtoidt1"),
set_prior(prior.LYERonPtoid, class = "b", coef = "log1pLYER_t", resp = "log1pPtoidt1"),
# aop2 effects
#set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:aop2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:aop2_genotypes", resp = "log1pPtoidt1"),
# AOP2 effects
#set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pBRBRt1"),
set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pBRBR_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pLYER_t:AOP2_genotypes", resp = "log1pPtoidt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pBRBRt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pLYERt1"),
#set_prior(prior.rich, class = "b", coef = "log1pPtoid_t:AOP2_genotypes", resp = "log1pPtoidt1"),
# temp effects
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pLYERt1"),
set_prior(prior.temp, class = "b", coef = "log1pBRBR_t:temp", resp = "log1pPtoidt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pBRBRt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pLYERt1"),
#set_prior(prior.temp, class = "b", coef = "log1pLYER_t:temp", resp = "log1pPtoidt1"),