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
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.50025
#> 5 0.04 25.07719
#> 6 0.05 25.86276
#> 7 0.06 26.17925
#> 8 0.07 26.54805
#> 9 0.08 26.98110
#> 10 0.09 27.39402
#> 11 0.10 27.75102
#> 12 0.11 28.10893
#> 13 0.12 28.44459
#> 14 0.13 28.72739
#> 15 0.14 28.89518
#> 16 0.15 29.26845
#> 17 0.16 29.54110
#> 18 0.17 29.79708
#> 19 0.18 29.96741
#> 20 0.19 30.10235
#> 21 0.20 30.30590
#> 22 0.21 30.49734
#> 23 0.22 30.71935
#> 24 0.23 31.02480
#> 25 0.24 31.38251
#> 26 0.25 31.51606
#> 27 0.26 31.70489
#> 28 0.27 31.84011
#> 29 0.28 32.02076
#> 30 0.29 32.11840
#> 31 0.30 32.29321
#> 32 0.31 32.42737
#> 33 0.32 32.62251
#> 34 0.33 32.89643
#> 35 0.34 33.11139
#> 36 0.35 33.25719
#> 37 0.36 33.43435
#> 38 0.37 33.73364
#> 39 0.38 33.91936
#> 40 0.39 34.01614
#> 41 0.40 34.13088
#> 42 0.41 34.29988
#> 43 0.42 34.46214
#> 44 0.43 34.59155
#> 45 0.44 34.77819
#> 46 0.45 34.93762
#> 47 0.46 35.02336
#> 48 0.47 35.11018
#> 49 0.48 35.25767
#> 50 0.49 35.44379
#> 51 0.50 35.61827
#> 52 0.51 35.71429
#> 53 0.52 35.80095
#> 54 0.53 35.98422
#> 55 0.54 36.00909
#> 56 0.55 36.16996
#> 57 0.56 36.37793
#> 58 0.57 36.54225
#> 59 0.58 36.72921
#> 60 0.59 36.92905
#> 61 0.60 37.00000
#> 62 0.61 37.11719
#> 63 0.62 37.29400
#> 64 0.63 37.37038
#> 65 0.64 37.47648
#> 66 0.65 37.59720
#> 67 0.66 37.88753
#> 68 0.67 38.00000
#> 69 0.68 38.12052
#> 70 0.69 38.26009
#> 71 0.70 38.50820
#> 72 0.71 38.71474
#> 73 0.72 38.93193
#> 74 0.73 39.11051
#> 75 0.74 39.40314
#> 76 0.75 39.56568
#> 77 0.76 39.76589
#> 78 0.77 40.00000
#> 79 0.78 40.19688
#> 80 0.79 40.50912
#> 81 0.80 40.72788
#> 82 0.81 40.95404
#> 83 0.82 41.03296
#> 84 0.83 41.31114
#> 85 0.84 41.58143
#> 86 0.85 42.00000
#> 87 0.86 42.15789
#> 88 0.87 42.38597
#> 89 0.88 42.67706
#> 90 0.89 42.97996
#> 91 0.90 43.12459
#> 92 0.91 43.54013
#> 93 0.92 44.00000
#> 94 0.93 44.33473
#> 95 0.94 44.95567
#> 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.7985
#> 4 0.03 194.5213
#> 5 0.04 206.4260
#> 6 0.05 214.3662
#> 7 0.06 217.6490
#> 8 0.07 223.0965
#> 9 0.08 225.5260
#> 10 0.09 230.1690
#> 11 0.10 231.8750
#> 12 0.11 234.7725
#> 13 0.12 236.0940
#> 14 0.13 242.3012
#> 15 0.14 245.0430
#> 16 0.15 247.1700
#> 17 0.16 251.1810
#> 18 0.17 253.7660
#> 19 0.18 255.6775
#> 20 0.19 256.9215
#> 21 0.20 259.2700
#> 22 0.21 263.3500
#> 23 0.22 264.7280
#> 24 0.23 265.5500
#> 25 0.24 267.0760
#> 26 0.25 271.6875
#> 27 0.26 273.7110
#> 28 0.27 275.1325
#> 29 0.28 276.3360
#> 30 0.29 277.0000
#> 31 0.30 278.2350
#> 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 287.9960
#> 38 0.37 291.2047
#> 39 0.38 293.2240
#> 40 0.39 295.0500
#> 41 0.40 296.9900
#> 42 0.41 297.7180
#> 43 0.42 299.0530
#> 44 0.43 302.9248
#> 45 0.44 305.5760
#> 46 0.45 306.9887
#> 47 0.46 308.3000
#> 48 0.47 309.5445
#> 49 0.48 313.2550
#> 50 0.49 315.1520
#> 51 0.50 316.9500
#> 52 0.51 317.3735
#> 53 0.52 318.8240
#> 54 0.53 321.0675
#> 55 0.54 323.6865
#> 56 0.55 324.7075
#> 57 0.56 326.5160
#> 58 0.57 328.3145
#> 59 0.58 329.2130
#> 60 0.59 332.5215
#> 61 0.60 334.8400
#> 62 0.61 336.3780
#> 63 0.62 337.5260
#> 64 0.63 338.8832
#> 65 0.64 343.0080
#> 66 0.65 344.4262
#> 67 0.66 346.2180
#> 68 0.67 347.8165
#> 69 0.68 349.1140
#> 70 0.69 353.2465
#> 71 0.70 355.7300
#> 72 0.71 356.6080
#> 73 0.72 357.9280
#> 74 0.73 359.7715
#> 75 0.74 362.6760
#> 76 0.75 364.8625
#> 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 386.1080
#> 84 0.83 388.5105
#> 85 0.84 394.0220
#> 86 0.85 397.0300
#> 87 0.86 400.0630
#> 88 0.87 405.6695
#> 89 0.88 408.2060
#> 90 0.89 410.0055
#> 91 0.90 413.6750
#> 92 0.91 419.9265
#> 93 0.92 428.0080
#> 94 0.93 430.6535
#> 95 0.94 437.0040
#> 96 0.95 440.6125
#> 97 0.96 448.4040
#> 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 104.36872
#> 3 0.02 109.57635
#> 4 0.03 113.98770
#> 5 0.04 117.03086
#> 6 0.05 119.25116
#> 7 0.06 120.48297
#> 8 0.07 122.17755
#> 9 0.08 125.10460
#> 10 0.09 126.44915
#> 11 0.10 127.48861
#> 12 0.11 129.56845
#> 13 0.12 130.94461
#> 14 0.13 133.26037
#> 15 0.14 134.16345
#> 16 0.15 136.07673
#> 17 0.16 136.79577
#> 18 0.17 137.92871
#> 19 0.18 139.04162
#> 20 0.19 140.66085
#> 21 0.20 141.89541
#> 22 0.21 142.54823
#> 23 0.22 143.64532
#> 24 0.23 144.84630
#> 25 0.24 145.50159
#> 26 0.25 146.25969
#> 27 0.26 147.15415
#> 28 0.27 148.15723
#> 29 0.28 149.34451
#> 30 0.29 150.60227
#> 31 0.30 151.29061
#> 32 0.31 152.07232
#> 33 0.32 152.64892
#> 34 0.33 153.41028
#> 35 0.34 154.28242
#> 36 0.35 154.94913
#> 37 0.36 155.70900
#> 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 162.96356
#> 47 0.46 163.48294
#> 48 0.47 164.10534
#> 49 0.48 164.51370
#> 50 0.49 164.98793
#> 51 0.50 166.05738
#> 52 0.51 167.00468
#> 53 0.52 167.65605
#> 54 0.53 168.75629
#> 55 0.54 169.33171
#> 56 0.55 170.01187
#> 57 0.56 170.90314
#> 58 0.57 171.77349
#> 59 0.58 172.79062
#> 60 0.59 173.26531
#> 61 0.60 174.18867
#> 62 0.61 174.90557
#> 63 0.62 175.99163
#> 64 0.63 176.61001
#> 65 0.64 177.46943
#> 66 0.65 178.41161
#> 67 0.66 179.06053
#> 68 0.67 179.61951
#> 69 0.68 180.14942
#> 70 0.69 180.70002
#> 71 0.70 181.64180
#> 72 0.71 182.46011
#> 73 0.72 183.38087
#> 74 0.73 184.22670
#> 75 0.74 184.95870
#> 76 0.75 186.32928
#> 77 0.76 186.84886
#> 78 0.77 188.57590
#> 79 0.78 190.13100
#> 80 0.79 190.78440
#> 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.87576
#> 87 0.86 198.89799
#> 88 0.87 201.74223
#> 89 0.88 203.23384
#> 90 0.89 205.41228
#> 91 0.90 206.68542
#> 92 0.91 209.29369
#> 93 0.92 211.72132
#> 94 0.93 213.92126
#> 95 0.94 216.63433
#> 96 0.95 218.54883
#> 97 0.96 220.56690
#> 98 0.97 223.49553
#> 99 0.98 232.38828
#> 100 0.99 238.65660
#> 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.21506
#> 5 0.04 127.62619
#> 6 0.05 130.57209
#> 7 0.06 133.15356
#> 8 0.07 135.35690
#> 9 0.08 137.40113
#> 10 0.09 140.58874
#> 11 0.10 142.16353
#> 12 0.11 145.98595
#> 13 0.12 147.76674
#> 14 0.13 148.97059
#> 15 0.14 150.58904
#> 16 0.15 151.70516
#> 17 0.16 153.43348
#> 18 0.17 155.42463
#> 19 0.18 156.99994
#> 20 0.19 158.38123
#> 21 0.20 159.84554
#> 22 0.21 161.38295
#> 23 0.22 162.50157
#> 24 0.23 163.37334
#> 25 0.24 164.11369
#> 26 0.25 165.34267
#> 27 0.26 166.26023
#> 28 0.27 167.57233
#> 29 0.28 168.85796
#> 30 0.29 170.21830
#> 31 0.30 171.24666
#> 32 0.31 172.84614
#> 33 0.32 174.03369
#> 34 0.33 174.91671
#> 35 0.34 175.74356
#> 36 0.35 176.31432
#> 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.33021
#> 44 0.43 183.35052
#> 45 0.44 184.08123
#> 46 0.45 184.81824
#> 47 0.46 185.50603
#> 48 0.47 186.22607
#> 49 0.48 187.64639
#> 50 0.49 188.56554
#> 51 0.50 189.59474
#> 52 0.51 190.27609
#> 53 0.52 191.00557
#> 54 0.53 191.79713
#> 55 0.54 192.90774
#> 56 0.55 194.33935
#> 57 0.56 195.33804
#> 58 0.57 196.08839
#> 59 0.58 196.88567
#> 60 0.59 198.43308
#> 61 0.60 199.41342
#> 62 0.61 200.58977
#> 63 0.62 201.20042
#> 64 0.63 201.96605
#> 65 0.64 202.75025
#> 66 0.65 203.68133
#> 67 0.66 204.87961
#> 68 0.67 205.86585
#> 69 0.68 206.27626
#> 70 0.69 207.09101
#> 71 0.70 207.99619
#> 72 0.71 209.81769
#> 73 0.72 210.96254
#> 74 0.73 212.36930
#> 75 0.74 213.59805
#> 76 0.75 215.02090
#> 77 0.76 216.75549
#> 78 0.77 217.67372
#> 79 0.78 219.44277
#> 80 0.79 220.22557
#> 81 0.80 221.65571
#> 82 0.81 223.07087
#> 83 0.82 224.70453
#> 84 0.83 227.02548
#> 85 0.84 228.56009
#> 86 0.85 230.65204
#> 87 0.86 232.32334
#> 88 0.87 233.81964
#> 89 0.88 236.10922
#> 90 0.89 238.02960
#> 91 0.90 239.97649
#> 92 0.91 241.72083
#> 93 0.92 243.94986
#> 94 0.93 246.87603
#> 95 0.94 248.32314
#> 96 0.95 252.06068
#> 97 0.96 254.71986
#> 98 0.97 258.88722
#> 99 0.98 269.26170
#> 100 0.99 281.47447
#> 101 1.00 370.99709