Learn R Programming

flexCountReg (version 0.1.1)

halton_dists: Generate pseudo-random draws from specified distributions using Halton draws

Description

Generate pseudo-random draws from specified distributions using Halton draws

Usage

halton_dists(dist, mean, sdev, hdraw = NULL, ndraws = 500)

Value

A vector of psudo-random draws from the specified distribution, based on Halton draws.

Arguments

dist

The distribution type to use. The distribution options include normal ("n"), lognormal ("ln"), triangular ("t"), uniform ("u"), and gamma ("g").

mean

The mean value for the random draws.

sdev

The standard deviation value for the random draws.

hdraw

An optional vector of Halton draws to convert to the specified distribution. If not provided, the function will generate Halton draws.

ndraws

The number of random draws to generate. This is only used if `hdraw` is not provided.

Details

This function is used to convert Halton draws to the specified distribution. The function can be used to generate random draws for use in random parameter models, generating Halton-based pseudo-random draws for specified distributions, etc.

The distributions generated all use the `mean` ($$\mu$$) and `sdev` ($$\sigma$$) parameters to generate the random draws. The density functions for the distributions are as follows: The Normal distribution is: \(f(x) = \frac{1}{\sqrt{2\pi\sigma^2}} \exp\left(-\frac{(x - \mu)^2}{2\sigma^2}\right)\)

The Lognormal distribution is: \(f(x) = \frac{1}{x\sigma\sqrt{2\pi}} \exp\left(-\frac{(\log(x) - \mu)^2}{2\sigma^2}\right)\)

The Triangular distribution is (note that this is a symmetrical triangular distribution where $$\mu$$ is the median and $$\sigma$$ is the half-width): \(f(x) = \begin{cases} \frac{(x - \mu + \sigma)}{\sigma^2}, & \text{for } \mu - \sigma \leq x \leq \mu \\ \frac{(\mu + \sigma - x)}{\sigma^2}, & \text{for } \mu < x \leq \mu + \sigma \\0, & \text{otherwise}\end{cases}\)

The Uniform distribution is (note that \(\mu\) is the midpoint and \(\sigma\) is the half-width): \(f(x) = \frac{1}{(\beta_{\mu}+\beta_{\sigma}) - (\beta_{\mu}-\beta_{\sigma})}=\frac{1}{2\beta_{\sigma}}\)

The Gamma distribution is based on $$\mu = \frac{\alpha}{\beta}$$ and $$\sigma^2 = \frac{\alpha}{\beta^2}$$: \(f(x) = \frac{\left(\frac{\mu}{\sigma^2}\right)^ {\frac{\mu^2}{\sigma^2}}}{\Gamma\left(\frac{\mu^2}{\sigma^2}\right)} x^{\frac{\mu^2}{\sigma^2} - 1} e^{-\frac{\mu}{\sigma^2} x}\)

Examples

Run this code
# Generate 500 random draws from a normal distribution 
halton_dists(dist="n", mean=3, sdev=2, ndraws=500)

# Generate 500 random draws from a lognormal distribution 
halton_dists(dist="ln", mean=2, sdev=1.5, ndraws=500)

# Generate 500 random draws from a triangular distribution
halton_dists(dist="t", mean=1, sdev=0.5, ndraws=500)

# Generate 500 random draws from a uniform distribution
halton_dists(dist="u", mean=8, sdev=3, ndraws=500)

# Generate 500 random draws from a gamma distribution
halton_dists(dist="g", mean=0.5, sdev=1.5, ndraws=500)

Run the code above in your browser using DataLab