sampleobs: Random Draws

View source: R/sampleobs.R

sampleobsR Documentation

Random Draws

Description

sampleobs returns nsim random draws from a two-parameter probability distribution specified by the function's arguments.

Usage

sampleobs(nsim = 99, distrib, mu, sig)

Arguments

nsim

double, length = 1, number of draws (simulations)

distrib

character, length = 1, distribution family, i.e. one of c("Gamma", "LogNormal", "TruncNormal", "Weibull", "ZIExponential", "NegBinom", "Poisson", "ZIP") or copy obs (when distrib == "NoBoot")

mu

double, length = 1, parameter 1 of model distribution

sig

double, length = 1, parameter 2 of model distribution

Details

sampleobs samples from a single distribution among a predetermined set of distribution families. The predetermined set consists of the gamma-, lognormal-, truncated normal-, Weibull-, zero-inflated exponential-, negative binomial-, Poisson-, and zero-inflated Poisson distribution families. The lower bound in the truncated normal distribution is always zero, while the upper bound is infinity. With these restrictions all distributions in the set have two parameters, except the Poisson with only one parameter.

sampleobs is a utility function adapted to the mathematical framework for calculating the nature index.

sampleobs calls random generation functions rLOGNO, rWEI, qGA, rPO, rNBII, rZIP in the gamlss.dist package, rtnorm in the msm package, runif and rexp in the stats package.

Value

double vector, length = nsim, nsim random draws from model specified by distrib, mu, and sig.

Author(s)

Nigel Yoccoz and Bård Pedersen

See Also

sampleObsMat

Examples

nn <- 100000
hist(sampleobs(nsim = nn, distrib="Gamma", mu = 1, sig = 0.5), breaks=50)
hist(sampleobs(nsim = nn, distrib="LogNormal", mu = -2, sig = 0.5), breaks=50)
hist(sampleobs(nsim = nn, distrib="TruncNormal", mu = -2, sig = 0.5), breaks=50)
hist(sampleobs(nsim = nn, distrib="Weibull", mu = 2, sig = 7), breaks=50)
hist(sampleobs(nsim = nn, distrib="ZIExponential", mu = 0.2, sig = 0.5),
     breaks=50)
hist(sampleobs(nsim = nn, distrib="NegBinom", mu = 4, sig = 1))
hist(sampleobs(nsim = nn, distrib="Poisson", mu = 4, sig = NA))
hist(sampleobs(nsim = nn, distrib="ZIP", mu = 10, sig = 0.25))


NINAnor/NIcalc documentation built on Oct. 26, 2023, 9:37 a.m.