Fits an appropriate distribution to the given population using gamlss
and draws samples from the fitted model.
Usage
sample_dist(nsample, pop, return_fit = TRUE, seed = NULL)
Arguments
- nsample
An integer. Number of samples to generate.
- pop
A numeric vector. Population data to fit a distribution to.
- return_fit
Logical (default: TRUE). If TRUE, return the fitted distribution object.
- seed
An optional numeric. Random seed for reproducibility.
Value
A list with elements:
sample
A numeric vector of sampled values.
fit
(Optional) A fitted distribution object from gamlss::fitDist.
Details
This function uses gamlss to automatically fit the best candidate distribution
(from the "realAll" family) to the non-missing values in pop.
It then draws nsample values from this distribution.
Values are filtered to ensure they are non-zero and below the maximum of pop.
Note
Requires the gamlss and gamlss.dist packages.
Examples
if (FALSE) { # \dontrun{
pop_data <- rlnorm(1000, meanlog = 1, sdlog = 0.5)
result <- sample_dist(nsample = 100, pop = pop_data, seed = 42)
hist(result$sample)
} # }