rdist: Random generation for a specified distribution

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Random generation for a specified distribution

Usage

1
rdist(dist, n, arg_list, lookup_verbose = F, ...)

Arguments

dist

character string, specification of the distribution of interest using the abbreviations from distributions

n

number of random values to return

arg_list

list, alternative to directly using the names of the arguments for the distribution of choice, the user can provide a list with those arguments enclosed. This is useful for when multiple distributions need to be drawn from.

lookup_verbose

logical, whether to print the abbreviated name found in the dist_lookup_table

...

arguments specific to the distribution of interest (e.g. the "binom" distribution requires arguments for size and prob)

Value

a numeric vector representing a random draw from the distribution of interest

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
## create a function that adds two distributions together
two_dist_sum <- function(n_sims, dist1, dist1_args, dist2, dist2_args){
x1 <- rdist(dist1, n=n_sims, arg_list=dist1_args)
x2 <- rdist(dist2, n=n_sims, arg_list=dist2_args)
return(x1+x2)
}
## use distribution to find time from exposure to covid-19 to hospitalization
## using log-normal incubation time from Lauer, Grantz, et al.
## and time from onset to hospitalization from Bi et al.
x <- two_dist_sum(n=1000,
                  dist1="lnorm",
                  dist1_args=list(meanlog=1.621,
                                  sdlog=0.418),
                  dist2="lnorm",
                  dist2_args=list(meanlog=1.23,
                                  sdlog=0.79))
summary(x)
## now change incubation time to gamma distribution from Lauer, Grantz, et al.
x_gamma <- two_dist_sum(n_sims=1000,
                        dist1="gamma",
                        dist1_args=list(shape=5.807,
                                        scale=0.948),
                        dist2="lnorm",
                        dist2_args=list(meanlog=1.23,
                                        sdlog=0.79))
summary(x_gamma)

salauer/gdist documentation built on Oct. 4, 2020, 11:09 p.m.