Calculate the cumulative distribution function of a summary statistic across all iterations of a simulate object
Source: R/summarise.R
get_cdf.RdCalculate the cumulative distribution function
of a summary statistic across all iterations of a
simulate object
Arguments
- sims
an object returned from
simulate- subset
integervector denoting the population classes to include in calculation of population abundance. Defaults to all classes- times
integervector specifying generations to include in calculation of extinction risk. Defaults to all simulated generations- n
integerspecifying number of threshold values to use in default case whenthresholdis not specified. Defaults to 100- fn
function to apply to each iteration. Defaults to min
- ...
additional arguments passed to
fn
Value
a data.frame containing a prob column that indicates
the probability the population will fall below the threshold value
in the value column
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.30499
#> 2 0.01 22.43665
#> 3 0.02 23.47920
#> 4 0.03 24.58012
#> 5 0.04 25.17847
#> 6 0.05 25.89223
#> 7 0.06 26.18922
#> 8 0.07 26.58227
#> 9 0.08 27.06739
#> 10 0.09 27.40426
#> 11 0.10 27.76330
#> 12 0.11 28.11301
#> 13 0.12 28.48490
#> 14 0.13 28.73059
#> 15 0.14 28.92384
#> 16 0.15 29.28635
#> 17 0.16 29.55179
#> 18 0.17 29.79708
#> 19 0.18 29.98027
#> 20 0.19 30.10235
#> 21 0.20 30.31807
#> 22 0.21 30.50218
#> 23 0.22 30.73326
#> 24 0.23 31.02480
#> 25 0.24 31.38251
#> 26 0.25 31.50897
#> 27 0.26 31.67490
#> 28 0.27 31.84011
#> 29 0.28 32.02076
#> 30 0.29 32.11840
#> 31 0.30 32.27836
#> 32 0.31 32.41805
#> 33 0.32 32.61042
#> 34 0.33 32.88687
#> 35 0.34 33.05765
#> 36 0.35 33.25432
#> 37 0.36 33.39493
#> 38 0.37 33.71578
#> 39 0.38 33.89373
#> 40 0.39 34.00652
#> 41 0.40 34.10491
#> 42 0.41 34.29988
#> 43 0.42 34.46906
#> 44 0.43 34.62938
#> 45 0.44 34.79762
#> 46 0.45 34.96862
#> 47 0.46 35.03060
#> 48 0.47 35.11433
#> 49 0.48 35.26490
#> 50 0.49 35.44379
#> 51 0.50 35.61827
#> 52 0.51 35.71429
#> 53 0.52 35.81046
#> 54 0.53 35.98469
#> 55 0.54 36.00985
#> 56 0.55 36.16292
#> 57 0.56 36.36637
#> 58 0.57 36.52719
#> 59 0.58 36.69159
#> 60 0.59 36.92817
#> 61 0.60 37.00000
#> 62 0.61 37.10172
#> 63 0.62 37.26884
#> 64 0.63 37.36489
#> 65 0.64 37.47648
#> 66 0.65 37.60743
#> 67 0.66 37.90248
#> 68 0.67 38.04388
#> 69 0.68 38.17743
#> 70 0.69 38.26990
#> 71 0.70 38.52281
#> 72 0.71 38.77707
#> 73 0.72 39.00294
#> 74 0.73 39.19514
#> 75 0.74 39.49518
#> 76 0.75 39.61129
#> 77 0.76 39.86391
#> 78 0.77 40.00000
#> 79 0.78 40.22007
#> 80 0.79 40.52953
#> 81 0.80 40.75290
#> 82 0.81 40.98438
#> 83 0.82 41.06025
#> 84 0.83 41.34185
#> 85 0.84 41.57229
#> 86 0.85 41.99953
#> 87 0.86 42.15422
#> 88 0.87 42.33000
#> 89 0.88 42.65776
#> 90 0.89 42.95536
#> 91 0.90 43.10349
#> 92 0.91 43.51349
#> 93 0.92 44.00000
#> 94 0.93 44.33328
#> 95 0.94 44.91363
#> 96 0.95 45.15529
#> 97 0.96 45.74946
#> 98 0.97 46.39202
#> 99 0.98 47.14190
#> 100 0.99 49.00000
#> 101 1.00 55.00000
# calculate distribution of maximum population sizes
get_cdf(sims, fn = max)
#> prob value
#> 1 0.00 106.6000
#> 2 0.01 179.2690
#> 3 0.02 188.6445
#> 4 0.03 194.3835
#> 5 0.04 205.2020
#> 6 0.05 214.3662
#> 7 0.06 219.1335
#> 8 0.07 223.7510
#> 9 0.08 225.7800
#> 10 0.09 230.1690
#> 11 0.10 232.6200
#> 12 0.11 235.0225
#> 13 0.12 237.5710
#> 14 0.13 242.7435
#> 15 0.14 245.5720
#> 16 0.15 247.5475
#> 17 0.16 251.6210
#> 18 0.17 254.2320
#> 19 0.18 256.2115
#> 20 0.19 257.0810
#> 21 0.20 260.9200
#> 22 0.21 263.7765
#> 23 0.22 264.7500
#> 24 0.23 266.2425
#> 25 0.24 267.7880
#> 26 0.25 271.8062
#> 27 0.26 273.7110
#> 28 0.27 274.9365
#> 29 0.28 276.2860
#> 30 0.29 277.0000
#> 31 0.30 278.1850
#> 32 0.31 279.5225
#> 33 0.32 282.6180
#> 34 0.33 284.4500
#> 35 0.34 286.0480
#> 36 0.35 287.1825
#> 37 0.36 288.1300
#> 38 0.37 291.4667
#> 39 0.38 293.5170
#> 40 0.39 295.0500
#> 41 0.40 297.1800
#> 42 0.41 297.8500
#> 43 0.42 300.2190
#> 44 0.43 303.0855
#> 45 0.44 305.7080
#> 46 0.45 306.9638
#> 47 0.46 308.1850
#> 48 0.47 309.5445
#> 49 0.48 313.2550
#> 50 0.49 315.1520
#> 51 0.50 316.9500
#> 52 0.51 317.3000
#> 53 0.52 318.3940
#> 54 0.53 320.3735
#> 55 0.54 323.4230
#> 56 0.55 324.5225
#> 57 0.56 325.9420
#> 58 0.57 327.8865
#> 59 0.58 329.1210
#> 60 0.59 331.5615
#> 61 0.60 334.7000
#> 62 0.61 336.1890
#> 63 0.62 337.1950
#> 64 0.63 338.4665
#> 65 0.64 342.3480
#> 66 0.65 344.2050
#> 67 0.66 345.8190
#> 68 0.67 347.6495
#> 69 0.68 348.4160
#> 70 0.69 351.4440
#> 71 0.70 355.5600
#> 72 0.71 356.5500
#> 73 0.72 357.8640
#> 74 0.73 359.7715
#> 75 0.74 362.1320
#> 76 0.75 364.7125
#> 77 0.76 367.2120
#> 78 0.77 368.9402
#> 79 0.78 373.2110
#> 80 0.79 376.0210
#> 81 0.80 377.4300
#> 82 0.81 380.1570
#> 83 0.82 385.8770
#> 84 0.83 388.2670
#> 85 0.84 392.7460
#> 86 0.85 397.0300
#> 87 0.86 400.5060
#> 88 0.87 405.8130
#> 89 0.88 408.3100
#> 90 0.89 410.0555
#> 91 0.90 415.3600
#> 92 0.91 420.7360
#> 93 0.92 427.6780
#> 94 0.93 429.9990
#> 95 0.94 436.1120
#> 96 0.95 440.1075
#> 97 0.96 447.9680
#> 98 0.97 457.8770
#> 99 0.98 473.6580
#> 100 0.99 496.6065
#> 101 1.00 626.6000
# calculate distribution of the 90th percentile of
# population sizes
get_cdf(sims, fn = quantile, prob = 0.9)
#> prob value
#> 1 0.00 72.60405
#> 2 0.01 103.12801
#> 3 0.02 108.89865
#> 4 0.03 114.06997
#> 5 0.04 117.19870
#> 6 0.05 119.33873
#> 7 0.06 120.56043
#> 8 0.07 122.34790
#> 9 0.08 125.22585
#> 10 0.09 126.53797
#> 11 0.10 127.91653
#> 12 0.11 129.69148
#> 13 0.12 130.97569
#> 14 0.13 133.46854
#> 15 0.14 134.16345
#> 16 0.15 136.12869
#> 17 0.16 136.85054
#> 18 0.17 137.94612
#> 19 0.18 139.17403
#> 20 0.19 140.66085
#> 21 0.20 141.84262
#> 22 0.21 142.48935
#> 23 0.22 143.45515
#> 24 0.23 144.25643
#> 25 0.24 145.18974
#> 26 0.25 145.95662
#> 27 0.26 146.72567
#> 28 0.27 147.79791
#> 29 0.28 148.70207
#> 30 0.29 150.35767
#> 31 0.30 151.22616
#> 32 0.31 152.00739
#> 33 0.32 152.53833
#> 34 0.33 153.35770
#> 35 0.34 154.16472
#> 36 0.35 154.94460
#> 37 0.36 155.63246
#> 38 0.37 156.42225
#> 39 0.38 157.49263
#> 40 0.39 158.08255
#> 41 0.40 158.99100
#> 42 0.41 159.95092
#> 43 0.42 160.60352
#> 44 0.43 161.55798
#> 45 0.44 162.32917
#> 46 0.45 163.04694
#> 47 0.46 163.57178
#> 48 0.47 164.15111
#> 49 0.48 164.52461
#> 50 0.49 165.12837
#> 51 0.50 166.22906
#> 52 0.51 167.11401
#> 53 0.52 167.95114
#> 54 0.53 168.98904
#> 55 0.54 169.39988
#> 56 0.55 170.16796
#> 57 0.56 171.06326
#> 58 0.57 171.77349
#> 59 0.58 172.83457
#> 60 0.59 173.32716
#> 61 0.60 174.18867
#> 62 0.61 174.90557
#> 63 0.62 176.03002
#> 64 0.63 176.61001
#> 65 0.64 177.52854
#> 66 0.65 178.56211
#> 67 0.66 179.10518
#> 68 0.67 179.66187
#> 69 0.68 180.24424
#> 70 0.69 180.86417
#> 71 0.70 181.76897
#> 72 0.71 182.59767
#> 73 0.72 183.57485
#> 74 0.73 184.46605
#> 75 0.74 185.06136
#> 76 0.75 186.48697
#> 77 0.76 187.14173
#> 78 0.77 188.71216
#> 79 0.78 190.27955
#> 80 0.79 190.91235
#> 81 0.80 191.56821
#> 82 0.81 192.60072
#> 83 0.82 194.23600
#> 84 0.83 195.03251
#> 85 0.84 196.88636
#> 86 0.85 197.68352
#> 87 0.86 198.68146
#> 88 0.87 201.58530
#> 89 0.88 202.68951
#> 90 0.89 204.98666
#> 91 0.90 206.59388
#> 92 0.91 208.95055
#> 93 0.92 211.37520
#> 94 0.93 213.38728
#> 95 0.94 215.90461
#> 96 0.95 217.58186
#> 97 0.96 219.72101
#> 98 0.97 223.29559
#> 99 0.98 230.97773
#> 100 0.99 238.22869
#> 101 1.00 316.65094
# calculate distribution of minimum population sizes
# but ignore first 10 years
get_cdf(sims, fn = max, times = 11:51)
#> prob value
#> 1 0.00 72.60405
#> 2 0.01 115.76272
#> 3 0.02 121.43059
#> 4 0.03 125.23788
#> 5 0.04 128.73525
#> 6 0.05 130.90704
#> 7 0.06 133.18926
#> 8 0.07 135.54819
#> 9 0.08 137.51902
#> 10 0.09 140.88699
#> 11 0.10 142.47271
#> 12 0.11 146.08277
#> 13 0.12 147.81183
#> 14 0.13 149.24120
#> 15 0.14 150.92684
#> 16 0.15 152.40870
#> 17 0.16 153.88629
#> 18 0.17 155.69653
#> 19 0.18 157.21321
#> 20 0.19 158.74907
#> 21 0.20 160.13876
#> 22 0.21 161.44972
#> 23 0.22 162.65037
#> 24 0.23 163.45212
#> 25 0.24 164.26924
#> 26 0.25 165.49903
#> 27 0.26 166.61370
#> 28 0.27 167.57855
#> 29 0.28 168.85796
#> 30 0.29 170.21830
#> 31 0.30 171.24666
#> 32 0.31 172.84614
#> 33 0.32 174.01211
#> 34 0.33 174.82302
#> 35 0.34 175.66674
#> 36 0.35 176.22651
#> 37 0.36 177.13126
#> 38 0.37 177.85432
#> 39 0.38 178.58576
#> 40 0.39 179.13544
#> 41 0.40 179.92571
#> 42 0.41 180.90098
#> 43 0.42 182.23880
#> 44 0.43 183.27342
#> 45 0.44 184.08123
#> 46 0.45 184.81824
#> 47 0.46 185.37212
#> 48 0.47 186.16840
#> 49 0.48 187.27806
#> 50 0.49 188.56554
#> 51 0.50 189.59474
#> 52 0.51 190.27609
#> 53 0.52 191.02280
#> 54 0.53 191.94946
#> 55 0.54 193.00215
#> 56 0.55 194.51393
#> 57 0.56 195.38511
#> 58 0.57 196.15353
#> 59 0.58 196.96250
#> 60 0.59 198.55732
#> 61 0.60 199.46796
#> 62 0.61 200.67572
#> 63 0.62 201.26963
#> 64 0.63 202.01988
#> 65 0.64 202.78276
#> 66 0.65 203.86671
#> 67 0.66 205.05017
#> 68 0.67 205.91927
#> 69 0.68 206.36119
#> 70 0.69 207.15708
#> 71 0.70 208.05542
#> 72 0.71 209.70641
#> 73 0.72 210.93852
#> 74 0.73 212.33498
#> 75 0.74 213.53085
#> 76 0.75 214.96170
#> 77 0.76 216.47110
#> 78 0.77 217.56840
#> 79 0.78 218.99511
#> 80 0.79 220.03851
#> 81 0.80 221.47350
#> 82 0.81 222.80570
#> 83 0.82 224.39408
#> 84 0.83 225.89362
#> 85 0.84 228.06640
#> 86 0.85 230.53583
#> 87 0.86 231.99711
#> 88 0.87 233.67544
#> 89 0.88 235.96152
#> 90 0.89 237.32509
#> 91 0.90 239.50586
#> 92 0.91 241.64867
#> 93 0.92 243.63605
#> 94 0.93 246.81354
#> 95 0.94 247.76114
#> 96 0.95 251.45786
#> 97 0.96 254.22533
#> 98 0.97 257.74538
#> 99 0.98 268.63742
#> 100 0.99 279.46384
#> 101 1.00 370.99709