Calculate the probability density of a summary statistic across all iterations of a simulate object

get_pdf(sims, subset = NULL, times = NULL, n = 100, fn = min, ...)

Arguments

sims

an object returned from simulate

subset

integer vector denoting the population classes to include in calculation of population abundance. Defaults to all classes

times

integer vector specifying generations to include in calculation of extinction risk. Defaults to all simulated generations

n

integer specifying number of threshold values to use in default case when threshold is not specified. Defaults to 100

fn

function to apply to each iteration. Defaults to min

...

additional arguments passed to fn

Details

get_pdf and get_cdf are faster and more general alternatives to the risk_curve function. get_pdf can be used to calculate the probability distribution of any summary statistic. For example, the probability distribution of the minimum population size is the density-based equivalent of a risk curve (the function get_cdf can be used to get the true equivalent). Summary statistics for get_pdf are extracted from a simulate object and represent the distribution of that statistic over all replicate trajectories at any time step within a set period. Abundances can be specified for all population classes or for a subset of classes.

Examples

# define a basic population
nstage <- 5
popmat <- matrix(0, nrow = nstage, ncol = nstage)
popmat[reproduction(popmat, dims = 4:5)] <- c(10, 20)
popmat[transition(popmat)] <- c(0.25, 0.3, 0.5, 0.65)

# define a dynamics object
dyn <- dynamics(popmat)

# simulate with the default updater
sims <- simulate(dyn, nsim = 1000)

# calculate distribution of minimum population sizes (default)
get_pdf(sims)
#>             prob    value
#> 1   3.619306e-06 13.42654
#> 2   1.006103e-05 13.89319
#> 3   2.473658e-05 14.35985
#> 4   5.396588e-05 14.82651
#> 5   1.048830e-04 15.29317
#> 6   1.820151e-04 15.75983
#> 7   2.823511e-04 16.22648
#> 8   3.933693e-04 16.69314
#> 9   4.952471e-04 17.15980
#> 10  5.690326e-04 17.62646
#> 11  6.089686e-04 18.09311
#> 12  6.320411e-04 18.55977
#> 13  6.781094e-04 19.02643
#> 14  8.010826e-04 19.49309
#> 15  1.055591e-03 19.95975
#> 16  1.481745e-03 20.42640
#> 17  2.102362e-03 20.89306
#> 18  2.928954e-03 21.35972
#> 19  3.967355e-03 21.82638
#> 20  5.222865e-03 22.29303
#> 21  6.695465e-03 22.75969
#> 22  8.386771e-03 23.22635
#> 23  1.029677e-02 23.69301
#> 24  1.241054e-02 24.15967
#> 25  1.468075e-02 24.62632
#> 26  1.702071e-02 25.09298
#> 27  1.934312e-02 25.55964
#> 28  2.160889e-02 26.02630
#> 29  2.385665e-02 26.49295
#> 30  2.618196e-02 26.95961
#> 31  2.867478e-02 27.42627
#> 32  3.137779e-02 27.89293
#> 33  3.428917e-02 28.35959
#> 34  3.738582e-02 28.82624
#> 35  4.061953e-02 29.29290
#> 36  4.388688e-02 29.75956
#> 37  4.702526e-02 30.22622
#> 38  4.986589e-02 30.69287
#> 39  5.231909e-02 31.15953
#> 40  5.442810e-02 31.62619
#> 41  5.632359e-02 32.09285
#> 42  5.811799e-02 32.55951
#> 43  5.981857e-02 33.02616
#> 44  6.129908e-02 33.49282
#> 45  6.236076e-02 33.95948
#> 46  6.285553e-02 34.42614
#> 47  6.281199e-02 34.89279
#> 48  6.248197e-02 35.35945
#> 49  6.223971e-02 35.82611
#> 50  6.234941e-02 36.29277
#> 51  6.277329e-02 36.75943
#> 52  6.316487e-02 37.22608
#> 53  6.304108e-02 37.69274
#> 54  6.201074e-02 38.15940
#> 55  5.997099e-02 38.62606
#> 56  5.709377e-02 39.09271
#> 57  5.372771e-02 39.55937
#> 58  5.024207e-02 40.02603
#> 59  4.689435e-02 40.49269
#> 60  4.376998e-02 40.95935
#> 61  4.082943e-02 41.42600
#> 62  3.799418e-02 41.89266
#> 63  3.521067e-02 42.35932
#> 64  3.246090e-02 42.82598
#> 65  2.973873e-02 43.29263
#> 66  2.703265e-02 43.75929
#> 67  2.433387e-02 44.22595
#> 68  2.165676e-02 44.69261
#> 69  1.904584e-02 45.15927
#> 70  1.655947e-02 45.62592
#> 71  1.424812e-02 46.09258
#> 72  1.214370e-02 46.55924
#> 73  1.026443e-02 47.02590
#> 74  8.611871e-03 47.49255
#> 75  7.171302e-03 47.95921
#> 76  5.909109e-03 48.42587
#> 77  4.784412e-03 48.89253
#> 78  3.774240e-03 49.35919
#> 79  2.887644e-03 49.82584
#> 80  2.162457e-03 50.29250
#> 81  1.635334e-03 50.75916
#> 82  1.310150e-03 51.22582
#> 83  1.144000e-03 51.69247
#> 84  1.058877e-03 52.15913
#> 85  9.814818e-04 52.62579
#> 86  8.721284e-04 53.09245
#> 87  7.338896e-04 53.55910
#> 88  5.971697e-04 54.02576
#> 89  4.908941e-04 54.49242
#> 90  4.227405e-04 54.95908
#> 91  3.786016e-04 55.42574
#> 92  3.363003e-04 55.89239
#> 93  2.814734e-04 56.35905
#> 94  2.146681e-04 56.82571
#> 95  1.465066e-04 57.29237
#> 96  8.865079e-05 57.75902
#> 97  4.744650e-05 58.22568
#> 98  2.243184e-05 58.69234
#> 99  9.345547e-06 59.15900
#> 100 3.424548e-06 59.62566

# calculate distribution of maximum population sizes
get_pdf(sims, fn = max)
#>             prob     value
#> 1   2.812120e-07  69.52868
#> 2   7.542976e-07  75.06042
#> 3   1.789267e-06  80.59217
#> 4   3.762210e-06  86.12391
#> 5   7.030003e-06  91.65565
#> 6   1.171835e-05  97.18740
#> 7   1.752030e-05 102.71914
#> 8   2.372331e-05 108.25089
#> 9   2.964167e-05 113.78263
#> 10  3.517732e-05 119.31437
#> 11  4.117153e-05 124.84612
#> 12  4.932534e-05 130.37786
#> 13  6.174213e-05 135.90960
#> 14  8.088679e-05 141.44135
#> 15  1.100283e-04 146.97309
#> 16  1.536702e-04 152.50484
#> 17  2.173102e-04 158.03658
#> 18  3.054456e-04 163.56832
#> 19  4.198663e-04 169.10007
#> 20  5.589621e-04 174.63181
#> 21  7.186760e-04 180.16356
#> 22  8.950775e-04 185.69530
#> 23  1.086955e-03 191.22704
#> 24  1.296902e-03 196.75879
#> 25  1.529692e-03 202.29053
#> 26  1.788059e-03 207.82228
#> 27  2.068731e-03 213.35402
#> 28  2.361630e-03 218.88576
#> 29  2.653822e-03 224.41751
#> 30  2.936346e-03 229.94925
#> 31  3.208328e-03 235.48099
#> 32  3.476367e-03 241.01274
#> 33  3.749589e-03 246.54448
#> 34  4.032840e-03 252.07623
#> 35  4.322531e-03 257.60797
#> 36  4.606924e-03 263.13971
#> 37  4.870607e-03 268.67146
#> 38  5.100302e-03 274.20320
#> 39  5.289363e-03 279.73495
#> 40  5.436328e-03 285.26669
#> 41  5.539830e-03 290.79843
#> 42  5.595064e-03 296.33018
#> 43  5.595009e-03 301.86192
#> 44  5.537336e-03 307.39366
#> 45  5.431449e-03 312.92541
#> 46  5.297868e-03 318.45715
#> 47  5.161313e-03 323.98890
#> 48  5.040066e-03 329.52064
#> 49  4.938676e-03 335.05238
#> 50  4.847484e-03 340.58413
#> 51  4.749812e-03 346.11587
#> 52  4.629853e-03 351.64762
#> 53  4.478466e-03 357.17936
#> 54  4.294489e-03 362.71110
#> 55  4.083150e-03 368.24285
#> 56  3.851023e-03 373.77459
#> 57  3.604002e-03 379.30634
#> 58  3.348453e-03 384.83808
#> 59  3.093408e-03 390.36982
#> 60  2.850024e-03 395.90157
#> 61  2.627192e-03 401.43331
#> 62  2.427645e-03 406.96505
#> 63  2.247784e-03 412.49680
#> 64  2.081300e-03 418.02854
#> 65  1.922758e-03 423.56029
#> 66  1.768420e-03 429.09203
#> 67  1.615081e-03 434.62377
#> 68  1.459540e-03 440.15552
#> 69  1.300025e-03 445.68726
#> 70  1.137807e-03 451.21901
#> 71  9.771266e-04 456.75075
#> 72  8.232890e-04 462.28249
#> 73  6.811009e-04 467.81424
#> 74  5.544238e-04 473.34598
#> 75  4.466380e-04 478.87772
#> 76  3.601801e-04 484.40947
#> 77  2.962768e-04 489.94121
#> 78  2.540621e-04 495.47296
#> 79  2.300228e-04 501.00470
#> 80  2.183286e-04 506.53644
#> 81  2.119438e-04 512.06819
#> 82  2.048417e-04 517.59993
#> 83  1.937236e-04 523.13168
#> 84  1.784489e-04 528.66342
#> 85  1.610544e-04 534.19516
#> 86  1.440558e-04 539.72691
#> 87  1.290200e-04 545.25865
#> 88  1.161718e-04 550.79040
#> 89  1.046997e-04 556.32214
#> 90  9.328741e-05 561.85388
#> 91  8.069047e-05 567.38563
#> 92  6.641193e-05 572.91737
#> 93  5.103781e-05 578.44911
#> 94  3.604931e-05 583.98086
#> 95  2.311755e-05 589.51260
#> 96  1.336426e-05 595.04435
#> 97  6.925938e-06 600.57609
#> 98  3.202797e-06 606.10783
#> 99  1.317089e-06 611.63958
#> 100 4.801634e-07 617.17132

# calculate distribution of the 90th percentile of
#   population sizes
get_pdf(sims, fn = quantile, prob = 0.9)
#>             prob     value
#> 1   8.338539e-07  58.70451
#> 2   2.368871e-06  61.12277
#> 3   5.978467e-06  63.54103
#> 4   1.327331e-05  65.95929
#> 5   2.598623e-05  68.37755
#> 6   4.494675e-05  70.79581
#> 7   6.881904e-05  73.21406
#> 8   9.345452e-05  75.63232
#> 9   1.133648e-04  78.05058
#> 10  1.250825e-04  80.46884
#> 11  1.308557e-04  82.88710
#> 12  1.405884e-04  85.30536
#> 13  1.697693e-04  87.72362
#> 14  2.337830e-04  90.14188
#> 15  3.417926e-04  92.56014
#> 16  4.933181e-04  94.97840
#> 17  6.803766e-04  97.39666
#> 18  8.946832e-04  99.81492
#> 19  1.137117e-03 102.23318
#> 20  1.419725e-03 104.65144
#> 21  1.760307e-03 107.06970
#> 22  2.171195e-03 109.48796
#> 23  2.651574e-03 111.90622
#> 24  3.186713e-03 114.32448
#> 25  3.750404e-03 116.74274
#> 26  4.311057e-03 119.16100
#> 27  4.844500e-03 121.57926
#> 28  5.350147e-03 123.99752
#> 29  5.858942e-03 126.41578
#> 30  6.422110e-03 128.83404
#> 31  7.080117e-03 131.25230
#> 32  7.829224e-03 133.67056
#> 33  8.617661e-03 136.08882
#> 34  9.368682e-03 138.50708
#> 35  1.001644e-02 140.92534
#> 36  1.053594e-02 143.34360
#> 37  1.094471e-02 145.76186
#> 38  1.128290e-02 148.18012
#> 39  1.158770e-02 150.59838
#> 40  1.187306e-02 153.01664
#> 41  1.212542e-02 155.43490
#> 42  1.231551e-02 157.85316
#> 43  1.241817e-02 160.27142
#> 44  1.242762e-02 162.68968
#> 45  1.236346e-02 165.10794
#> 46  1.226338e-02 167.52620
#> 47  1.216662e-02 169.94446
#> 48  1.209681e-02 172.36272
#> 49  1.204840e-02 174.78098
#> 50  1.198476e-02 177.19924
#> 51  1.185458e-02 179.61750
#> 52  1.161460e-02 182.03576
#> 53  1.124698e-02 184.45402
#> 54  1.076199e-02 186.87228
#> 55  1.018847e-02 189.29054
#> 56  9.553852e-03 191.70880
#> 57  8.876818e-03 194.12706
#> 58  8.170063e-03 196.54532
#> 59  7.449256e-03 198.96358
#> 60  6.736709e-03 201.38184
#> 61  6.057855e-03 203.80010
#> 62  5.434739e-03 206.21836
#> 63  4.881733e-03 208.63662
#> 64  4.400124e-03 211.05488
#> 65  3.979266e-03 213.47314
#> 66  3.597666e-03 215.89140
#> 67  3.228637e-03 218.30966
#> 68  2.849143e-03 220.72792
#> 69  2.449463e-03 223.14618
#> 70  2.037524e-03 225.56444
#> 71  1.637059e-03 227.98270
#> 72  1.279857e-03 230.40096
#> 73  9.923958e-04 232.81922
#> 74  7.853435e-04 235.23748
#> 75  6.511321e-04 237.65574
#> 76  5.688716e-04 240.07400
#> 77  5.140049e-04 242.49226
#> 78  4.669450e-04 244.91052
#> 79  4.187286e-04 247.32878
#> 80  3.697944e-04 249.74704
#> 81  3.256484e-04 252.16530
#> 82  2.910918e-04 254.58356
#> 83  2.659664e-04 257.00182
#> 84  2.454146e-04 259.42008
#> 85  2.236864e-04 261.83834
#> 86  1.987308e-04 264.25660
#> 87  1.738719e-04 266.67486
#> 88  1.545793e-04 269.09312
#> 89  1.435386e-04 271.51138
#> 90  1.380141e-04 273.92964
#> 91  1.314588e-04 276.34790
#> 92  1.182207e-04 278.76616
#> 93  9.712200e-05 281.18442
#> 94  7.154978e-05 283.60268
#> 95  4.683829e-05 286.02094
#> 96  2.715352e-05 288.43920
#> 97  1.390230e-05 290.85746
#> 98  6.272201e-06 293.27572
#> 99  2.487421e-06 295.69398
#> 100 8.756626e-07 298.11224

# calculate distribution of minimum population sizes
#   but ignore first 10 years
get_pdf(sims, fn = max, times = 11:51)
#>             prob     value
#> 1   5.468625e-07  54.35433
#> 2   1.508920e-06  57.28766
#> 3   3.670129e-06  60.22100
#> 4   7.848915e-06  63.15434
#> 5   1.481094e-05  66.08767
#> 6   2.476450e-05  69.02101
#> 7   3.691066e-05  71.95435
#> 8   4.941441e-05  74.88769
#> 9   6.024668e-05  77.82102
#> 10  6.817935e-05  80.75436
#> 11  7.337488e-05  83.68770
#> 12  7.738651e-05  86.62103
#> 13  8.309968e-05  89.55437
#> 14  9.520340e-05  92.48771
#> 15  1.210157e-04  95.42104
#> 16  1.705716e-04  98.35438
#> 17  2.545349e-04 101.28772
#> 18  3.809238e-04 104.22105
#> 19  5.530623e-04 107.15439
#> 20  7.684578e-04 110.08773
#> 21  1.019785e-03 113.02106
#> 22  1.296343e-03 115.95440
#> 23  1.589529e-03 118.88774
#> 24  1.898015e-03 121.82108
#> 25  2.231191e-03 124.75441
#> 26  2.606908e-03 127.68775
#> 27  3.040756e-03 130.62109
#> 28  3.537037e-03 133.55442
#> 29  4.085148e-03 136.48776
#> 30  4.664059e-03 139.42110
#> 31  5.248799e-03 142.35443
#> 32  5.815869e-03 145.28777
#> 33  6.346298e-03 148.22111
#> 34  6.830331e-03 151.15444
#> 35  7.272364e-03 154.08778
#> 36  7.691371e-03 157.02112
#> 37  8.108475e-03 159.95446
#> 38  8.531481e-03 162.88779
#> 39  8.944906e-03 165.82113
#> 40  9.313048e-03 168.75447
#> 41  9.598998e-03 171.68780
#> 42  9.784720e-03 174.62114
#> 43  9.883691e-03 177.55448
#> 44  9.938044e-03 180.48781
#> 45  1.000118e-02 183.42115
#> 46  1.010985e-02 186.35449
#> 47  1.026269e-02 189.28782
#> 48  1.041361e-02 192.22116
#> 49  1.048477e-02 195.15450
#> 50  1.040342e-02 198.08784
#> 51  1.013980e-02 201.02117
#> 52  9.726796e-03 203.95451
#> 53  9.248715e-03 206.88785
#> 54  8.802249e-03 209.82118
#> 55  8.446473e-03 212.75452
#> 56  8.178648e-03 215.68786
#> 57  7.944732e-03 218.62119
#> 58  7.673461e-03 221.55453
#> 59  7.313747e-03 224.48787
#> 60  6.855162e-03 227.42120
#> 61  6.321968e-03 230.35454
#> 62  5.755593e-03 233.28788
#> 63  5.195825e-03 236.22122
#> 64  4.668122e-03 239.15455
#> 65  4.181137e-03 242.08789
#> 66  3.731695e-03 245.02123
#> 67  3.311395e-03 247.95456
#> 68  2.912326e-03 250.88790
#> 69  2.530679e-03 253.82124
#> 70  2.169040e-03 256.75457
#> 71  1.834997e-03 259.68791
#> 72  1.537589e-03 262.62125
#> 73  1.282243e-03 265.55458
#> 74  1.068099e-03 268.48792
#> 75  8.896158e-04 271.42126
#> 76  7.394947e-04 274.35460
#> 77  6.120913e-04 277.28793
#> 78  5.048341e-04 280.22127
#> 79  4.188586e-04 283.15461
#> 80  3.568559e-04 286.08794
#> 81  3.194895e-04 289.02128
#> 82  3.020905e-04 291.95462
#> 83  2.939356e-04 294.88795
#> 84  2.828176e-04 297.82129
#> 85  2.605816e-04 300.75463
#> 86  2.270087e-04 303.68796
#> 87  1.893151e-04 306.62130
#> 88  1.568549e-04 309.55464
#> 89  1.352012e-04 312.48798
#> 90  1.233638e-04 315.42131
#> 91  1.152902e-04 318.35465
#> 92  1.042875e-04 321.28799
#> 93  8.731552e-05 324.22132
#> 94  6.590703e-05 327.15466
#> 95  4.423974e-05 330.08800
#> 96  2.627588e-05 333.02133
#> 97  1.376335e-05 335.95467
#> 98  6.343125e-06 338.88801
#> 99  2.566277e-06 341.82134
#> 100 9.146720e-07 344.75468