90%-confidence interval based univariate random number generation (by exact parameter calculation).

Description

This function generates random numbers for a set of univariate parametric distributions from given 90% confidence interval. Internally, this is achieved by exact, i.e. analytic, calculation of the parameters for the individual distribution from the given 90% confidence interval.

Usage

1
rdist90ci_exact(distribution, n, lower, upper)

Arguments

distribution

character; A character string that defines the univariate distribution to be randomly sampled. For possible options cf. section Details.

n

Number of generated observations.

lower

numeric; lower bound of the 90% confidence interval.

upper

numeric; upper bound of the 90% confidence interval.

Details

The following table shows the available distributions and their identification (option: distribution) as a character string:

distribution Distribution Name Requirements
"const" Deterministic case lower == upper
"norm" Normal lower < upper
"lnorm" Log Normal 0 < lower < upper
"unif" Uniform lower < upper

Parameter formulae

We use the notation: l=lower and u=upper; Φ is the cumulative distribution function of the standard normal distribution and Φ^(-1) its inverse, which is the quantile function of the standard normal distribution.

distribution="norm":

The formulae for μ and σ, viz. the mean and standard deviation, respectively, of the normal distribution are μ=(l+u)/2 and σ=(μ - l)/Φ^(-1)(0.95).

distribution="unif":

For the minimum a and maximum b of the uniform distribution U([a,b]) it holds that a = l - 0.05 (u - l) and b = u + 0.05 (u - l).

distribution="lnorm":

The density of the log normal distribution is f(x)=1/((2 π)^(1/2)σ x) exp(-1/2(((ln(x)-μ)/σ)^2)) for x > 0 and f(x) = 0 otherwise. Its parameters are determined by the confidence interval via μ = (ln(l)+ln(u))/2 and σ = (μ-ln(l))/Φ^(-1)(0.95) . Note the correspondence to the formula for the normal distribution.

Value

A numeric vector of length n with the sampled values according to the chosen distribution.

In case of distribution="const", viz. the deterministic case, the function returns: rep(lower, n).

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Generate uniformly distributed random numbers:
lower=3
upper=6
hist(r<-rdist90ci_exact(distribution="unif", n=10000, lower=lower, upper=upper),breaks=100)
print(quantile(x=r, probs=c(0.05,0.95)))
print(summary(r))

# Generate log normal distributed random numbers:
hist(r<-rdist90ci_exact(distribution="lnorm", n=10000, lower=lower, upper=upper),breaks=100)
print(quantile(x=r, probs=c(0.05,0.95)))
print(summary(r))

Want to suggest features or report bugs for rdrr.io? Use the GitHub issue tracker.