Calculate the cumulative distribution function of a summary statistic across all iterations of a simulate object

get_cdf(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_cdf is a faster and more general alternative to the risk_curve function. get_cdf can be used to calculate the cumulative distribution of any summary statistic. For example, the cumulative distribution of the minimum population size is equivalent to a risk curve. Summary statistics for get_cdf are extracted from a simulate object and represent the cumulative 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_cdf(sims)
#>     prob    value
#> 1   0.00 16.57627
#> 2   0.01 22.76214
#> 3   0.02 23.53699
#> 4   0.03 24.70575
#> 5   0.04 25.44184
#> 6   0.05 26.25621
#> 7   0.06 26.80685
#> 8   0.07 27.21967
#> 9   0.08 27.63838
#> 10  0.09 28.01883
#> 11  0.10 28.21132
#> 12  0.11 28.52113
#> 13  0.12 28.80478
#> 14  0.13 29.01816
#> 15  0.14 29.27747
#> 16  0.15 29.49167
#> 17  0.16 29.75466
#> 18  0.17 29.93450
#> 19  0.18 30.17543
#> 20  0.19 30.36014
#> 21  0.20 30.52386
#> 22  0.21 30.73327
#> 23  0.22 30.94783
#> 24  0.23 31.21974
#> 25  0.24 31.38598
#> 26  0.25 31.62794
#> 27  0.26 31.87343
#> 28  0.27 32.04050
#> 29  0.28 32.11920
#> 30  0.29 32.33426
#> 31  0.30 32.45162
#> 32  0.31 32.67995
#> 33  0.32 32.78106
#> 34  0.33 32.95388
#> 35  0.34 33.09542
#> 36  0.35 33.23107
#> 37  0.36 33.41848
#> 38  0.37 33.62761
#> 39  0.38 33.81373
#> 40  0.39 34.00703
#> 41  0.40 34.10330
#> 42  0.41 34.29785
#> 43  0.42 34.44988
#> 44  0.43 34.63895
#> 45  0.44 34.76482
#> 46  0.45 34.91542
#> 47  0.46 35.00000
#> 48  0.47 35.04430
#> 49  0.48 35.14422
#> 50  0.49 35.34647
#> 51  0.50 35.52478
#> 52  0.51 35.65412
#> 53  0.52 35.80061
#> 54  0.53 35.93372
#> 55  0.54 36.05007
#> 56  0.55 36.20076
#> 57  0.56 36.40055
#> 58  0.57 36.60039
#> 59  0.58 36.80431
#> 60  0.59 37.01074
#> 61  0.60 37.17714
#> 62  0.61 37.29078
#> 63  0.62 37.57234
#> 64  0.63 37.78301
#> 65  0.64 37.92597
#> 66  0.65 38.02424
#> 67  0.66 38.18515
#> 68  0.67 38.31945
#> 69  0.68 38.48259
#> 70  0.69 38.57785
#> 71  0.70 38.71078
#> 72  0.71 38.96248
#> 73  0.72 39.02102
#> 74  0.73 39.23670
#> 75  0.74 39.42163
#> 76  0.75 39.58612
#> 77  0.76 39.85937
#> 78  0.77 40.00568
#> 79  0.78 40.28316
#> 80  0.79 40.43740
#> 81  0.80 40.60948
#> 82  0.81 40.75497
#> 83  0.82 41.00000
#> 84  0.83 41.09616
#> 85  0.84 41.34031
#> 86  0.85 41.55361
#> 87  0.86 41.80701
#> 88  0.87 41.95882
#> 89  0.88 42.32450
#> 90  0.89 42.87538
#> 91  0.90 43.30201
#> 92  0.91 43.78990
#> 93  0.92 44.00104
#> 94  0.93 44.19003
#> 95  0.94 44.75662
#> 96  0.95 45.43513
#> 97  0.96 46.00255
#> 98  0.97 47.17404
#> 99  0.98 48.00000
#> 100 0.99 48.65680
#> 101 1.00 54.00000

# calculate distribution of maximum population sizes
get_cdf(sims, fn = max)
#>     prob    value
#> 1   0.00 120.2500
#> 2   0.01 173.6498
#> 3   0.02 189.7890
#> 4   0.03 195.5790
#> 5   0.04 204.2440
#> 6   0.05 209.2612
#> 7   0.06 215.2085
#> 8   0.07 224.6230
#> 9   0.08 226.1500
#> 10  0.09 230.8210
#> 11  0.10 233.3450
#> 12  0.11 235.3445
#> 13  0.12 236.9900
#> 14  0.13 241.5545
#> 15  0.14 244.9650
#> 16  0.15 246.2638
#> 17  0.16 250.2910
#> 18  0.17 254.1330
#> 19  0.18 256.0615
#> 20  0.19 258.1000
#> 21  0.20 261.8350
#> 22  0.21 265.1290
#> 23  0.22 266.5280
#> 24  0.23 267.6097
#> 25  0.24 271.7460
#> 26  0.25 272.5250
#> 27  0.26 274.6720
#> 28  0.27 276.0865
#> 29  0.28 276.8000
#> 30  0.29 277.7033
#> 31  0.30 281.8325
#> 32  0.31 283.3345
#> 33  0.32 284.4040
#> 34  0.33 285.4675
#> 35  0.34 286.7490
#> 36  0.35 287.8000
#> 37  0.36 290.7840
#> 38  0.37 293.7760
#> 39  0.38 295.3500
#> 40  0.39 296.4550
#> 41  0.40 297.7800
#> 42  0.41 298.8885
#> 43  0.42 302.6190
#> 44  0.43 303.9070
#> 45  0.44 305.3500
#> 46  0.45 306.5000
#> 47  0.46 307.3080
#> 48  0.47 309.4858
#> 49  0.48 313.4680
#> 50  0.49 314.4510
#> 51  0.50 315.2750
#> 52  0.51 316.9980
#> 53  0.52 317.9980
#> 54  0.53 319.1350
#> 55  0.54 323.6075
#> 56  0.55 325.3000
#> 57  0.56 326.4660
#> 58  0.57 327.6715
#> 59  0.58 328.7565
#> 60  0.59 330.3870
#> 61  0.60 335.2350
#> 62  0.61 336.4585
#> 63  0.62 337.6570
#> 64  0.63 338.6035
#> 65  0.64 339.9860
#> 66  0.65 343.0150
#> 67  0.66 344.8010
#> 68  0.67 348.2000
#> 69  0.68 349.7960
#> 70  0.69 353.5155
#> 71  0.70 355.4000
#> 72  0.71 356.6660
#> 73  0.72 358.1640
#> 74  0.73 359.2445
#> 75  0.74 362.5910
#> 76  0.75 364.8813
#> 77  0.76 366.0600
#> 78  0.77 367.7615
#> 79  0.78 369.2500
#> 80  0.79 371.1710
#> 81  0.80 374.1000
#> 82  0.81 376.6285
#> 83  0.82 377.9500
#> 84  0.83 381.6350
#> 85  0.84 387.2400
#> 86  0.85 389.0575
#> 87  0.86 394.6920
#> 88  0.87 398.0260
#> 89  0.88 404.5620
#> 90  0.89 407.8885
#> 91  0.90 412.2600
#> 92  0.91 416.2000
#> 93  0.92 418.4040
#> 94  0.93 422.8560
#> 95  0.94 428.2140
#> 96  0.95 438.5600
#> 97  0.96 447.4720
#> 98  0.97 456.1255
#> 99  0.98 461.0510
#> 100 0.99 487.4690
#> 101 1.00 593.1500

# calculate distribution of the 90th percentile of
#   population sizes
get_cdf(sims, fn = quantile, prob = 0.9)
#>     prob     value
#> 1   0.00  76.98023
#> 2   0.01 102.49990
#> 3   0.02 109.84399
#> 4   0.03 114.02712
#> 5   0.04 118.38532
#> 6   0.05 122.02219
#> 7   0.06 123.52929
#> 8   0.07 125.63030
#> 9   0.08 126.64000
#> 10  0.09 129.37145
#> 11  0.10 131.01680
#> 12  0.11 132.17844
#> 13  0.12 133.31749
#> 14  0.13 135.12942
#> 15  0.14 136.48753
#> 16  0.15 137.89821
#> 17  0.16 139.01827
#> 18  0.17 140.45710
#> 19  0.18 141.38502
#> 20  0.19 142.26075
#> 21  0.20 143.13278
#> 22  0.21 143.59812
#> 23  0.22 144.45184
#> 24  0.23 145.22565
#> 25  0.24 146.05740
#> 26  0.25 146.72162
#> 27  0.26 147.15972
#> 28  0.27 147.95998
#> 29  0.28 148.64738
#> 30  0.29 149.34416
#> 31  0.30 150.44060
#> 32  0.31 151.20954
#> 33  0.32 152.78267
#> 34  0.33 153.74902
#> 35  0.34 154.58036
#> 36  0.35 155.11948
#> 37  0.36 156.27845
#> 38  0.37 157.06037
#> 39  0.38 157.55732
#> 40  0.39 158.03724
#> 41  0.40 159.20053
#> 42  0.41 159.93501
#> 43  0.42 160.53031
#> 44  0.43 161.31254
#> 45  0.44 161.92491
#> 46  0.45 162.64418
#> 47  0.46 163.28153
#> 48  0.47 163.94852
#> 49  0.48 164.24063
#> 50  0.49 164.90263
#> 51  0.50 165.47777
#> 52  0.51 166.08699
#> 53  0.52 166.86590
#> 54  0.53 168.41017
#> 55  0.54 169.52043
#> 56  0.55 170.28281
#> 57  0.56 171.35084
#> 58  0.57 172.00788
#> 59  0.58 173.01916
#> 60  0.59 173.68737
#> 61  0.60 174.60170
#> 62  0.61 175.60320
#> 63  0.62 176.20011
#> 64  0.63 177.46607
#> 65  0.64 178.22055
#> 66  0.65 179.31283
#> 67  0.66 179.81465
#> 68  0.67 180.46916
#> 69  0.68 181.40481
#> 70  0.69 182.66460
#> 71  0.70 183.85959
#> 72  0.71 184.45540
#> 73  0.72 185.07142
#> 74  0.73 186.19832
#> 75  0.74 186.65070
#> 76  0.75 187.13092
#> 77  0.76 187.86243
#> 78  0.77 189.12423
#> 79  0.78 190.17429
#> 80  0.79 191.24000
#> 81  0.80 191.97720
#> 82  0.81 193.35646
#> 83  0.82 194.09119
#> 84  0.83 195.35651
#> 85  0.84 196.70510
#> 86  0.85 197.75283
#> 87  0.86 199.02672
#> 88  0.87 200.35235
#> 89  0.88 201.52974
#> 90  0.89 202.76375
#> 91  0.90 204.45930
#> 92  0.91 207.19144
#> 93  0.92 210.20370
#> 94  0.93 212.15702
#> 95  0.94 216.70593
#> 96  0.95 220.67927
#> 97  0.96 223.86260
#> 98  0.97 227.07772
#> 99  0.98 233.16718
#> 100 0.99 240.15184
#> 101 1.00 298.02023

# calculate distribution of minimum population sizes
#   but ignore first 10 years
get_cdf(sims, fn = max, times = 11:51)
#>     prob     value
#> 1   0.00  76.98023
#> 2   0.01 110.76862
#> 3   0.02 121.18732
#> 4   0.03 125.23802
#> 5   0.04 132.00945
#> 6   0.05 135.67082
#> 7   0.06 137.54360
#> 8   0.07 139.57583
#> 9   0.08 142.16263
#> 10  0.09 143.35866
#> 11  0.10 145.29109
#> 12  0.11 147.10626
#> 13  0.12 149.31802
#> 14  0.13 150.62007
#> 15  0.14 151.72098
#> 16  0.15 152.79263
#> 17  0.16 155.34258
#> 18  0.17 157.23199
#> 19  0.18 158.00231
#> 20  0.19 159.99816
#> 21  0.20 160.90076
#> 22  0.21 161.62467
#> 23  0.22 162.89199
#> 24  0.23 163.69255
#> 25  0.24 164.64765
#> 26  0.25 165.43308
#> 27  0.26 166.27613
#> 28  0.27 167.06386
#> 29  0.28 168.00876
#> 30  0.29 169.29768
#> 31  0.30 170.08799
#> 32  0.31 171.70649
#> 33  0.32 172.69784
#> 34  0.33 173.96883
#> 35  0.34 175.84834
#> 36  0.35 176.84356
#> 37  0.36 177.67196
#> 38  0.37 179.26154
#> 39  0.38 180.59065
#> 40  0.39 181.19841
#> 41  0.40 181.66738
#> 42  0.41 182.43189
#> 43  0.42 183.65343
#> 44  0.43 184.36777
#> 45  0.44 185.06306
#> 46  0.45 186.44617
#> 47  0.46 187.05054
#> 48  0.47 188.30648
#> 49  0.48 189.12173
#> 50  0.49 190.02921
#> 51  0.50 190.59325
#> 52  0.51 191.22220
#> 53  0.52 191.70171
#> 54  0.53 192.66907
#> 55  0.54 193.78567
#> 56  0.55 194.35298
#> 57  0.56 196.18237
#> 58  0.57 197.43916
#> 59  0.58 197.99194
#> 60  0.59 199.02538
#> 61  0.60 200.57673
#> 62  0.61 201.49634
#> 63  0.62 202.05108
#> 64  0.63 203.03897
#> 65  0.64 204.01362
#> 66  0.65 204.57874
#> 67  0.66 205.75188
#> 68  0.67 206.58421
#> 69  0.68 207.25865
#> 70  0.69 208.29693
#> 71  0.70 209.22692
#> 72  0.71 210.91813
#> 73  0.72 212.33493
#> 74  0.73 213.18168
#> 75  0.74 213.84866
#> 76  0.75 215.06762
#> 77  0.76 216.10726
#> 78  0.77 217.19395
#> 79  0.78 217.95693
#> 80  0.79 219.02752
#> 81  0.80 220.70312
#> 82  0.81 222.72153
#> 83  0.82 224.34445
#> 84  0.83 225.88376
#> 85  0.84 227.21535
#> 86  0.85 228.71166
#> 87  0.86 230.62884
#> 88  0.87 232.17310
#> 89  0.88 233.92418
#> 90  0.89 235.85527
#> 91  0.90 237.22303
#> 92  0.91 239.40521
#> 93  0.92 242.17571
#> 94  0.93 245.47500
#> 95  0.94 248.91567
#> 96  0.95 253.61895
#> 97  0.96 259.76756
#> 98  0.97 264.40355
#> 99  0.98 270.32208
#> 100 0.99 281.66846
#> 101 1.00 355.75692