This function acts as a skeleton for a truncated distribution defined by model type, maximum value and model parameters. It is designed to be used with the output from get_dist.

dist_skel(n, dist = FALSE, cum = TRUE, model, params, max_value = 120)

Arguments

n

Numeric vector, number of samples to take (or days for the probability density).

dist

Logical, defaults to FALSE. Should the probability density be returned rather than a number of samples.

cum

Logical, defaults to TRUE. If dist = TRUE should the returned distribution be cumulative.

model

Character string, defining the model to be used. Supported options are exponential ("exp"), gamma ("gamma"), and log normal ("lognorm")

params

A list of parameters values (by name) required for each model. For the exponential model this is a rate parameter and for the gamma model this is alpha and beta.

max_value

Numeric, the maximum value to allow. Defaults to 120. Samples outside of this range are resampled.

Value

A vector of samples or a probability distribution.

Examples

## Exponential model ## Sample dist_skel(10, model = "exp", params = list(rate = 1))
#> [1] 0 0 1 0 0 0 0 0 2 0
## Cumulative prob density dist_skel(1:10, model = "exp", dist = TRUE, params = list(rate = 1))
#> [1] 0.6321206 0.8646647 0.9502129 0.9816844 0.9932621 0.9975212 0.9990881 #> [8] 0.9996645 0.9998766 0.9999546
## Probability density dist_skel(1:10, model = "exp", dist = TRUE, cum = FALSE, params = list(rate = 1))
#> [1] 2.325442e-01 8.554821e-02 3.147143e-02 1.157769e-02 4.259195e-03 #> [6] 1.566870e-03 5.764193e-04 2.120528e-04 7.800987e-05 2.869823e-05
## Gamma model dist_skel(10, model = "gamma", params = list(alpha = 1, beta = 2))
#> [1] 1 0 0 0 0 0 0 0 0 0
## Cumulative prob density dist_skel(0:10, model = "gamma", dist = TRUE, params = list(alpha = 1, beta = 2))
#> [1] 0.0000000 0.8646647 0.9816844 0.9975212 0.9996645 0.9999546 0.9999939 #> [8] 0.9999992 0.9999999 1.0000000 1.0000000
## Probability density dist_skel(0:10, model = "gamma", dist = TRUE, cum = FALSE, params = list(alpha = 2, beta = 2))
#> [1] 5.939942e-01 3.144277e-01 7.422693e-02 1.433210e-02 2.519764e-03 #> [6] 4.195245e-04 6.740183e-05 1.055983e-05 1.623728e-06 2.460854e-07 #> [11] 3.686845e-08
## Log normal model dist_skel(10, model = "lognorm", params = list(mean = log(5), sd = log(2)))
#> [1] 8 6 3 2 4 7 12 5 3 2
## Cumulative prob density dist_skel(0:10, model = "lognorm", dist = TRUE, params = list(mean = log(5), sd = log(2)))
#> [1] 0.00000000 0.01011843 0.09309626 0.23057216 0.37375443 0.50000114 #> [7] 0.60373934 0.68631476 0.75113865 0.80178197 0.84134666
## Probability density dist_skel(0:10, model = "lognorm", dist = TRUE, cum = FALSE, params = list(mean = log(5), sd = log(2)))
#> [1] 0.01011843 0.08297783 0.13747590 0.14318227 0.12624670 0.10373821 #> [7] 0.08257541 0.06482390 0.05064332 0.03956468 0.03099140