Skip to contents

[Questioning] 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().

Usage

dist_skel(
  n,
  dist = FALSE,
  cum = TRUE,
  model,
  discrete = FALSE,
  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 ("lognormal")

discrete

Logical, defaults to FALSE. Should the probability distribution be discretised. In this case each entry of the probability mass function corresponds to the 2-length interval ending at the entry except for the first interval that covers (0, 1). That is, the probability mass function is a vector where the first entry corresponds to the integral over the (0,1] interval of the continuous distribution, the second entry corresponds to the (0,2] interval, the third entry corresponds to the (1, 3] interval etc.

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 1 0 0 0 0 1 0 0 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
# sample
dist_skel(10, model = "gamma", params = list(shape = 1, rate = 0.5))
#>  [1] 2 0 2 1 0 0 7 0 0 2

# cumulative prob density
dist_skel(0:10,
  model = "gamma", dist = TRUE,
  params = list(shape = 1, rate = 0.5)
)
#>  [1] 0.0000000 0.3934693 0.6321206 0.7768698 0.8646647 0.9179150 0.9502129
#>  [8] 0.9698026 0.9816844 0.9888910 0.9932621

# probability density
dist_skel(0:10,
  model = "gamma", dist = TRUE,
  cum = FALSE, params = list(shape = 2, rate = 0.5)
)
#>  [1] 0.09020401 0.17403711 0.17793348 0.15181955 0.11870835 0.08814922
#>  [7] 0.06326005 0.04431003 0.03047871 0.02067180 0.01386367

## Log normal model
# sample
dist_skel(10,
  model = "lognormal", params = list(meanlog = log(5), sdlog = log(2))
)
#>  [1]  6  9  3  6  3 15  6  3  4  3

# cumulative prob density
dist_skel(0:10,
  model = "lognormal", dist = TRUE,
  params = list(meanlog = log(5), sdlog = log(2))
)
#>  [1] 0.00000000 0.01011843 0.09309625 0.23057213 0.37375439 0.50000107
#>  [7] 0.60373926 0.68631467 0.75113856 0.80178187 0.84134655

# probability density
dist_skel(0:10,
  model = "lognormal", dist = TRUE, cum = FALSE,
  params = list(meanlog = log(5), sdlog = log(2))
)
#>  [1] 0.01011843 0.08297782 0.13747588 0.14318225 0.12624669 0.10373819
#>  [7] 0.08257540 0.06482389 0.05064331 0.03956468 0.03099139