rtruncbeta | R Documentation |
Random generation for the truncated exponential family distributions. Please refer to the "Details" and "Examples" section for more information on how to use this function.
rtruncbeta(n, shape1, shape2, a = 0, b = 1, faster = FALSE)
rtruncbinom(n, size, prob, a = 0, b = size, faster = FALSE)
rtruncchisq(n, df, a = 0, b = Inf, faster = FALSE)
rtrunccontbern(n, lambda, a = 0, b = 1, faster = FALSE)
rtruncexp(n, rate = 1, a = 0, b = Inf, faster = FALSE)
rtruncgamma(n, shape, rate = 1, scale = 1/rate, a = 0, b = Inf, faster = FALSE)
rtruncinvgamma(
n,
shape,
rate = 1,
scale = 1/rate,
a = 0,
b = Inf,
faster = FALSE
)
rtruncinvgauss(n, m, s, a = 0, b = Inf, faster = FALSE)
rtrunclnorm(n, meanlog, sdlog, a = 0, b = Inf, faster = FALSE)
rtruncnbinom(n, size, prob, mu, a = 0, b = Inf, faster = FALSE)
rtruncnorm(n, mean, sd, a = -Inf, b = Inf, faster = FALSE)
rtruncpois(n, lambda, a = 0, b = Inf, faster = FALSE)
rtrunc(n, family = "gaussian", faster = FALSE, ...)
rtrunc_direct(n, family = "gaussian", parms, a, b, ...)
n |
sample size |
shape1 |
positive shape parameter alpha |
shape2 |
positive shape parameter beta |
a |
point of left truncation. For discrete distributions, |
b |
point of right truncation |
faster |
if |
size |
target for number of successful trials, or dispersion parameter (the shape parameter of the gamma mixing distribution). Must be strictly positive, need not be integer. |
prob |
probability of success on each trial |
df |
degrees of freedom for "parent" distribution |
lambda |
mean and var of "parent" distribution |
rate |
inverse gamma rate parameter |
shape |
inverse gamma shape parameter |
scale |
inverse gamma scale parameter |
m |
vector of means |
s |
vector of dispersion parameters |
meanlog |
mean of untruncated distribution |
sdlog |
standard deviation of untruncated distribution |
mu |
alternative parametrization via mean |
mean |
mean of parent distribution |
sd |
standard deviation is parent distribution |
family |
distribution family to use |
... |
individual arguments to each distribution |
parms |
list of parameters passed to rtrunc (through the |
One way to use this function is by calling the rtrunc
generic with the family
parameter of your choice. You can also
specifically call one of the methods (e.g. rtruncpois(10, lambda=3)
instead of rtrunc(10, family="poisson", lambda=3)). The latter is more flexible (i.e., easily programmable) and more robust (i.e., it contains better error handling and validation procedures), while the former better conforms with the nomenclature from other distribution-related functions in the
stats' package.
Setting faster=TRUE
uses a new algorithm that samples directly from
the truncated distribution, as opposed to the old algorithm that samples
from the untruncated distribution and then truncates the result. The
advantage of the new algorithm is that it is way faster than the old one,
particularly for highly-truncated distributions. On the other hand, the
sample for untruncated distributions called through rtrunc()
will no longer
match their stats-package counterparts for the same seed.
A sample of size n drawn from a truncated distribution
vector of one of the rtrunc_*
classes containing the sample
elements, as well as some attributes related to the chosen distribution.
The current sample-generating algorithm may be slow if the distribution is largely represented by low-probability values. This will be fixed soon. Please follow https://github.com/ocbe-uio/TruncExpFam/issues/72 for details.
René Holst, Waldir Leôncio
# Truncated binomial distribution
sample.binom <- rtrunc(
100, family = "binomial", prob = 0.6, size = 20, a = 4, b = 10
)
sample.binom
plot(
table(sample.binom), ylab = "Frequency", main = "Freq. of sampled values"
)
# Truncated Log-Normal distribution
sample.lognorm <- rtrunc(
n = 100, family = "lognormal", meanlog = 2.5, sdlog = 0.5, a = 7
)
summary(sample.lognorm)
hist(
sample.lognorm,
nclass = 35, xlim = c(0, 60), freq = FALSE,
ylim = c(0, 0.15)
)
# Normal distribution
sample.norm <- rtrunc(n = 100, mean = 2, sd = 1.5, a = -1)
head(sample.norm)
hist(sample.norm, nclass = 25)
# Gamma distribution
sample.gamma <- rtrunc(n = 100, family = "gamma", shape = 6, rate = 2, a = 2)
hist(sample.gamma, nclass = 15)
# Poisson distribution
sample.pois <- rtrunc(n = 10, family = "poisson", lambda = 10, a = 4)
sample.pois
plot(table(sample.pois))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.