View source: R/rdist90ci_exact.R
rdist90ci_exact | R Documentation |
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.
rdist90ci_exact(distribution, n, lower, upper)
distribution |
|
n |
Number of generated observations. |
lower |
|
upper |
|
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
|
We use the notation: l
=lower
and u
=upper
;
\Phi
is the cumulative distribution function of the standard normal distribution and
\Phi^{-1}
its inverse, which is the quantile function of the standard normal
distribution.
distribution="norm":
The formulae for \mu
and \sigma
, viz. the
mean and standard deviation, respectively, of the normal distribution are
\mu=\frac{l+u}{2}
and
\sigma=\frac{\mu - l}{\Phi^{-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) = \frac{1}{ \sqrt{2 \pi} \sigma x } \exp( - \frac{( \ln(x) - \mu )^2 %
}{
2 \sigma^2})
for x > 0
and f(x) = 0
otherwise.
Its parameters are determined by the confidence interval via
\mu = \frac{\ln(l) + \ln(u)}{2}
and
\sigma = \frac{1}{\Phi^{-1}(0.95)} ( \mu - \ln(l) )
. Note the correspondence to the formula for the normal distribution.
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).
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.