truncatedDistribution {windAC} | R Documentation |
Truncated Distributions
Description
Truncated probability density function, truncated cumulative density function, inverse truncated cumulative density function, and random variates from a truncated distribution.
Usage
dtrunc(x, distribution, tbound = c(-Inf, Inf), ..., log = FALSE)
ptrunc(
q,
distribution,
tbound = c(-Inf, Inf),
...,
lower.tail = TRUE,
log.p = NULL
)
qtrunc(
p,
distribution,
tbound = c(-Inf, Inf),
...,
lower.tail = TRUE,
log.p = NULL
)
rtrunc(n, distribution, tbound = c(-Inf, Inf), ...)
Arguments
x |
Vector of quantiles. |
distribution |
Character value specifying the desired probability distribution. |
tbound |
Numeric vector specifying the lower and upper truncation bounds. Default is |
... |
Additional arguments passed to the non-truncated distribution functions. |
log |
Logical; if TRUE, log densities are returned. |
q |
Vector of quantiles. |
lower.tail |
Logical; if TRUE (default), probabilities are P(X <= x) otherwise, P(X > x). |
log.p |
Currently ignored. |
p |
Vector of probabilities. |
n |
A positive integer specifying the desired number of random variates. |
Details
The non truncated distribution functions are assumed to be available. For example if the normal distribution is desired then used distribution='norm'
, the functions then look for 'qnorm', 'pnorm', etc.
The max(tbound)
and min(tbound)
are considered the upper and lower truncation bounds, respectively.
The random variates are produced using the direct method (see Casella and Berger 2002).
Value
dtrunc
returns a vector of densities.
ptrunc
returns a vector of probabilities.
qtrunc
returns a vector of quantiles.
rtrunc
returns a vector of random variates.
References
G. Casella and R. L. Berger. Statistical inference. Vol. 2. Duxbury Pacific Grove, CA, 2002.
Examples
## dtrunc
# not truncted
dnorm(5,mean=5)
# truncated
dtrunc(x=5,distribution='norm',tbound=c(4,5.5),mean=5)
## ptrunc
#not truncated
pgamma(2,shape=3,rate=2)
# truncated
ptrunc(2, distribution = 'gamma', tbound=c(1,5),shape=3,rate=2)
## upper tail
# not truncated
pgamma(2,shape=3,rate=2,lower.tail=FALSE)
# truncated
ptrunc(2,distribution='gamma',tbound=c(1,5),shape=3,rate=2,lower.tail=FALSE)
## qtrunc
#not truncated
qnorm(p=.975)
# truncted
qtrunc(p=.975,distribution='norm',tbound=c(0,1))
## upper tail
# not truncted
qnorm(p=.975,lower.tail=FALSE)
# truncated
qtrunc(p=.975,distribution='norm',tbound=c(0,1),lower.tail=FALSE)
## rtrunc
rtrunc(n=5, distribution = 'gamma', tbound=c(2,5),shape=3,rate=2)