-
Notifications
You must be signed in to change notification settings - Fork 2
/
Sahul megafauna demographic susceptibility-base models.R
5783 lines (4724 loc) · 227 KB
/
Sahul megafauna demographic susceptibility-base models.R
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
##########################################################################################################################################
## megafauna demographic susceptibility model
## AIM: construct plausible stochastic demographic models for main Sahul megafauna to determine relative demographic
## susceptibility to environmental change & novel predation (human) sources
##
## VOMBATIFORM HERBIVORES: ✓Diprotodon (†), ✓Palorchestes (†), ✓Zygomaturus (†), ✓Phascolonus (†), ✓Vombatus ursinus
## MACROPODIFORM HERBIVORES: ✓Protemnodon (†), ✓Osphranter rufus, ✓Sthenurus (†), ✓Simosthenurus (†), ✓Procoptodon (†), ✓Metasthenurus (†), ✓Notamacropus
## LARGE BIRDS: ✓Genyornis (†), ✓Dromaius novaehollandiae, ✓Alectura lathami
## CARNIVORES: ✓Sarcophilus, ✓Thylacinus (†), ✓Thylacoleo (†), ✓Dasyurus
## MONOTREMES: ✓Megalibgwilia (†), ✓Tachyglossus
##
## Corey Bradshaw
## Flinders University, August 2020
##########################################################################################################################################
## functions
# beta distribution shape parameter estimator function
estBetaParams <- function(mu, var) {
alpha <- ((1 - mu) / var - 1 / mu) * mu ^ 2
beta <- alpha * (1 / mu - 1)
return(params = list(alpha = alpha, beta = beta))
}
AICc <- function(...) {
models <- list(...)
num.mod <- length(models)
AICcs <- numeric(num.mod)
ns <- numeric(num.mod)
ks <- numeric(num.mod)
AICc.vec <- rep(0,num.mod)
for (i in 1:num.mod) {
if (length(models[[i]]$df.residual) == 0) n <- models[[i]]$dims$N else n <- length(models[[i]]$residuals)
if (length(models[[i]]$df.residual) == 0) k <- sum(models[[i]]$dims$ncol) else k <- (length(models[[i]]$coeff))+1
AICcs[i] <- (-2*logLik(models[[i]])) + ((2*k*n)/(n-k-1))
ns[i] <- n
ks[i] <- k
AICc.vec[i] <- AICcs[i]
}
return(AICc.vec)
}
delta.AIC <- function(x) x - min(x) ## where x is a vector of AIC
weight.AIC <- function(x) (exp(-0.5*x))/sum(exp(-0.5*x)) ## Where x is a vector of dAIC
ch.dev <- function(x) ((( as.numeric(x$null.deviance) - as.numeric(x$deviance) )/ as.numeric(x$null.deviance))*100) ## % change in deviance, where x is glm object
linreg.ER <- function(x,y) { # where x and y are vectors of the same length; calls AICc, delta.AIC, weight.AIC functions
fit.full <- lm(y ~ x); fit.null <- lm(y ~ 1)
AIC.vec <- c(AICc(fit.full),AICc(fit.null))
dAIC.vec <- delta.AIC(AIC.vec); wAIC.vec <- weight.AIC(dAIC.vec)
ER <- wAIC.vec[1]/wAIC.vec[2]
r.sq.adj <- as.numeric(summary(fit.full)[9])
return(c(ER,r.sq.adj))
}
## source
source("matrixOperators.r")
# MACROPOD CORRECTIONS (data from Fisher et al. 2001. The ecological basis of life history variation in marsupials. Ecology 82:3531-3540. doi:10.1890/0012-9658(2001)082[3531:TEBOLH]2.0.CO;2)
# mass
NR.mass <- 5.1 # Notamacropus rufogriseus
OR.mass <- 25 # Osphranter rufus
DOL.mass <- 3.57 # Dorcopsis luctuosa
LC.mass <- 3 # Lagorchestes conspicillatus
LH.mass <- 1.3 # L. hirsutus
LF.mass <- 1.8 # L. fasciatus
MAg.mass <- 11 # Macropus agilis
MAn.mass <- 17.5 # M. antilopus
MDo.mass <- 6.5 # M. dorsalis
MFu.mass <- 16 # M. fuliginosus
MGi.mass <- 17.8 # M. giganteus
MPa.mass <- 3.55 # M. parma
MParr.mass <- 11 # M. parryi
MRo.mass <- 15.6 # M. robustus
PAs.mass <- 4.3 # Petrogale assimilis
PI.mass <- 4.2 # P. inomata
PP.mass <- 6.3 # P. penicillata
PPe.mass <- 5.2 # P. persephone
PX.mass <- 7 # P. xanthopus
TB.mass <- 3.9 # Thylogale billardienii
TS.mass <- 4.1 # T. stigmatica
TT.mass <- 3.8 # T. thetis
WB.mass <- 13.0 # Wallabia bicolor
# inter-birth interval
NR.IBI <- 286
OR.IBI <- 241
DOL.IBI <- 191
LC.IBI <- 153
LH.IBI <- 125
LF.IBI <- 365
MAg.IBI <- 220
MAn.IBI <- 270
MDo.IBI <- 211
MFu.IBI <- 372
MGi.IBI <- 363
MPa.IBI <- 213
MParr.IBI <- 266
MRo.IBI <- mean(c(256,264))
PAs.IBI <- 200
PI.IBI <- 210
PP.IBI <- 205
PPe.IBI <- 209
PX.IBI <- 196
TB.IBI <- 204
TS.IBI <- 185
TT.IBI <- 182
WB.IBI <- 256
MACROPOD.IBI <- c(NR.IBI,OR.IBI,DOL.IBI,LC.IBI,LH.IBI,LF.IBI,MAg.IBI,MAn.IBI,MDo.IBI,MFu.IBI,MGi.IBI,MPa.IBI,MParr.IBI,MRo.IBI,PAs.IBI,PI.IBI,PP.IBI,PPe.IBI,PX.IBI,TB.IBI,TS.IBI,TT.IBI,WB.IBI)
MACROPOD.mass <- c(NR.mass,OR.mass,DOL.mass,LC.mass,LH.mass,LF.mass,MAg.mass,MAn.mass,MDo.mass,MFu.mass,MGi.mass,MPa.mass,MParr.mass,MRo.mass,PAs.mass,PI.mass,PP.mass,PPe.mass,PX.mass,TB.mass,TS.mass,TT.mass,WB.mass)
plot(log10(MACROPOD.mass), MACROPOD.IBI, pch=19)
linreg.ER(log10(MACROPOD.mass), MACROPOD.IBI)
IBImass.fit <- lm(MACROPOD.IBI ~ log10(MACROPOD.mass))
summary(IBImass.fit)
abline(h=mean(MACROPOD.IBI), lty=2)
abline(IBImass.fit, lty=2, col="red")
MACROPOD.F.corr1 <- 365/mean(MACROPOD.IBI)
MACROPOD.F.corr1
MACROPOD.F.corr.a <- coef(IBImass.fit)[1]
MACROPOD.F.corr.b <- coef(IBImass.fit)[2]
# age at first breeding
NR.alpha <- mean(c(412,420,390))
OR.alpha <- mean(c(913,613))
DOL.alpha <- 450
LC.alpha <- 363
LH.alpha <- mean(c(315,345))
LF.alpha <- 365
MAg.alpha <- mean(c(405,357))
MAn.alpha <- 802
MDo.alpha <- 420
MFu.alpha <- mean(c(604,420))
MGi.alpha <- mean(c(660,600))
MPa.alpha <- 424
MParr.alpha <- mean(c(630,586))
MRo.alpha <- mean(c(535,613,909))
PAs.alpha <- 525
PI.alpha <- 540
PP.alpha <- 540
PPe.alpha <- 683
PX.alpha <- 541
TB.alpha <- 392
TS.alpha <- mean(c(341,336))
TT.alpha <- mean(c(510,600))
WB.alpha <- 450
# predicted age at first breeding
NR.alpha.pred <- (exp(-1.34 + (0.214*log(NR.mass*1000))))
OR.alpha.pred <- (exp(-1.34 + (0.214*log(OR.mass*1000))))
DOL.alpha.pred <- (exp(-1.34 + (0.214*log(DOL.mass*1000))))
LC.alpha.pred <- (exp(-1.34 + (0.214*log(LC.mass*1000))))
LH.alpha.pred <- (exp(-1.34 + (0.214*log(LH.mass*1000))))
LF.alpha.pred <- (exp(-1.34 + (0.214*log(LF.mass*1000))))
MAg.alpha.pred <- (exp(-1.34 + (0.214*log(MAg.mass*1000))))
MAn.alpha.pred <- (exp(-1.34 + (0.214*log(MAn.mass*1000))))
MDo.alpha.pred <- (exp(-1.34 + (0.214*log(MDo.mass*1000))))
MFu.alpha.pred <- (exp(-1.34 + (0.214*log(MFu.mass*1000))))
MGi.alpha.pred <- (exp(-1.34 + (0.214*log(MGi.mass*1000))))
MPa.alpha.pred <- (exp(-1.34 + (0.214*log(MPa.mass*1000))))
MParr.alpha.pred <- (exp(-1.34 + (0.214*log(MParr.mass*1000))))
MRo.alpha.pred <- (exp(-1.34 + (0.214*log(MRo.mass*1000))))
PAs.alpha.pred <- (exp(-1.34 + (0.214*log(PAs.mass*1000))))
PI.alpha.pred <- (exp(-1.34 + (0.214*log(PI.mass*1000))))
PP.alpha.pred <- (exp(-1.34 + (0.214*log(PP.mass*1000))))
PPe.alpha.pred <- (exp(-1.34 + (0.214*log(PPe.mass*1000))))
PX.alpha.pred <- (exp(-1.34 + (0.214*log(PX.mass*1000))))
TB.alpha.pred <- (exp(-1.34 + (0.214*log(TB.mass*1000))))
TS.alpha.pred <- (exp(-1.34 + (0.214*log(TS.mass*1000))))
TT.alpha.pred <- (exp(-1.34 + (0.214*log(TT.mass*1000))))
WB.alpha.pred <- (exp(-1.34 + (0.214*log(WB.mass*1000))))
MACROPOD.alpha.vec <- c(NR.alpha,OR.alpha,DOL.alpha,LC.alpha,LH.alpha,LF.alpha,MAg.alpha,MAn.alpha,MDo.alpha,MFu.alpha,MGi.alpha,MPa.alpha,MParr.alpha,MRo.alpha,PAs.alpha,PI.alpha,PP.alpha,PPe.alpha,PX.alpha,TB.alpha,TS.alpha,TT.alpha,WB.alpha)
MACROPOD.alpha.pred.vec <- c(NR.alpha.pred,OR.alpha.pred,DOL.alpha.pred,LC.alpha.pred,LH.alpha.pred,LF.alpha.pred,MAg.alpha.pred,MAn.alpha.pred,MDo.alpha.pred,MFu.alpha.pred,MGi.alpha.pred,MPa.alpha.pred,MParr.alpha.pred,MRo.alpha.pred,PAs.alpha.pred,PI.alpha.pred,PP.alpha.pred,PPe.alpha.pred,PX.alpha.pred,TB.alpha.pred,TS.alpha.pred,TT.alpha.pred,WB.alpha.pred)
MACROPOD.alpha.vec.yr <- MACROPOD.alpha.vec/365
mean((MACROPOD.alpha.pred.vec - MACROPOD.alpha.vec.yr) / MACROPOD.alpha.pred.vec)
MACROPOD.alpha.corr <- mean(MACROPOD.alpha.vec)/365 / mean(MACROPOD.alpha.pred.vec)
MACROPOD.alpha.corr
plot(MACROPOD.mass, MACROPOD.alpha.vec, pch=19)
# VOMBATIFORM CORRECTIONS
# mass
PC.mass <- 5.1
VU.mass <- 25
LL.mass <- 26
LK.mass <- 31
# inter-birth interval
PC.IBI <- 383 # koala interbirth interval (Martin, R.W. & Handasyde, K.A. 1995 Koala In The Australian Museum complete book of Australian Mammals (ed. R. Strahan) pp.196-198. Sydney: Reed Books)
VU.IBI <- 730 # Vombatus ursinus
LL.IBI <- 365 # southern hairy-nosed wombat
LK.IBI <- 548 # northern hairy-nosed wombat
# age at first breeding (from Fisher et al. 2001)
PC.alpha <- 2
VU.alpha <- 2
LL.alpha <- round(mean(c(1095,540))/365, 0)
# predicted age at first breeding
PC.alpha.pred <- ceiling(exp(-1.34 + (0.214*log(PC.mass*1000))))
VU.alpha.pred <- ceiling(exp(-1.34 + (0.214*log(VU.mass*1000))))
LL.alpha.pred <- ceiling(exp(-1.34 + (0.214*log(LL.mass*1000))))
VOMBAT.alpha.corr <- mean(c(PC.alpha,VU.alpha,LL.alpha)) / mean(c(PC.alpha.pred,VU.alpha.pred,LL.alpha.pred))
VOMBAT.alpha.corr
VOMBAT.IBI <- c(PC.IBI,VU.IBI,LL.IBI,LK.IBI)
VOMBAT.mass <- c(PC.mass,VU.mass,LL.mass,LK.mass)
plot((VOMBAT.mass), VOMBAT.IBI, pch=19)
abline(h=mean(VOMBAT.IBI), lty=2)
VOMBAT.F.corr <- 365/mean(VOMBAT.IBI)
VOMBAT.F.corr
# use macropod relationship to project vombatiforms
mass.range.vec <- seq(1,DP.mass,1)
VOMBAT.IBI.pred <- mean(VOMBAT.IBI) + (MACROPOD.F.corr.b * log10(mass.range.vec))
plot(log10(mass.range.vec),VOMBAT.IBI.pred, type="l", ylim=c(min(VOMBAT.IBI),max(VOMBAT.IBI.pred)))
abline(h=mean(VOMBAT.IBI), lty=2)
points(log10(VOMBAT.mass), VOMBAT.IBI, pch=19)
VOMBAT.EXT.mass <- c(DP.mass, PA.mass, ZT.mass, PH.mass)
VOMBAT.IBI.EXT.pred <- mean(VOMBAT.IBI) + (MACROPOD.F.corr.b * log10(VOMBAT.EXT.mass))
points(log10(VOMBAT.EXT.mass), VOMBAT.IBI.EXT.pred, pch=19, col="red")
# as above, but anchor relationship to VU
VU.IBI.pred <- as.numeric(mean(VOMBAT.IBI) + (MACROPOD.F.corr.b * log10(VU.mass)))
VOMBAT.IBI.pred2 <- (mean(VOMBAT.IBI) + (VU.IBI - VU.IBI.pred)) + (MACROPOD.F.corr.b * log10(mass.range.vec))
plot(log10(mass.range.vec),VOMBAT.IBI.pred2, type="l", ylim=c(min(VOMBAT.IBI),max(VOMBAT.IBI.pred2)))
points(log10(VOMBAT.mass), VOMBAT.IBI, pch=19)
VOMBAT.IBI.EXT.pred2 <- (mean(VOMBAT.IBI) + (VU.IBI - VU.IBI.pred)) + (MACROPOD.F.corr.b * log10(VOMBAT.EXT.mass))
points(log10(VOMBAT.EXT.mass), VOMBAT.IBI.EXT.pred2, pch=19, col="red")
## BASE MODELS
############################
## DIPROTODON (optatum) (DP)
## sources: Brook & Johnson 2006 (Alcheringa 30:39-48, http://doi.org/10.1080/03115510609506854)
# mass
DP.mass <- 2786 # kg (Wroe et al. 2004 PRSB 271:S34-S36)
## predicted rm (from Henneman 1983 Oecologia 56:104-108)
## log10rm = 0.6914 - 0.2622*log10m (mass in g)
DP.rm.pred <- 10^(0.6914 - (0.2622*log10(DP.mass*1000)))
DP.lm.pred <- exp(DP.rm.pred)
## theoretical population density for mammalian herbivores based on body size (Damuth 1981; Freeland 1990)
## log10D = 4.196 − 0.74*(log10m)
DP.D.pred <- (10^(4.196 - (0.74*log10(DP.mass*1000))))/2 # divided by 2 for females only
DP.D.pred # animals/km2
## max age
## non-volant birds & mammals (Healy K et al. 2014 PRSB)
## log10ls = 0.89 + 0.13log10m (mass in grams; ls = years)
DP.age.max1 <- round(10^(0.89 + (0.13*log10(DP.mass*1000))), 0)
DP.age.max <- round(DP.age.max1 * 26/29, 0) # corrected for over-estimate derived from Vombatus
## age vector
DP.age.vec <- 0:DP.age.max
## fertility
## total fecundity from Allainé et al. 1987 (Oecologia)
## lnF = 2.719 - 0.211lnM (all mammals)
DP.F.pred1 <- exp(2.719 - (0.211*log(DP.mass*1000)))/2 # divided by 2 for females
DP.F.pred <- DP.F.pred1 * (365/as.numeric((mean(VOMBAT.IBI) + (VU.IBI - VU.IBI.pred)) + (MACROPOD.F.corr.b * log10(DP.mass))))
## age at primiparity
## lnalpha = 0.214 + 0.263*lnM (https://dx.doi.org/10.1093%2Fgerona%2F62.2.149)
DP.alpha1 <- ceiling(exp(-1.34 + (0.214*log(DP.mass*1000))))
DP.alpha <- DP.alpha1
## define m function with age
DP.m.vec <- c(rep(0, DP.alpha-1), rep(0.75*DP.F.pred, round(DP.alpha/2,0)), rep(DP.F.pred, (DP.age.max+1-((DP.alpha-1+round(DP.alpha/2,0))))))
DP.m.sd.vec <- 0.05*DP.m.vec
plot(DP.age.vec, DP.m.vec, type="b", pch=19, xlab="age (yrs)", ylab="m")
# fit sigmoidal function
# logistic power function y = a / (1+(x/b)^c)
DP.m.dat <- data.frame(DP.age.vec, DP.m.vec)
param.init <- c(0.3, 6, -5)
DP.fit.logp <- nls(DP.m.vec ~ a / (1+(DP.age.vec/b)^c),
data = DP.m.dat,
algorithm = "port",
start = c(a = param.init[1], b = param.init[2], c = param.init[3]),
trace = TRUE,
nls.control(maxiter = 1000, tol = 1e-05, minFactor = 1/1024))
DP.fit.logp.summ <- summary(DP.fit.logp)
plot(DP.age.vec, DP.m.vec, type="b", pch=19, xlab="age (yrs)", ylab="m")
DP.age.vec.cont <- seq(0,max(DP.age.vec),1)
DP.pred.p.m <- coef(DP.fit.logp)[1] / (1+(DP.age.vec.cont/coef(DP.fit.logp)[2])^coef(DP.fit.logp)[3])
DP.pred.p.mm <- ifelse(DP.pred.p.m > 1, 1, DP.pred.p.m)
lines(DP.age.vec.cont, DP.pred.p.mm,lty=2,lwd=3,col="red")
## survival
## mean adult survival (McCarthy et al. 2008 Am Nat)
## ln{-ln[s(t)]} = ln(a) + bln(M) + ln (t)
ln.a.s <- -0.5; b.s <- -0.25
DP.s.tran <- ln.a.s + b.s*log(DP.mass*1000) + log(1)
DP.s.ad.yr <- exp(-exp(DP.s.tran))
# Siler hazard h(x) (Gurven et al. 2007)
a1 <- 1 - (1*DP.s.ad.yr) # initial infant mortality rate (also known as αt)
b1 <- 1.0 # rate of mortality decline (also known as bt)
a2 <- 1 - DP.s.ad.yr # age-independent mortality (exogenous mortality due to environment); also known as ct
a3 <- 0.9e-04 # initial adult mortality rate (also known as βt)
b3 <- 0.05 # rate of mortality increase
longev <- DP.age.max
x <- seq(0,longev,1) # age vector
h.x <- a1 * exp(-b1*x) + a2 + a3 * exp(b3 * x) # Siler's hazard model
plot(x,h.x,pch=19,type="l")
plot(x,log(h.x),pch=19,type="l")
l.x <- exp((-a1/b1) * (1 - exp(-b1*x))) * exp(-a2 * x) * exp(a3/b3 * (1 - exp(b3 * x))) # Siler's survival (proportion surviving) model
init.pop <- 10000
lx <- round(init.pop*l.x,0)
len.lx <- length(lx)
dx <- lx[1:(len.lx-1)]-lx[2:len.lx]
qx <- dx/lx[1:(length(lx)-1)]
DP.Sx <- c(0.99*DP.s.ad.yr, 1 - qx)
plot(x, DP.Sx, pch=19, type="l", xlab="age (years)", ylab="Sx")
DP.s.sd.vec <- 0.05*DP.Sx
## create matrix
DP.popmat <- matrix(data = 0, nrow=DP.age.max+1, ncol=DP.age.max+1)
diag(DP.popmat[2:(DP.age.max+1),]) <- DP.Sx[-(DP.age.max+1)]
DP.popmat[DP.age.max+1,DP.age.max+1] <- DP.Sx[DP.age.max+1]
DP.popmat[1,] <- DP.pred.p.mm
colnames(DP.popmat) <- c(0:DP.age.max)
rownames(DP.popmat) <- c(0:DP.age.max)
DP.popmat.orig <- DP.popmat ## save original matrix
## matrix properties
max.lambda(DP.popmat.orig) ## 1-yr lambda
DP.lm.pred
max.r(DP.popmat.orig) # rate of population change, 1-yr
DP.ssd <- stable.stage.dist(DP.popmat.orig) ## stable stage distribution
plot(DP.age.vec, DP.ssd, type="l", pch=19, xlab="age (yrs)", ylab="ssd")
R.val(DP.popmat.orig, DP.age.max) # reproductive value
DP.gen.l <- G.val(DP.popmat.orig, DP.age.max) # mean generation length
## initial population vector
area <- 500*500 # km × km = 250,000 km^2; equates to approximatley 10% larger than State of Victoria (227,444 km^2)
DP.pop.found <- round(area*DP.D.pred, 0) # founding population size (estimated density * 100 × 100 km region [10,000 km2])
DP.init.vec <- DP.ssd * DP.pop.found
#################
## project
## set time limit for projection in 1-yr increments
yr.st <- 1
#************************
yr.end <- round(40*DP.gen.l, 0) # set projection end date
#************************
t <- (yr.end - yr.st)
DP.tot.F <- sum(DP.popmat.orig[1,])
DP.popmat <- DP.popmat.orig
yr.vec <- seq(yr.st,yr.end)
## set population storage matrices
DP.n.mat <- matrix(0, nrow=DP.age.max+1,ncol=(t+1))
DP.n.mat[,1] <- DP.init.vec
## set up projection loop
for (i in 1:t) {
DP.n.mat[,i+1] <- DP.popmat %*% DP.n.mat[,i]
}
DP.n.pred <- colSums(DP.n.mat)
yrs <- seq(yr.st, yr.end, 1)
plot(yrs, log10(DP.n.pred),type="l",lty=2,pch=19,xlab="year",ylab="log10 N")
# compensatory density feedback
DP.K.max <- 1*DP.pop.found
DP.K.vec <- c(1, DP.K.max/2, 0.75*DP.K.max, DP.K.max)
DP.red.vec <- c(1,0.98,0.96,0.9383)
plot(DP.K.vec, DP.red.vec,pch=19,type="b")
DP.Kred.dat <- data.frame(DP.K.vec, DP.red.vec)
# logistic power function a/(1+(x/b)^c)
DP.param.init <- c(1, 2*DP.K.max, 2)
DP.fit.lp <- nls(DP.red.vec ~ a/(1+(DP.K.vec/b)^c),
data = DP.Kred.dat,
algorithm = "port",
start = c(a = DP.param.init[1], b = DP.param.init[2], c = DP.param.init[3]),
trace = TRUE,
nls.control(maxiter = 1000, tol = 1e-05, minFactor = 1/1024))
DP.fit.lp.summ <- summary(DP.fit.lp)
plot(DP.K.vec, DP.red.vec, pch=19,xlab="N",ylab="reduction factor")
DP.K.vec.cont <- seq(1,2*DP.pop.found,1)
DP.pred.lp.fx <- coef(DP.fit.lp)[1]/(1+(DP.K.vec.cont/coef(DP.fit.lp)[2])^coef(DP.fit.lp)[3])
lines(DP.K.vec.cont, DP.pred.lp.fx, lty=3,lwd=3,col="red")
DP.a.lp <- coef(DP.fit.lp)[1]
DP.b.lp <- coef(DP.fit.lp)[2]
DP.c.lp <- coef(DP.fit.lp)[3]
## compensatory density-feedback deterministic model
## set population storage matrices
DP.n.mat <- matrix(0, nrow=DP.age.max+1, ncol=(t+1))
DP.n.mat[,1] <- DP.init.vec
DP.popmat <- DP.popmat.orig
## set up projection loop
for (i in 1:t) {
DP.totN.i <- sum(DP.n.mat[,i])
DP.pred.red <- as.numeric(DP.a.lp/(1+(DP.totN.i/DP.b.lp)^DP.c.lp))
diag(DP.popmat[2:(DP.age.max+1),]) <- (DP.Sx[-(DP.age.max+1)])*DP.pred.red
DP.popmat[DP.age.max+1,DP.age.max+1] <- (DP.Sx[DP.age.max+1])*DP.pred.red
DP.popmat[1,] <- DP.pred.p.mm
DP.n.mat[,i+1] <- DP.popmat %*% DP.n.mat[,i]
}
DP.n.pred <- colSums(DP.n.mat)
plot(yrs, DP.n.pred, type="l",lty=2,pch=19,xlab="year",ylab="N")
abline(h=DP.pop.found, lty=2, col="red", lwd=2)
## stochatic projection with density feedback
## set storage matrices & vectors
iter <- 100
itdiv <- iter/10
DP.n.sums.mat <- matrix(data=NA, nrow=iter, ncol=(t+1))
DP.s.arr <- DP.m.arr <- array(data=NA, dim=c(t+1, DP.age.max+1, iter))
for (e in 1:iter) {
DP.popmat <- DP.popmat.orig
DP.n.mat <- DP.s.mat <- DP.m.mat <- matrix(0, nrow=DP.age.max+1,ncol=(t+1))
DP.n.mat[,1] <- DP.init.vec
DP.s.mat[,1] <- DP.Sx
DP.m.mat[,1] <- DP.pred.p.mm
for (i in 1:t) {
# stochastic survival values
DP.s.alpha <- estBetaParams(DP.Sx, DP.s.sd.vec^2)$alpha
DP.s.beta <- estBetaParams(DP.Sx, DP.s.sd.vec^2)$beta
DP.s.stoch <- rbeta(length(DP.s.alpha), DP.s.alpha, DP.s.beta)
# stochastic fertilty sampler (gaussian)
DP.fert.stch <- rnorm(length(DP.popmat[,1]), DP.pred.p.mm, DP.m.sd.vec)
DP.m.arr[i,,e] <- ifelse(DP.fert.stch < 0, 0, DP.fert.stch)
DP.totN.i <- sum(DP.n.mat[,i], na.rm=T)
DP.pred.red <- DP.a.lp/(1+(DP.totN.i/DP.b.lp)^DP.c.lp)
diag(DP.popmat[2:(DP.age.max+1),]) <- (DP.s.stoch[-(DP.age.max+1)])*DP.pred.red
DP.popmat[DP.age.max+1,DP.age.max+1] <- (DP.s.stoch[DP.age.max+1])*DP.pred.red
DP.popmat[1,] <- DP.m.arr[i,,e]
DP.n.mat[,i+1] <- DP.popmat %*% DP.n.mat[,i]
DP.s.arr[i,,e] <- DP.s.stoch * DP.pred.red
} # end i loop
DP.n.sums.mat[e,] <- ((as.vector(colSums(DP.n.mat))/DP.pop.found))
if (e %% itdiv==0) print(e)
} # end e loop
DP.n.md <- apply(DP.n.sums.mat, MARGIN=2, median, na.rm=T) # mean over all iterations
DP.n.up <- apply(DP.n.sums.mat, MARGIN=2, quantile, probs=0.975, na.rm=T) # upper over all iterations
DP.n.lo <- apply(DP.n.sums.mat, MARGIN=2, quantile, probs=0.025, na.rm=T) # lower over all iterations
par(mfrow=c(1,3))
plot(yrs,DP.n.md,type="l", main = "", xlab="year", ylab="pN1", lwd=2, ylim=c(0.95*min(DP.n.lo),1.05*max(DP.n.up)))
lines(yrs,DP.n.lo,lty=2,col="red",lwd=1.5)
lines(yrs,DP.n.up,lty=2,col="red",lwd=1.5)
DP.s.add <- DP.m.add <- rep(0, DP.age.max+1)
for (m in 1:iter) {
DP.s.add <- rbind(DP.s.add, DP.s.arr[ceiling(DP.gen.l):(t+1),,m])
DP.m.add <- rbind(DP.m.add, DP.m.arr[ceiling(DP.gen.l):(t+1),,m])
}
DP.s.add <- DP.s.add[-1,]
DP.m.add <- DP.m.add[-1,]
DP.s.md <- apply(DP.s.add, MARGIN=2, median, na.rm=T) # mean s over all iterations
DP.s.up <- apply(DP.s.add, MARGIN=2, quantile, probs=0.975, na.rm=T) # upper over all iterations
DP.s.lo <- apply(DP.s.add, MARGIN=2, quantile, probs=0.025, na.rm=T) # lower over all iterations
plot(DP.age.vec,DP.s.md,type="l", main = "", xlab="age", ylab="s", lwd=2, ylim=c(0.95*min(DP.s.lo),1.05*max(DP.s.up)))
lines(DP.age.vec,DP.s.lo,lty=2,col="red",lwd=1.5)
lines(DP.age.vec,DP.s.up,lty=2,col="red",lwd=1.5)
DP.m.md <- apply(DP.m.add, MARGIN=2, median, na.rm=T) # mean s over all iterations
DP.m.up <- apply(DP.m.add, MARGIN=2, quantile, probs=0.975, na.rm=T) # upper over all iterations
DP.m.lo <- apply(DP.m.add, MARGIN=2, quantile, probs=0.025, na.rm=T) # lower over all iterations
plot(DP.age.vec,DP.m.md,type="l", main = "", xlab="age", ylab="m", lwd=2, ylim=c(0.95*min(DP.m.lo),1.05*max(DP.m.up)))
lines(DP.age.vec,DP.m.lo,lty=2,col="red",lwd=1.5)
lines(DP.age.vec,DP.m.up,lty=2,col="red",lwd=1.5)
par(mfrow=c(1,1))
############################
## PALORCHESTES (azael) (PA)
## sources: Brook & Johnson 2006 (Alcheringa 30:39-48, http://doi.org/10.1080/03115510609506854)
## Richards et al. 2019 (PLoS One https://doi.org/10.1371/journal.pone.0221824)
# mass
PA.mass <- 1000 # kg (Richards et al. 2019 (PLoS One https://doi.org/10.1371/journal.pone.0221824))
## predicted rm (from Henneman 1983 Oecologia 56:104-108)
## log10rm = 0.6914 - 0.2622*log10m (mass in g)
PA.rm.pred <- 10^(0.6914 - (0.2622*log10(PA.mass*1000)))
PA.lm.pred <- exp(PA.rm.pred)
## theoretical population density for mammalian herbivores based on body size (Damuth 1981; Freeland 1990)
## log10D = 4.196 − 0.74*(log10m)
PA.D.pred <- (10^(4.196 - (0.74*log10(PA.mass*1000))))/2 # divided by 2 for females only
PA.D.pred # animals/km2
## max age
## non-volant birds & mammals (Healy K et al. 2014 PRSB)
## log10ls = 0.89 + 0.13log10m (mass in grams; ls = years)
PA.age.max1 <- round(10^(0.89 + (0.13*log10(PA.mass*1000))), 0)
PA.age.max <- round(PA.age.max1 * 26/29, 0) # corrected for over-estimate derived from Vombatus
## age vector
PA.age.vec <- 0:PA.age.max
## fertility
## total fecundity from Allainé et al. 1987 (Oecologia)
## lnF = 2.719 - 0.211lnM (all mammals)
PA.F.pred1 <- exp(2.719 - (0.211*log(PA.mass*1000)))/2 # divided by 2 for females
PA.F.pred <- PA.F.pred1 * (365/as.numeric((mean(VOMBAT.IBI) + (VU.IBI - VU.IBI.pred)) + (MACROPOD.F.corr.b * log10(PA.mass))))
## age at primiparity
## lnalpha = 0.214 + 0.263*lnM (https://dx.doi.org/10.1093%2Fgerona%2F62.2.149)
PA.alpha1 <- ceiling(exp(-1.34 + (0.214*log(PA.mass*1000))))
PA.alpha <- PA.alpha1
## define m function with age
PA.m.vec <- c(rep(0, PA.alpha-1), rep(0.75*PA.F.pred, round(PA.alpha/2,0)), rep(PA.F.pred, (PA.age.max+1-((PA.alpha-1+round(PA.alpha/2,0))))))
PA.m.sd.vec <- 0.05*PA.m.vec
plot(PA.age.vec, PA.m.vec, type="b", pch=19, xlab="age (yrs)", ylab="m")
# fit sigmoidal function
# logistic power function y = a / (1+(x/b)^c)
PA.m.dat <- data.frame(PA.age.vec, PA.m.vec)
param.init <- c(0.3, 7, -5)
PA.fit.logp <- nls(PA.m.vec ~ a / (1+(PA.age.vec/b)^c),
data = PA.m.dat,
algorithm = "port",
start = c(a = param.init[1], b = param.init[2], c = param.init[3]),
trace = TRUE,
nls.control(maxiter = 1000, tol = 1e-05, minFactor = 1/1024))
PA.fit.logp.summ <- summary(PA.fit.logp)
plot(PA.age.vec, PA.m.vec, type="b", pch=19, xlab="age (yrs)", ylab="m")
PA.age.vec.cont <- seq(0,max(PA.age.vec),1)
PA.pred.p.m <- coef(PA.fit.logp)[1] / (1+(PA.age.vec.cont/coef(PA.fit.logp)[2])^coef(PA.fit.logp)[3])
PA.pred.p.mm <- ifelse(PA.pred.p.m > 1, 1, PA.pred.p.m)
lines(PA.age.vec.cont, PA.pred.p.mm,lty=2,lwd=3,col="red")
## survival
## mean adult survival (McCarthy et al. 2008 Am Nat)
## ln{-ln[s(t)]} = ln(a) + bln(M) + ln (t)
ln.a.s <- -0.5; b.s <- -0.25
PA.s.tran <- ln.a.s + b.s*log(PA.mass*1000) + log(1)
PA.s.ad.yr <- exp(-exp(PA.s.tran))
# Siler hazard h(x) (Gurven et al. 2007)
a1 <- 1 - (PA.s.ad.yr) # initial infant mortality rate (also known as αt)
b1 <- 1.5 # rate of mortality decline (also known as bt)
a2 <- 1 - PA.s.ad.yr # age-independent mortality (exogenous mortality due to environment); also known as ct
a3 <- 0.7e-04 # initial adult mortality rate (also known as βt)
b3 <- 0.05 # rate of mortality increase
longev <- PA.age.max
x <- seq(0,longev,1) # age vector
h.x <- a1 * exp(-b1*x) + a2 + a3 * exp(b3 * x) # Siler's hazard model
plot(x,h.x,pch=19,type="l")
plot(x,log(h.x),pch=19,type="l")
l.x <- exp((-a1/b1) * (1 - exp(-b1*x))) * exp(-a2 * x) * exp(a3/b3 * (1 - exp(b3 * x))) # Siler's survival (proportion surviving) model
init.pop <- 10000
lx <- round(init.pop*l.x,0)
len.lx <- length(lx)
dx <- lx[1:(len.lx-1)]-lx[2:len.lx]
qx <- dx/lx[1:(length(lx)-1)]
PA.Sx <- c(0.99*PA.s.ad.yr, 1 - qx)
plot(x, PA.Sx, pch=19, type="l", xlab="age (years)", ylab="Sx")
PA.s.sd.vec <- 0.05*PA.Sx
## create matrix
PA.popmat <- matrix(data = 0, nrow=PA.age.max+1, ncol=PA.age.max+1)
diag(PA.popmat[2:(PA.age.max+1),]) <- PA.Sx[-(PA.age.max+1)]
PA.popmat[PA.age.max+1,PA.age.max+1] <- PA.Sx[PA.age.max+1]
PA.popmat[1,] <- PA.pred.p.mm
colnames(PA.popmat) <- c(0:PA.age.max)
rownames(PA.popmat) <- c(0:PA.age.max)
PA.popmat.orig <- PA.popmat ## save original matrix
## matrix properties
max.lambda(PA.popmat.orig) ## 1-yr lambda
PA.lm.pred
max.r(PA.popmat.orig) # rate of population change, 1-yr
PA.ssd <- stable.stage.dist(PA.popmat.orig) ## stable stage distribution
plot(PA.age.vec, PA.ssd, type="l", pch=19, xlab="age (yrs)", ylab="ssd")
R.val(PA.popmat.orig, PA.age.max) # reproductive value
PA.gen.l <- G.val(PA.popmat.orig, PA.age.max) # mean generation length
## initial population vector
area <- 500*500 # km × km
PA.pop.found <- round(area*PA.D.pred, 0) # founding population size (estimated density * 100 × 100 km region [10,000 km2])
PA.init.vec <- PA.ssd * PA.pop.found
#################
## project
## set time limit for projection in 1-yr increments
yr.st <- 1
#************************
yr.end <- round(40*PA.gen.l, 0) # set projection end date
#************************
t <- (yr.end - yr.st)
PA.tot.F <- sum(PA.popmat.orig[1,])
PA.popmat <- PA.popmat.orig
yr.vec <- seq(yr.st,yr.end)
## set population storage matrices
PA.n.mat <- matrix(0, nrow=PA.age.max+1,ncol=(t+1))
PA.n.mat[,1] <- PA.init.vec
## set up projection loop
for (i in 1:t) {
PA.n.mat[,i+1] <- PA.popmat %*% PA.n.mat[,i]
}
PA.n.pred <- colSums(PA.n.mat)
yrs <- seq(yr.st, yr.end, 1)
plot(yrs, log10(PA.n.pred),type="l",lty=2,pch=19,xlab="year",ylab="log10 N")
# compensatory density feedback
PA.K.max <- 1*PA.pop.found
PA.K.vec <- c(1, PA.K.max/2, 0.75*PA.K.max, PA.K.max)
PA.red.vec <- c(1,0.982,0.957,0.9206)
plot(PA.K.vec, PA.red.vec,pch=19,type="b")
PA.Kred.dat <- data.frame(PA.K.vec, PA.red.vec)
# logistic power function a/(1+(x/b)^c)
PA.param.init <- c(1, 2*PA.K.max, 2)
PA.fit.lp <- nls(PA.red.vec ~ a/(1+(PA.K.vec/b)^c),
data = PA.Kred.dat,
algorithm = "port",
start = c(a = PA.param.init[1], b = PA.param.init[2], c = PA.param.init[3]),
trace = TRUE,
nls.control(maxiter = 1000, tol = 1e-05, minFactor = 1/1024))
PA.fit.lp.summ <- summary(PA.fit.lp)
plot(PA.K.vec, PA.red.vec, pch=19,xlab="N",ylab="reduction factor")
PA.K.vec.cont <- seq(1,2*PA.pop.found,1)
PA.pred.lp.fx <- coef(PA.fit.lp)[1]/(1+(PA.K.vec.cont/coef(PA.fit.lp)[2])^coef(PA.fit.lp)[3])
lines(PA.K.vec.cont, PA.pred.lp.fx, lty=3,lwd=3,col="red")
PA.a.lp <- coef(PA.fit.lp)[1]
PA.b.lp <- coef(PA.fit.lp)[2]
PA.c.lp <- coef(PA.fit.lp)[3]
## compensatory density-feedback deterministic model
## set population storage matrices
PA.n.mat <- matrix(0, nrow=PA.age.max+1, ncol=(t+1))
PA.n.mat[,1] <- PA.init.vec
PA.popmat <- PA.popmat.orig
## set up projection loop
for (i in 1:t) {
PA.totN.i <- sum(PA.n.mat[,i])
PA.pred.red <- as.numeric(PA.a.lp/(1+(PA.totN.i/PA.b.lp)^PA.c.lp))
diag(PA.popmat[2:(PA.age.max+1),]) <- (PA.Sx[-(PA.age.max+1)])*PA.pred.red
PA.popmat[PA.age.max+1,PA.age.max+1] <- (PA.Sx[PA.age.max+1])*PA.pred.red
PA.popmat[1,] <- PA.pred.p.mm
PA.n.mat[,i+1] <- PA.popmat %*% PA.n.mat[,i]
}
PA.n.pred <- colSums(PA.n.mat)
plot(yrs, PA.n.pred, type="l",lty=2,pch=19,xlab="year",ylab="N")
abline(h=PA.pop.found, lty=2, col="red", lwd=2)
## stochatic projection with density feedback
## set storage matrices & vectors
iter <- 100
itdiv <- iter/10
PA.n.sums.mat <- matrix(data=NA, nrow=iter, ncol=(t+1))
PA.s.arr <- PA.m.arr <- array(data=NA, dim=c(t+1, PA.age.max+1, iter))
for (e in 1:iter) {
PA.popmat <- PA.popmat.orig
PA.n.mat <- matrix(0, nrow=PA.age.max+1,ncol=(t+1))
PA.n.mat[,1] <- PA.init.vec
for (i in 1:t) {
# stochastic survival values
PA.s.alpha <- estBetaParams(PA.Sx, PA.s.sd.vec^2)$alpha
PA.s.beta <- estBetaParams(PA.Sx, PA.s.sd.vec^2)$beta
PA.s.stoch <- rbeta(length(PA.s.alpha), PA.s.alpha, PA.s.beta)
# stochastic fertilty sampler (gaussian)
PA.fert.stch <- rnorm(length(PA.popmat[,1]), PA.pred.p.mm, PA.m.sd.vec)
PA.m.arr[i,,e] <- ifelse(PA.fert.stch < 0, 0, PA.fert.stch)
PA.totN.i <- sum(PA.n.mat[,i], na.rm=T)
PA.pred.red <- PA.a.lp/(1+(PA.totN.i/PA.b.lp)^PA.c.lp)
diag(PA.popmat[2:(PA.age.max+1),]) <- (PA.s.stoch[-(PA.age.max+1)])*PA.pred.red
PA.popmat[PA.age.max+1,PA.age.max+1] <- (PA.s.stoch[PA.age.max+1])*PA.pred.red
PA.popmat[1,] <- PA.m.arr[i,,e]
PA.n.mat[,i+1] <- PA.popmat %*% PA.n.mat[,i]
PA.s.arr[i,,e] <- PA.s.stoch * PA.pred.red
} # end i loop
PA.n.sums.mat[e,] <- ((as.vector(colSums(PA.n.mat))/PA.pop.found))
if (e %% itdiv==0) print(e)
} # end e loop
PA.n.md <- apply(PA.n.sums.mat, MARGIN=2, median, na.rm=T) # mean over all iterations
PA.n.up <- apply(PA.n.sums.mat, MARGIN=2, quantile, probs=0.975, na.rm=T) # upper over all iterations
PA.n.lo <- apply(PA.n.sums.mat, MARGIN=2, quantile, probs=0.025, na.rm=T) # lower over all iterations
par(mfrow=c(1,3))
plot(yrs,PA.n.md,type="l", main = "", xlab="year", ylab="pN1", lwd=2, ylim=c(0.95*min(PA.n.lo),1.05*max(PA.n.up)))
lines(yrs,PA.n.lo,lty=2,col="red",lwd=1.5)
lines(yrs,PA.n.up,lty=2,col="red",lwd=1.5)
PA.s.add <- PA.m.add <- rep(0, PA.age.max+1)
for (m in 1:iter) {
PA.s.add <- rbind(PA.s.add, PA.s.arr[ceiling(PA.gen.l):(t+1),,m])
PA.m.add <- rbind(PA.m.add, PA.m.arr[ceiling(PA.gen.l):(t+1),,m])
}
PA.s.add <- PA.s.add[-1,]
PA.m.add <- PA.m.add[-1,]
PA.s.md <- apply(PA.s.add, MARGIN=2, median, na.rm=T) # mean s over all iterations
PA.s.up <- apply(PA.s.add, MARGIN=2, quantile, probs=0.975, na.rm=T) # upper over all iterations
PA.s.lo <- apply(PA.s.add, MARGIN=2, quantile, probs=0.025, na.rm=T) # lower over all iterations
plot(PA.age.vec,PA.s.md,type="l", main = "", xlab="age", ylab="s", lwd=2, ylim=c(0.95*min(PA.s.lo),1.05*max(PA.s.up)))
lines(PA.age.vec,PA.s.lo,lty=2,col="red",lwd=1.5)
lines(PA.age.vec,PA.s.up,lty=2,col="red",lwd=1.5)
PA.m.md <- apply(PA.m.add, MARGIN=2, median, na.rm=T) # mean s over all iterations
PA.m.up <- apply(PA.m.add, MARGIN=2, quantile, probs=0.975, na.rm=T) # upper over all iterations
PA.m.lo <- apply(PA.m.add, MARGIN=2, quantile, probs=0.025, na.rm=T) # lower over all iterations
plot(PA.age.vec,PA.m.md,type="l", main = "", xlab="age", ylab="m", lwd=2, ylim=c(0.95*min(PA.m.lo),1.05*max(PA.m.up)))
lines(PA.age.vec,PA.m.lo,lty=2,col="red",lwd=1.5)
lines(PA.age.vec,PA.m.up,lty=2,col="red",lwd=1.5)
par(mfrow=c(1,1))
##############################
## ZYGOMATURUS (trilobus) (ZT)
## sources: Brook & Johnson 2006 (Alcheringa 30:39-48, http://doi.org/10.1080/03115510609506854)
## Richards et al. 2019 (PLoS One https://doi.org/10.1371/journal.pone.0221824)
# mass
ZT.mass <- 500 # kg (Johnson et al. 2006 Australia’s Mammal Extinctions. 278 pp. Cambridge University Press, Melbourne)
## predicted rm (from Henneman 1983 Oecologia 56:104-108)
## log10rm = 0.6914 - 0.2622*log10m (mass in g)
ZT.rm.pred <- 10^(0.6914 - (0.2622*log10(ZT.mass*1000)))
ZT.lm.pred <- exp(ZT.rm.pred)
## theoretical population density for mammalian herbivores based on body size (Damuth 1981; Freeland 1990)
## log10D = 4.196 − 0.74*(log10m)
ZT.D.pred <- (10^(4.196 - (0.74*log10(ZT.mass*1000))))/2 # divided by 2 for females only
ZT.D.pred # animals/km2
## max age
## non-volant birds & mammals (Healy K et al. 2014 PRSB)
## log10ls = 0.89 + 0.13log10m (mass in grams; ls = years)
ZT.age.max1 <- round(10^(0.89 + (0.13*log10(ZT.mass*1000))), 0)
ZT.age.max <- round(ZT.age.max1 * 26/29, 0) # corrected for over-estimate derived from Vombatus
## age vector
ZT.age.vec <- 0:ZT.age.max
## fertility
## total fecundity from Allainé et al. 1987 (Oecologia)
## lnF = 2.719 - 0.211lnM (all mammals)
ZT.F.pred1 <- exp(2.719 - (0.211*log(ZT.mass*1000)))/2 # divided by 2 for females
ZT.F.pred <- ZT.F.pred1 * (365/as.numeric((mean(VOMBAT.IBI) + (VU.IBI - VU.IBI.pred)) + (MACROPOD.F.corr.b * log10(ZT.mass))))
## age at primiparity
## lnalpha = 0.214 + 0.263*lnM (https://dx.doi.org/10.1093%2Fgerona%2F62.2.149)
ZT.alpha1 <- ceiling(exp(-1.34 + (0.214*log(ZT.mass*1000))))
ZT.alpha <- ZT.alpha1
## define m function with age
ZT.m.vec <- c(rep(0, ZT.alpha-1), rep(0.75*ZT.F.pred, round(ZT.alpha/2,0)), rep(ZT.F.pred, (ZT.age.max+1-((ZT.alpha-1+round(ZT.alpha/2,0))))))
ZT.m.sd.vec <- 0.05*ZT.m.vec
plot(ZT.age.vec, ZT.m.vec, type="b", pch=19, xlab="age (yrs)", ylab="m")
# fit sigmoidal function
# logistic power function y = a / (1+(x/b)^c)
ZT.m.dat <- data.frame(ZT.age.vec, ZT.m.vec)
param.init <- c(0.1, 2, -5)
ZT.fit.logp <- nls(ZT.m.vec ~ a / (1+(ZT.age.vec/b)^c),
data = ZT.m.dat,
algorithm = "port",
start = c(a = param.init[1], b = param.init[2], c = param.init[3]),
trace = TRUE,
nls.control(maxiter = 1000, tol = 1e-05, minFactor = 1/1024))
ZT.fit.logp.summ <- summary(ZT.fit.logp)
plot(ZT.age.vec, ZT.m.vec, type="b", pch=19, xlab="age (yrs)", ylab="m")
ZT.age.vec.cont <- seq(0,max(ZT.age.vec),1)
ZT.pred.p.m <- coef(ZT.fit.logp)[1] / (1+(ZT.age.vec.cont/coef(ZT.fit.logp)[2])^coef(ZT.fit.logp)[3])
ZT.pred.p.mm <- ifelse(ZT.pred.p.m > 1, 1, ZT.pred.p.m)
lines(ZT.age.vec.cont, ZT.pred.p.mm,lty=2,lwd=3,col="red")
## survival
## mean adult survival (McCarthy et al. 2008 Am Nat)
## ln{-ln[s(t)]} = ln(a) + bln(M) + ln (t)
ln.a.s <- -0.5; b.s <- -0.25
ZT.s.tran <- ln.a.s + b.s*log(ZT.mass*1000) + log(1)
ZT.s.ad.yr <- exp(-exp(ZT.s.tran))
# Siler hazard h(x) (Gurven et al. 2007)
a1 <- 1 - (1.01*ZT.s.ad.yr) # initial infant mortality rate (also known as αt)
b1 <- 2.7 # rate of mortality decline (also known as bt)
a2 <- 1 - ZT.s.ad.yr # age-independent mortality (exogenous mortality due to environment); also known as ct
a3 <- 0.1e-04 # initial adult mortality rate (also known as βt)
b3 <- 0.02 # rate of mortality increase
longev <- ZT.age.max
x <- seq(0,longev,1) # age vector
h.x <- a1 * exp(-b1*x) + a2 + a3 * exp(b3 * x) # Siler's hazard model
plot(x,h.x,pch=19,type="l")
plot(x,log(h.x),pch=19,type="l")
l.x <- exp((-a1/b1) * (1 - exp(-b1*x))) * exp(-a2 * x) * exp(a3/b3 * (1 - exp(b3 * x))) # Siler's survival (proportion surviving) model
init.pop <- 10000
lx <- round(init.pop*l.x,0)
len.lx <- length(lx)
dx <- lx[1:(len.lx-1)]-lx[2:len.lx]
qx <- dx/lx[1:(length(lx)-1)]
ZT.Sx <- c(0.995*ZT.s.ad.yr, 1 - qx)
plot(x, ZT.Sx, pch=19, type="l", xlab="age (years)", ylab="Sx")
ZT.s.sd.vec <- 0.05*ZT.Sx
## create matrix
ZT.popmat <- matrix(data = 0, nrow=ZT.age.max+1, ncol=ZT.age.max+1)
diag(ZT.popmat[2:(ZT.age.max+1),]) <- ZT.Sx[-(ZT.age.max+1)]
ZT.popmat[ZT.age.max+1,ZT.age.max+1] <- ZT.Sx[ZT.age.max+1]
ZT.popmat[1,] <- ZT.pred.p.mm
colnames(ZT.popmat) <- c(0:ZT.age.max)
rownames(ZT.popmat) <- c(0:ZT.age.max)
ZT.popmat.orig <- ZT.popmat ## save original matrix
## matrix properties
max.lambda(ZT.popmat.orig) ## 1-yr lambda
ZT.lm.pred
max.r(ZT.popmat.orig) # rate of population change, 1-yr
ZT.ssd <- stable.stage.dist(ZT.popmat.orig) ## stable stage distribution
plot(ZT.age.vec, ZT.ssd, type="l", pch=19, xlab="age (yrs)", ylab="ssd")
R.val(ZT.popmat.orig, ZT.age.max) # reproductive value
ZT.gen.l <- G.val(ZT.popmat.orig, ZT.age.max) # mean generation length
## initial population vector
area <- 500*500 # km × km
ZT.pop.found <- round(area*ZT.D.pred, 0) # founding population size (estimated density * 100 × 100 km region [10,000 km2])
ZT.init.vec <- ZT.ssd * ZT.pop.found
#################
## project
## set time limit for projection in 1-yr increments
yr.st <- 1
#************************
yr.end <- round(40*ZT.gen.l, 0) # set projection end date
#************************
t <- (yr.end - yr.st)
ZT.tot.F <- sum(ZT.popmat.orig[1,])
ZT.popmat <- ZT.popmat.orig
yr.vec <- seq(yr.st,yr.end)
## set population storage matrices
ZT.n.mat <- matrix(0, nrow=ZT.age.max+1,ncol=(t+1))
ZT.n.mat[,1] <- ZT.init.vec
## set up projection loop
for (i in 1:t) {
ZT.n.mat[,i+1] <- ZT.popmat %*% ZT.n.mat[,i]
}
ZT.n.pred <- colSums(ZT.n.mat)
yrs <- seq(yr.st, yr.end, 1)
plot(yrs, log10(ZT.n.pred),type="l",lty=2,pch=19,xlab="year",ylab="log10 N")
# compensatory density feedback
ZT.K.max <- 1*ZT.pop.found
ZT.K.vec <- c(1, ZT.K.max/2, 0.75*ZT.K.max, ZT.K.max)
ZT.red.vec <- c(1,0.975,0.945,0.9018)
plot(ZT.K.vec, ZT.red.vec,pch=19,type="b")
ZT.Kred.dat <- data.frame(ZT.K.vec, ZT.red.vec)
# logistic power function a/(1+(x/b)^c)
ZT.param.init <- c(1, 2*ZT.K.max, 2)
ZT.fit.lp <- nls(ZT.red.vec ~ a/(1+(ZT.K.vec/b)^c),
data = ZT.Kred.dat,
algorithm = "port",
start = c(a = ZT.param.init[1], b = ZT.param.init[2], c = ZT.param.init[3]),
trace = TRUE,
nls.control(maxiter = 1000, tol = 1e-05, minFactor = 1/1024))
ZT.fit.lp.summ <- summary(ZT.fit.lp)
plot(ZT.K.vec, ZT.red.vec, pch=19,xlab="N",ylab="reduction factor")
ZT.K.vec.cont <- seq(1,2*ZT.pop.found,1)
ZT.pred.lp.fx <- coef(ZT.fit.lp)[1]/(1+(ZT.K.vec.cont/coef(ZT.fit.lp)[2])^coef(ZT.fit.lp)[3])
lines(ZT.K.vec.cont, ZT.pred.lp.fx, lty=3,lwd=3,col="red")
ZT.a.lp <- coef(ZT.fit.lp)[1]
ZT.b.lp <- coef(ZT.fit.lp)[2]
ZT.c.lp <- coef(ZT.fit.lp)[3]
## compensatory density-feedback deterministic model
## set population storage matrices
ZT.n.mat <- matrix(0, nrow=ZT.age.max+1, ncol=(t+1))
ZT.n.mat[,1] <- ZT.init.vec
ZT.popmat <- ZT.popmat.orig
## set up projection loop
for (i in 1:t) {
ZT.totN.i <- sum(ZT.n.mat[,i])
ZT.pred.red <- as.numeric(ZT.a.lp/(1+(ZT.totN.i/ZT.b.lp)^ZT.c.lp))
diag(ZT.popmat[2:(ZT.age.max+1),]) <- (ZT.Sx[-(ZT.age.max+1)])*ZT.pred.red
ZT.popmat[ZT.age.max+1,ZT.age.max+1] <- (ZT.Sx[ZT.age.max+1])*ZT.pred.red
ZT.popmat[1,] <- ZT.pred.p.mm
ZT.n.mat[,i+1] <- ZT.popmat %*% ZT.n.mat[,i]
}
ZT.n.pred <- colSums(ZT.n.mat)
plot(yrs, ZT.n.pred, type="l",lty=2,pch=19,xlab="year",ylab="N")
abline(h=ZT.pop.found, lty=2, col="red", lwd=2)
## stochatic projection with density feedback
## set storage matrices & vectors
iter <- 100
itdiv <- iter/10
ZT.n.sums.mat <- matrix(data=NA, nrow=iter, ncol=(t+1))
ZT.s.arr <- ZT.m.arr <- array(data=NA, dim=c(t+1, ZT.age.max+1, iter))
for (e in 1:iter) {
ZT.popmat <- ZT.popmat.orig
ZT.n.mat <- matrix(0, nrow=ZT.age.max+1,ncol=(t+1))
ZT.n.mat[,1] <- ZT.init.vec
for (i in 1:t) {
# stochastic survival values
ZT.s.alpha <- estBetaParams(ZT.Sx, ZT.s.sd.vec^2)$alpha
ZT.s.beta <- estBetaParams(ZT.Sx, ZT.s.sd.vec^2)$beta
ZT.s.stoch <- rbeta(length(ZT.s.alpha), ZT.s.alpha, ZT.s.beta)
# stochastic fertilty sampler (gaussian)
ZT.fert.stch <- rnorm(length(ZT.popmat[,1]), ZT.pred.p.mm, ZT.m.sd.vec)
ZT.m.arr[i,,e] <- ifelse(ZT.fert.stch < 0, 0, ZT.fert.stch)
ZT.totN.i <- sum(ZT.n.mat[,i], na.rm=T)
ZT.pred.red <- ZT.a.lp/(1+(ZT.totN.i/ZT.b.lp)^ZT.c.lp)
diag(ZT.popmat[2:(ZT.age.max+1),]) <- (ZT.s.stoch[-(ZT.age.max+1)])*ZT.pred.red
ZT.popmat[ZT.age.max+1,ZT.age.max+1] <- (ZT.s.stoch[ZT.age.max+1])*ZT.pred.red
ZT.popmat[1,] <- ZT.m.arr[i,,e]
ZT.n.mat[,i+1] <- ZT.popmat %*% ZT.n.mat[,i]
ZT.s.arr[i,,e] <- ZT.s.stoch * ZT.pred.red
} # end i loop
ZT.n.sums.mat[e,] <- ((as.vector(colSums(ZT.n.mat))/ZT.pop.found))
if (e %% itdiv==0) print(e)
} # end e loop
ZT.n.md <- apply(ZT.n.sums.mat, MARGIN=2, median, na.rm=T) # mean over all iterations
ZT.n.up <- apply(ZT.n.sums.mat, MARGIN=2, quantile, probs=0.975, na.rm=T) # upper over all iterations
ZT.n.lo <- apply(ZT.n.sums.mat, MARGIN=2, quantile, probs=0.025, na.rm=T) # lower over all iterations
par(mfrow=c(1,3))
plot(yrs,ZT.n.md,type="l", main = "", xlab="year", ylab="pN1", lwd=2, ylim=c(0.95*min(ZT.n.lo),1.05*max(ZT.n.up)))
lines(yrs,ZT.n.lo,lty=2,col="red",lwd=1.5)
lines(yrs,ZT.n.up,lty=2,col="red",lwd=1.5)
ZT.s.add <- ZT.m.add <- rep(0, ZT.age.max+1)
for (m in 1:iter) {
ZT.s.add <- rbind(ZT.s.add, ZT.s.arr[ceiling(ZT.gen.l):(t+1),,m])
ZT.m.add <- rbind(ZT.m.add, ZT.m.arr[ceiling(ZT.gen.l):(t+1),,m])