Mean and standard deviation parameterised Weibull sampling function

rweibull_with_mean_sd(n, mean, sd)

Arguments

n

Numeric, the number of samples to take.

mean

Numeric, the mean of the distribution.

sd

Numeric the standard deviation of the distribution.

Value

A vector of samples from the Weibull distribution

Examples

## Example sample <- rweibull_with_mean_sd(1000, 3, 5) mean(sample)
#> [1] 2.792536
sd(sample)
#> [1] 4.466703
hist(sample)
## Code rweibull_with_mean_sd
#> function (n, mean, sd) #> { #> mu <- mean #> sigma <- sd #> loc <- 0 #> cv <- sigma/(mu - loc) #> if (cv < 1e-06) { #> nu <- cv/(sqrt(trigamma(1)) - cv * digamma(1)) #> shape <- 1/nu #> scale <- (mu - loc)/(1 + nu * digamma(1)) #> } #> else { #> aa <- log(cv^2 + 1) #> nu <- 2 * cv/(1 + cv) #> repeat { #> gb <- (lgamma(1 + 2 * nu) - 2 * lgamma(1 + nu) - #> aa)/(2 * (digamma(1 + 2 * nu) - digamma(1 + nu))) #> nu <- nu - gb #> if (abs(gb) < 1e-12) #> break #> } #> shape <- 1/nu #> scale <- exp(log(mu - loc) - lgamma(1 + nu)) #> } #> stats::rweibull(n, shape = shape, scale = scale) #> } #> <bytecode: 0x55a6b7b33fe8> #> <environment: namespace:WuhanSeedingVsTransmission>