Title: | Probability Distributions as S3 Objects |
---|---|
Description: | Tools to create and manipulate probability distributions using S3. Generics pdf(), cdf(), quantile(), and random() provide replacements for base R's d/p/q/r style functions. Functions and arguments have been named carefully to minimize confusion for students in intro stats courses. The documentation for each distribution contains detailed mathematical notes. |
Authors: | Alex Hayes [aut, cre] , Ralph Moller-Trane [aut], Emil Hvitfeldt [ctb] , Daniel Jordan [aut], Paul Northrop [aut], Moritz N. Lang [aut] , Achim Zeileis [aut] , Bruna Wundervald [ctb], Alessandro Gasparini [ctb] |
Maintainer: | Alex Hayes <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.2.2.9000 |
Built: | 2024-11-16 05:51:48 UTC |
Source: | https://github.com/alexpghayes/distributions3 |
distributions3
objectsVarious utility functions to implement methods for distributions with a
unified workflow, in particular to facilitate working with vectorized
distributions3
objects.
These are particularly useful in the computation of densities, probabilities, quantiles,
and random samples when classical d/p/q/r functions are readily available for
the distribution of interest.
apply_dpqr(d, FUN, at, elementwise = NULL, drop = TRUE, type = NULL, ...) make_support(min, max, d, drop = TRUE) make_positive_integer(n)
apply_dpqr(d, FUN, at, elementwise = NULL, drop = TRUE, type = NULL, ...) make_support(min, max, d, drop = TRUE) make_positive_integer(n)
d |
A |
FUN |
Function to be computed. Function should be of type |
at |
Specification of values at which |
elementwise |
logical. Should each element of |
drop |
logical. Should the result be simplified to a vector if possible (by
dropping the dimension attribute)? If |
type |
Character string used for naming, typically one of |
... |
Arguments to be passed to |
min , max
|
Numeric vectors. Minima and maxima of the supports of a |
n |
numeric. Number of observations for computing random draws. If |
## Implementing a new distribution based on the provided utility functions ## Illustration: Gaussian distribution ## Note: Gaussian() is really just a copy of Normal() with a different class/distribution name ## Generator function for the distribution object. Gaussian <- function(mu = 0, sigma = 1) { stopifnot( "parameter lengths do not match (only scalars are allowed to be recycled)" = length(mu) == length(sigma) | length(mu) == 1 | length(sigma) == 1 ) d <- data.frame(mu = mu, sigma = sigma) class(d) <- c("Gaussian", "distribution") d } ## Set up a vector Y containing four Gaussian distributions: Y <- Gaussian(mu = 1:4, sigma = c(1, 1, 2, 2)) Y ## Extract the underlying parameters: as.matrix(Y) ## Extractor functions for moments of the distribution include ## mean(), variance(), skewness(), kurtosis(). ## These can be typically be defined as functions of the list of parameters. mean.Gaussian <- function(x, ...) { rlang::check_dots_used() setNames(x$mu, names(x)) } ## Analogously for other moments, see distributions3:::variance.Normal etc. mean(Y) ## The support() method should return a matrix of "min" and "max" for the ## distribution. The make_support() function helps to set the right names and ## dimension. support.Gaussian <- function(d, drop = TRUE, ...) { min <- rep(-Inf, length(d)) max <- rep(Inf, length(d)) make_support(min, max, d, drop = drop) } support(Y) ## Evaluating certain functions associated with the distribution, e.g., ## pdf(), log_pdf(), cdf() quantile(), random(), etc. The apply_dpqr() ## function helps to call the typical d/p/q/r functions (like dnorm, ## pnorm, etc.) and set suitable names and dimension. pdf.Gaussian <- function(d, x, elementwise = NULL, drop = TRUE, ...) { FUN <- function(at, d) dnorm(x = at, mean = d$mu, sd = d$sigma, ...) apply_dpqr(d = d, FUN = FUN, at = x, type = "density", elementwise = elementwise, drop = drop) } ## Evaluate all densities at the same argument (returns vector): pdf(Y, 0) ## Evaluate all densities at several arguments (returns matrix): pdf(Y, c(0, 5)) ## Evaluate each density at a different argument (returns vector): pdf(Y, 4:1) ## Force evaluation of each density at a different argument (returns vector) ## or at all arguments (returns matrix): pdf(Y, 4:1, elementwise = TRUE) pdf(Y, 4:1, elementwise = FALSE) ## Drawing random() samples also uses apply_dpqr() with the argument ## n assured to be a positive integer. random.Gaussian <- function(x, n = 1L, drop = TRUE, ...) { n <- make_positive_integer(n) if (n == 0L) { return(numeric(0L)) } FUN <- function(at, d) rnorm(n = at, mean = d$mu, sd = d$sigma) apply_dpqr(d = x, FUN = FUN, at = n, type = "random", drop = drop) } ## One random sample for each distribution (returns vector): random(Y, 1) ## Several random samples for each distribution (returns matrix): random(Y, 3) ## For further analogous methods see the "Normal" distribution provided ## in distributions3. methods(class = "Normal")
## Implementing a new distribution based on the provided utility functions ## Illustration: Gaussian distribution ## Note: Gaussian() is really just a copy of Normal() with a different class/distribution name ## Generator function for the distribution object. Gaussian <- function(mu = 0, sigma = 1) { stopifnot( "parameter lengths do not match (only scalars are allowed to be recycled)" = length(mu) == length(sigma) | length(mu) == 1 | length(sigma) == 1 ) d <- data.frame(mu = mu, sigma = sigma) class(d) <- c("Gaussian", "distribution") d } ## Set up a vector Y containing four Gaussian distributions: Y <- Gaussian(mu = 1:4, sigma = c(1, 1, 2, 2)) Y ## Extract the underlying parameters: as.matrix(Y) ## Extractor functions for moments of the distribution include ## mean(), variance(), skewness(), kurtosis(). ## These can be typically be defined as functions of the list of parameters. mean.Gaussian <- function(x, ...) { rlang::check_dots_used() setNames(x$mu, names(x)) } ## Analogously for other moments, see distributions3:::variance.Normal etc. mean(Y) ## The support() method should return a matrix of "min" and "max" for the ## distribution. The make_support() function helps to set the right names and ## dimension. support.Gaussian <- function(d, drop = TRUE, ...) { min <- rep(-Inf, length(d)) max <- rep(Inf, length(d)) make_support(min, max, d, drop = drop) } support(Y) ## Evaluating certain functions associated with the distribution, e.g., ## pdf(), log_pdf(), cdf() quantile(), random(), etc. The apply_dpqr() ## function helps to call the typical d/p/q/r functions (like dnorm, ## pnorm, etc.) and set suitable names and dimension. pdf.Gaussian <- function(d, x, elementwise = NULL, drop = TRUE, ...) { FUN <- function(at, d) dnorm(x = at, mean = d$mu, sd = d$sigma, ...) apply_dpqr(d = d, FUN = FUN, at = x, type = "density", elementwise = elementwise, drop = drop) } ## Evaluate all densities at the same argument (returns vector): pdf(Y, 0) ## Evaluate all densities at several arguments (returns matrix): pdf(Y, c(0, 5)) ## Evaluate each density at a different argument (returns vector): pdf(Y, 4:1) ## Force evaluation of each density at a different argument (returns vector) ## or at all arguments (returns matrix): pdf(Y, 4:1, elementwise = TRUE) pdf(Y, 4:1, elementwise = FALSE) ## Drawing random() samples also uses apply_dpqr() with the argument ## n assured to be a positive integer. random.Gaussian <- function(x, n = 1L, drop = TRUE, ...) { n <- make_positive_integer(n) if (n == 0L) { return(numeric(0L)) } FUN <- function(at, d) rnorm(n = at, mean = d$mu, sd = d$sigma) apply_dpqr(d = x, FUN = FUN, at = n, type = "random", drop = drop) } ## One random sample for each distribution (returns vector): random(Y, 1) ## Several random samples for each distribution (returns matrix): random(Y, 3) ## For further analogous methods see the "Normal" distribution provided ## in distributions3. methods(class = "Normal")
Bernoulli distributions are used to represent events like coin flips
when there is single trial that is either successful or unsuccessful.
The Bernoulli distribution is a special case of the Binomial()
distribution with n = 1
.
Bernoulli(p = 0.5)
Bernoulli(p = 0.5)
p |
The success probability for the distribution. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a Bernoulli random variable with parameter
p
= . Some textbooks also define
, or use
instead of
.
The Bernoulli probability distribution is widely used to model
binary variables, such as 'failure' and 'success'. The most
typical example is the flip of a coin, when is thought as the
probability of flipping a head, and
is the
probability of flipping a tail.
Support:
Mean:
Variance:
Probability mass function (p.m.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
A Bernoulli
object.
Other discrete distributions:
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Create a Beta distribution
Beta(alpha = 1, beta = 1)
Beta(alpha = 1, beta = 1)
alpha |
The alpha parameter. |
beta |
The beta parameter. |
A beta
object.
Other continuous distributions:
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Binomial distributions are used to represent situations can that can
be thought as the result of Bernoulli experiments (here the
is defined as the
size
of the experiment). The classical
example is independent coin flips, where each coin flip has
probability
p
of success. In this case, the individual probability of
flipping heads or tails is given by the Bernoulli(p) distribution,
and the probability of having equal results (
heads,
for example), in
trials is given by the Binomial(n, p) distribution.
The equation of the Binomial distribution is directly derived from
the equation of the Bernoulli distribution.
Binomial(size, p = 0.5)
Binomial(size, p = 0.5)
size |
The number of trials. Must be an integer greater than or equal
to one. When |
p |
The success probability for a given trial. |
The Binomial distribution comes up when you are interested in the portion
of people who do a thing. The Binomial distribution
also comes up in the sign test, sometimes called the Binomial test
(see stats::binom.test()
), where you may need the Binomial C.D.F. to
compute p-values.
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a Binomial random variable with parameter
size
= and
p
= . Some textbooks define
,
or called
instead of
.
Support:
Mean:
Variance:
Probability mass function (p.m.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
A Binomial
object.
Other discrete distributions:
Bernoulli()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Create a Categorical distribution
Categorical(outcomes, p = NULL)
Categorical(outcomes, p = NULL)
outcomes |
A vector specifying the elements in the sample space. Can be numeric, factor, character, or logical. |
p |
A vector of success probabilities for each outcome.
Each element of |
A Categorical
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
Note that the Cauchy distribution is the student's t distribution with one degree of freedom. The Cauchy distribution does not have a well defined mean or variance. Cauchy distributions often appear as priors in Bayesian contexts due to their heavy tails.
Cauchy(location = 0, scale = 1)
Cauchy(location = 0, scale = 1)
location |
The location parameter. Can be any real number. Defaults
to |
scale |
The scale parameter. Must be greater than zero (?). Defaults
to |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Cauchy variable with mean
location =
and
scale
= .
Support: , the set of all real numbers
Mean: Undefined.
Variance: Undefined.
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
Does not exist.
A Cauchy
object.
Other continuous distributions:
Beta()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Generic function for computing probabilities from distribution objects based on the cumulative distribution function (CDF).
cdf(d, x, drop = TRUE, ...)
cdf(d, x, drop = TRUE, ...)
d |
An object. The package provides methods for distribution
objects such as those from |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
Probabilities corresponding to the vector x
.
## distribution object X <- Normal() ## probabilities from CDF cdf(X, c(1, 2, 3, 4, 5))
## distribution object X <- Normal() ## probabilities from CDF cdf(X, c(1, 2, 3, 4, 5))
Evaluate the cumulative distribution function of a Bernoulli distribution
## S3 method for class 'Bernoulli' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Bernoulli' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a Beta distribution
## S3 method for class 'Beta' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Beta' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a Binomial distribution
## S3 method for class 'Binomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Binomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of a Categorical distribution
## S3 method for class 'Categorical' cdf(d, x, ...)
## S3 method for class 'Categorical' cdf(d, x, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
A vector of probabilities, one for each element of x
.
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
Evaluate the cumulative distribution function of a Cauchy distribution
## S3 method for class 'Cauchy' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Cauchy' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of a chi square distribution
## S3 method for class 'ChiSquare' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ChiSquare' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of an Erlang distribution
## S3 method for class 'Erlang' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Erlang' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
An |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of an Exponential distribution
## S3 method for class 'Exponential' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Exponential' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
An |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of an F distribution
## S3 method for class 'FisherF' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'FisherF' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of a Frechet distribution
## S3 method for class 'Frechet' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Frechet' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a Gamma distribution
## S3 method for class 'Gamma' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Gamma' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of a Geometric distribution
## S3 method for class 'Geometric' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Geometric' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Geometric distribution:
pdf.Geometric()
,
quantile.Geometric()
,
random.Geometric()
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Evaluate the cumulative distribution function of a GEV distribution
## S3 method for class 'GEV' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'GEV' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a GP distribution
## S3 method for class 'GP' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'GP' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a Gumbel distribution
## S3 method for class 'Gumbel' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Gumbel' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a hurdle negative binomial distribution
## S3 method for class 'HurdleNegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HurdleNegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the cumulative distribution function of a hurdle Poisson distribution
## S3 method for class 'HurdlePoisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HurdlePoisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the cumulative distribution function of a HyperGeometric distribution
## S3 method for class 'HyperGeometric' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HyperGeometric' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other HyperGeometric distribution:
pdf.HyperGeometric()
,
quantile.HyperGeometric()
,
random.HyperGeometric()
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Evaluate the cumulative distribution function of a Logistic distribution
## S3 method for class 'Logistic' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Logistic' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Logistic distribution:
pdf.Logistic()
,
quantile.Logistic()
,
random.Logistic()
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Evaluate the cumulative distribution function of a LogNormal distribution
## S3 method for class 'LogNormal' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'LogNormal' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other LogNormal distribution:
fit_mle.LogNormal()
,
pdf.LogNormal()
,
quantile.LogNormal()
,
random.LogNormal()
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Evaluate the cumulative distribution function of a negative binomial distribution
## S3 method for class 'NegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'NegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other NegativeBinomial distribution:
pdf.NegativeBinomial()
,
quantile.NegativeBinomial()
,
random.NegativeBinomial()
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
Evaluate the cumulative distribution function of a Normal distribution
## S3 method for class 'Normal' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Normal' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Normal distribution:
fit_mle.Normal()
,
pdf.Normal()
,
quantile.Normal()
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of a Poisson distribution
## S3 method for class 'Poisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Poisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the cumulative distribution function of a PoissonBinomial distribution
## S3 method for class 'PoissonBinomial' cdf( d, x, drop = TRUE, elementwise = NULL, lower.tail = TRUE, log.p = FALSE, verbose = TRUE, ... )
## S3 method for class 'PoissonBinomial' cdf( d, x, drop = TRUE, elementwise = NULL, lower.tail = TRUE, log.p = FALSE, verbose = TRUE, ... )
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
lower.tail , log.p , ...
|
|
verbose |
logical. Should a warning be issued if the normal approximation is applied because the PoissonBinomial package is not installed? |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
Evaluate the cumulative distribution function of an RevWeibull distribution
## S3 method for class 'RevWeibull' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'RevWeibull' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a StudentsT distribution
## S3 method for class 'StudentsT' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'StudentsT' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other StudentsT distribution:
pdf.StudentsT()
,
quantile.StudentsT()
,
random.StudentsT()
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
Evaluate the cumulative distribution function of a Tukey distribution
## S3 method for class 'Tukey' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Tukey' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Tukey distribution:
quantile.Tukey()
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
Evaluate the cumulative distribution function of a continuous Uniform distribution
## S3 method for class 'Uniform' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Uniform' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the cumulative distribution function of a Weibull distribution
## S3 method for class 'Weibull' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Weibull' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Weibull distribution:
pdf.Weibull()
,
quantile.Weibull()
,
random.Weibull()
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Evaluate the cumulative distribution function of a zero-inflated negative binomial distribution
## S3 method for class 'ZINegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZINegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the cumulative distribution function of a zero-inflated Poisson distribution
## S3 method for class 'ZIPoisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZIPoisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the cumulative distribution function of a zero-truncated negative binomial distribution
## S3 method for class 'ZTNegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZTNegativeBinomial' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the cumulative distribution function of a zero-truncated Poisson distribution
## S3 method for class 'ZTPoisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZTPoisson' cdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Chi-square distributions show up often in frequentist settings as the sampling distribution of test statistics, especially in maximum likelihood estimation settings.
ChiSquare(df)
ChiSquare(df)
df |
Degrees of freedom. Must be positive. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a
random variable with
df
= .
Support: , the set of positive real numbers
Mean:
Variance:
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
The cumulative distribution function has the form
but this integral does not have a closed form solution and must be
approximated numerically. The c.d.f. of a standard normal is sometimes
called the "error function". The notation also stands
for the c.d.f. of a standard normal evaluated at
. Z-tables
list the value of
for various
.
Moment generating function (m.g.f):
A ChiSquare
object.
A squared standard Normal()
distribution is equivalent to a
distribution with one degree of freedom. The
distribution is a special case of the
Gamma()
distribution with shape (TODO: check this) parameter equal
to a half. Sums of distributions
are also distributed as
distributions, where the
degrees of freedom of the contributing distributions get summed.
The ratio of two
distributions is a
FisherF()
distribution. The ratio of a Normal()
and the square root
of a scaled ChiSquare()
is a StudentsT()
distribution.
Other continuous distributions:
Beta()
,
Cauchy()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Density, distribution function, quantile function, and random
generation for the zero-hurdle negative binomial distribution with
parameters mu
, theta
(or size
), and pi
.
dhnbinom(x, mu, theta, size, pi, log = FALSE) phnbinom(q, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) qhnbinom(p, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) rhnbinom(n, mu, theta, size, pi)
dhnbinom(x, mu, theta, size, pi, log = FALSE) phnbinom(q, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) qhnbinom(p, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) rhnbinom(n, mu, theta, size, pi)
x |
vector of (non-negative integer) quantiles. |
mu |
vector of (non-negative) negative binomial location parameters. |
theta , size
|
vector of (non-negative) negative binomial overdispersion parameters.
Only |
pi |
vector of zero-hurdle probabilities in the unit interval. |
log , log.p
|
logical indicating whether probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical indicating whether probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
All functions follow the usual conventions of d/p/q/r functions
in base R. In particular, all four hnbinom
functions for the
hurdle negative binomial distribution call the corresponding nbinom
functions for the negative binomial distribution from base R internally.
Note, however, that the precision of qhnbinom
for very large
probabilities (close to 1) is limited because the probabilities
are internally handled in levels and not in logs (even if log.p = TRUE
).
HurdleNegativeBinomial
, dnbinom
## theoretical probabilities for a hurdle negative binomial distribution x <- 0:8 p <- dhnbinom(x, mu = 2.5, theta = 1, pi = 0.75) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rhnbinom(500, mu = 2.5, theta = 1, pi = 0.75) hist(y, breaks = -1:max(y) + 0.5)
## theoretical probabilities for a hurdle negative binomial distribution x <- 0:8 p <- dhnbinom(x, mu = 2.5, theta = 1, pi = 0.75) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rhnbinom(500, mu = 2.5, theta = 1, pi = 0.75) hist(y, breaks = -1:max(y) + 0.5)
Density, distribution function, quantile function, and random
generation for the zero-hurdle Poisson distribution with
parameters lambda
and pi
.
dhpois(x, lambda, pi, log = FALSE) phpois(q, lambda, pi, lower.tail = TRUE, log.p = FALSE) qhpois(p, lambda, pi, lower.tail = TRUE, log.p = FALSE) rhpois(n, lambda, pi)
dhpois(x, lambda, pi, log = FALSE) phpois(q, lambda, pi, lower.tail = TRUE, log.p = FALSE) qhpois(p, lambda, pi, lower.tail = TRUE, log.p = FALSE) rhpois(n, lambda, pi)
x |
vector of (non-negative integer) quantiles. |
lambda |
vector of (non-negative) Poisson parameters. |
pi |
vector of zero-hurdle probabilities in the unit interval. |
log , log.p
|
logical indicating whether probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical indicating whether probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
All functions follow the usual conventions of d/p/q/r functions
in base R. In particular, all four hpois
functions for the
hurdle Poisson distribution call the corresponding pois
functions for the Poisson distribution from base R internally.
Note, however, that the precision of qhpois
for very large
probabilities (close to 1) is limited because the probabilities
are internally handled in levels and not in logs (even if log.p = TRUE
).
## theoretical probabilities for a hurdle Poisson distribution x <- 0:8 p <- dhpois(x, lambda = 2.5, pi = 0.75) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rhpois(500, lambda = 2.5, pi = 0.75) hist(y, breaks = -1:max(y) + 0.5)
## theoretical probabilities for a hurdle Poisson distribution x <- 0:8 p <- dhpois(x, lambda = 2.5, pi = 0.75) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rhpois(500, lambda = 2.5, pi = 0.75) hist(y, breaks = -1:max(y) + 0.5)
Density, distribution function, quantile function, and random
generation for the zero-inflated negative binomial distribution with
parameters mu
, theta
(or size
), and pi
.
dzinbinom(x, mu, theta, size, pi, log = FALSE) pzinbinom(q, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) qzinbinom(p, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) rzinbinom(n, mu, theta, size, pi)
dzinbinom(x, mu, theta, size, pi, log = FALSE) pzinbinom(q, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) qzinbinom(p, mu, theta, size, pi, lower.tail = TRUE, log.p = FALSE) rzinbinom(n, mu, theta, size, pi)
x |
vector of (non-negative integer) quantiles. |
mu |
vector of (non-negative) negative binomial location parameters. |
theta , size
|
vector of (non-negative) negative binomial overdispersion parameters.
Only |
pi |
vector of zero-inflation probabilities in the unit interval. |
log , log.p
|
logical indicating whether probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical indicating whether probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
All functions follow the usual conventions of d/p/q/r functions
in base R. In particular, all four zinbinom
functions for the
zero-inflated negative binomial distribution call the corresponding nbinom
functions for the negative binomial distribution from base R internally.
Note, however, that the precision of qzinbinom
for very large
probabilities (close to 1) is limited because the probabilities
are internally handled in levels and not in logs (even if log.p = TRUE
).
## theoretical probabilities for a zero-inflated negative binomial distribution x <- 0:8 p <- dzinbinom(x, mu = 2.5, theta = 1, pi = 0.25) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rzinbinom(500, mu = 2.5, theta = 1, pi = 0.25) hist(y, breaks = -1:max(y) + 0.5)
## theoretical probabilities for a zero-inflated negative binomial distribution x <- 0:8 p <- dzinbinom(x, mu = 2.5, theta = 1, pi = 0.25) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rzinbinom(500, mu = 2.5, theta = 1, pi = 0.25) hist(y, breaks = -1:max(y) + 0.5)
Density, distribution function, quantile function, and random
generation for the zero-inflated Poisson distribution with
parameters lambda
and pi
.
dzipois(x, lambda, pi, log = FALSE) pzipois(q, lambda, pi, lower.tail = TRUE, log.p = FALSE) qzipois(p, lambda, pi, lower.tail = TRUE, log.p = FALSE) rzipois(n, lambda, pi)
dzipois(x, lambda, pi, log = FALSE) pzipois(q, lambda, pi, lower.tail = TRUE, log.p = FALSE) qzipois(p, lambda, pi, lower.tail = TRUE, log.p = FALSE) rzipois(n, lambda, pi)
x |
vector of (non-negative integer) quantiles. |
lambda |
vector of (non-negative) Poisson parameters. |
pi |
vector of zero-inflation probabilities in the unit interval. |
log , log.p
|
logical indicating whether probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical indicating whether probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
All functions follow the usual conventions of d/p/q/r functions
in base R. In particular, all four zipois
functions for the
zero-inflated Poisson distribution call the corresponding pois
functions for the Poisson distribution from base R internally.
Note, however, that the precision of qzipois
for very large
probabilities (close to 1) is limited because the probabilities
are internally handled in levels and not in logs (even if log.p = TRUE
).
## theoretical probabilities for a zero-inflated Poisson distribution x <- 0:8 p <- dzipois(x, lambda = 2.5, pi = 0.25) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rzipois(500, lambda = 2.5, pi = 0.25) hist(y, breaks = -1:max(y) + 0.5)
## theoretical probabilities for a zero-inflated Poisson distribution x <- 0:8 p <- dzipois(x, lambda = 2.5, pi = 0.25) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rzipois(500, lambda = 2.5, pi = 0.25) hist(y, breaks = -1:max(y) + 0.5)
Density, distribution function, quantile function, and random
generation for the zero-truncated negative binomial distribution with
parameters mu
and theta
(or size
).
dztnbinom(x, mu, theta, size, log = FALSE) pztnbinom(q, mu, theta, size, lower.tail = TRUE, log.p = FALSE) qztnbinom(p, mu, theta, size, lower.tail = TRUE, log.p = FALSE) rztnbinom(n, mu, theta, size)
dztnbinom(x, mu, theta, size, log = FALSE) pztnbinom(q, mu, theta, size, lower.tail = TRUE, log.p = FALSE) qztnbinom(p, mu, theta, size, lower.tail = TRUE, log.p = FALSE) rztnbinom(n, mu, theta, size)
x |
vector of (non-negative integer) quantiles. |
mu |
vector of (non-negative) negative binomial location parameters. |
theta , size
|
vector of (non-negative) negative binomial overdispersion parameters.
Only |
log , log.p
|
logical indicating whether probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical indicating whether probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
The negative binomial distribution left-truncated at zero (or zero-truncated negative binomial for short) is the distribution obtained, when considering a negative binomial variable Y conditional on Y being greater than zero.
All functions follow the usual conventions of d/p/q/r functions
in base R. In particular, all four ztnbinom
functions for the
zero-truncated negative binomial distribution call the corresponding nbinom
functions for the negative binomial distribution from base R internally.
## theoretical probabilities for a zero-truncated negative binomial distribution x <- 0:8 p <- dztnbinom(x, mu = 2.5, theta = 1) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rztnbinom(500, mu = 2.5, theta = 1) hist(y, breaks = -1:max(y) + 0.5)
## theoretical probabilities for a zero-truncated negative binomial distribution x <- 0:8 p <- dztnbinom(x, mu = 2.5, theta = 1) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rztnbinom(500, mu = 2.5, theta = 1) hist(y, breaks = -1:max(y) + 0.5)
Density, distribution function, quantile function, and random
generation for the zero-truncated Poisson distribution with
parameter lambda
.
dztpois(x, lambda, log = FALSE) pztpois(q, lambda, lower.tail = TRUE, log.p = FALSE) qztpois(p, lambda, lower.tail = TRUE, log.p = FALSE) rztpois(n, lambda)
dztpois(x, lambda, log = FALSE) pztpois(q, lambda, lower.tail = TRUE, log.p = FALSE) qztpois(p, lambda, lower.tail = TRUE, log.p = FALSE) rztpois(n, lambda)
x |
vector of (non-negative integer) quantiles. |
lambda |
vector of (non-negative) Poisson parameters. |
log , log.p
|
logical indicating whether probabilities p are given as log(p). |
q |
vector of quantiles. |
lower.tail |
logical indicating whether probabilities are |
p |
vector of probabilities. |
n |
number of random values to return. |
The Poisson distribution left-truncated at zero (or zero-truncated Poisson for short) is the distribution obtained, when considering a Poisson variable Y conditional on Y being greater than zero.
All functions follow the usual conventions of d/p/q/r functions
in base R. In particular, all four ztpois
functions for the
zero-truncated Poisson distribution call the corresponding pois
functions for the Poisson distribution from base R internally.
## theoretical probabilities for a zero-truncated Poisson distribution x <- 0:8 p <- dztpois(x, lambda = 2.5) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rztpois(500, lambda = 2.5) hist(y, breaks = -1:max(y) + 0.5)
## theoretical probabilities for a zero-truncated Poisson distribution x <- 0:8 p <- dztpois(x, lambda = 2.5) plot(x, p, type = "h", lwd = 2) ## corresponding empirical frequencies from a simulated sample set.seed(0) y <- rztpois(500, lambda = 2.5) hist(y, breaks = -1:max(y) + 0.5)
The Erlang distribution is a two-parameter family of continuous probability
distributions with support .
The two parameters are a positive integer shape parameter
and a
positive real rate parameter
.
The Erlang distribution with shape parameter
simplifies to the
exponential distribution, and it is a special case of the gamma distribution.
It corresponds to a sum of
independent exponential variables with mean
each.
Erlang(k, lambda)
Erlang(k, lambda)
k |
The shape parameter. Can be any positive integer number. |
lambda |
The rate parameter. Can be any positive number. |
An Erlang
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Exponential distributions are frequently used for modeling the amount of time that passes until a specific event occurs. For example, exponential distributions could be used to model the time between two earthquakes, the amount of delay between internet packets, or the amount of time a piece of machinery can run before needing repair.
Exponential(rate = 1)
Exponential(rate = 1)
rate |
The rate parameter, written |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be an Exponential random variable with
rate parameter
rate
= .
Support:
Mean:
Variance:
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
An Exponential
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Data from all 64 matches in the 2018 FIFA World Cup along with predicted ability differences based on bookmakers odds.
data("FIFA2018", package = "distributions3")
data("FIFA2018", package = "distributions3")
A data frame with 128 rows and 7 columns.
integer. Number of goals scored in normal time (90 minutes), \ i.e., excluding potential extra time or penalties in knockout matches.
character. 3-letter FIFA code for the team.
integer. Match ID ranging from 1 (opening match) to 64 (final).
factor. Type of match for groups A to H, round of 16 (R16), quarter final, semi-final, match for 3rd place, and final.
factor. Group vs. knockout tournament stage.
numeric. Estimated log-ability for each team based on bookmaker consensus model.
numeric. Difference in estimated log-abilities between a team and its opponent in each match.
To investigate the number of goals scored per match in the 2018 FIFA World Cup,
FIFA2018
provides two rows, one for each team, for each of the matches
during the tournament. In addition some basic meta-information for the matches
(an ID, team name abbreviations, type of match, group vs. knockout stage),
information on the estimated log-ability for each team is provided. These
have been estimated by Zeileis et al. (2018) prior to the start of the
tournament (2018-05-20) based on quoted odds from 26 online bookmakers using
the bookmaker consensus model of Leitner et al. (2010). The difference in
log-ability between a team and its opponent is a useful predictor for the
number of goals scored.
To model the data a basic Poisson regression model provides a good fit. This treats the number of goals by the two teams as independent given the ability difference which is a reasonable assumption in this data set.
The goals for each match have been obtained from Wikipedia (https://en.wikipedia.org/wiki/2018_FIFA_World_Cup) and the log-abilities from Zeileis et al. (2018) based on quoted odds from Oddschecker.com and Bwin.com.
Leitner C, Zeileis A, Hornik K (2010). Forecasting Sports Tournaments by Ratings of (Prob)abilities: A Comparison for the EURO 2008. International Journal of Forecasting, 26(3), 471-481. doi:10.1016/j.ijforecast.2009.10.001
Zeileis A, Leitner C, Hornik K (2018). Probabilistic Forecasts for the 2018 FIFA World Cup Based on the Bookmaker Consensus Model. Working Paper 2018-09, Working Papers in Economics and Statistics, Research Platform Empirical and Experimental Economics, University of Innsbruck. https://EconPapers.RePEc.org/RePEc:inn:wpaper:2018-09
## load data data("FIFA2018", package = "distributions3") ## observed relative frequencies of goals in all matches obsrvd <- prop.table(table(FIFA2018$goals)) ## expected probabilities assuming a simple Poisson model, ## using the average number of goals across all teams/matches ## as the point estimate for the mean (lambda) of the distribution p_const <- Poisson(lambda = mean(FIFA2018$goals)) p_const expctd <- pdf(p_const, 0:6) ## comparison: observed vs. expected frequencies ## frequencies for 3 and 4 goals are slightly overfitted ## while 5 and 6 goals are slightly underfitted cbind("observed" = obsrvd, "expected" = expctd) ## instead of fitting the same average Poisson model to all ## teams/matches, take ability differences into account m <- glm(goals ~ difference, data = FIFA2018, family = poisson) summary(m) ## when the ratio of abilities increases by 1 percent, the ## expected number of goals increases by around 0.4 percent ## this yields a different predicted Poisson distribution for ## each team/match p_reg <- Poisson(lambda = fitted(m)) head(p_reg) ## as an illustration, the following goal distributions ## were expected for the final (that France won 4-2 against Croatia) p_final <- tail(p_reg, 2) p_final pdf(p_final, 0:6) ## clearly France was expected to score more goals than Croatia ## but both teams scored more goals than expected, albeit not unlikely many ## assuming independence of the number of goals scored, obtain ## table of possible match results (after normal time), along with ## overall probabilities of win/draw/lose res <- outer(pdf(p_final[1], 0:6), pdf(p_final[2], 0:6)) sum(res[lower.tri(res)]) ## France wins sum(diag(res)) ## draw sum(res[upper.tri(res)]) ## France loses ## update expected frequencies table based on regression model expctd <- pdf(p_reg, 0:6) head(expctd) expctd <- colMeans(expctd) cbind("observed" = obsrvd, "expected" = expctd)
## load data data("FIFA2018", package = "distributions3") ## observed relative frequencies of goals in all matches obsrvd <- prop.table(table(FIFA2018$goals)) ## expected probabilities assuming a simple Poisson model, ## using the average number of goals across all teams/matches ## as the point estimate for the mean (lambda) of the distribution p_const <- Poisson(lambda = mean(FIFA2018$goals)) p_const expctd <- pdf(p_const, 0:6) ## comparison: observed vs. expected frequencies ## frequencies for 3 and 4 goals are slightly overfitted ## while 5 and 6 goals are slightly underfitted cbind("observed" = obsrvd, "expected" = expctd) ## instead of fitting the same average Poisson model to all ## teams/matches, take ability differences into account m <- glm(goals ~ difference, data = FIFA2018, family = poisson) summary(m) ## when the ratio of abilities increases by 1 percent, the ## expected number of goals increases by around 0.4 percent ## this yields a different predicted Poisson distribution for ## each team/match p_reg <- Poisson(lambda = fitted(m)) head(p_reg) ## as an illustration, the following goal distributions ## were expected for the final (that France won 4-2 against Croatia) p_final <- tail(p_reg, 2) p_final pdf(p_final, 0:6) ## clearly France was expected to score more goals than Croatia ## but both teams scored more goals than expected, albeit not unlikely many ## assuming independence of the number of goals scored, obtain ## table of possible match results (after normal time), along with ## overall probabilities of win/draw/lose res <- outer(pdf(p_final[1], 0:6), pdf(p_final[2], 0:6)) sum(res[lower.tri(res)]) ## France wins sum(diag(res)) ## draw sum(res[upper.tri(res)]) ## France loses ## update expected frequencies table based on regression model expctd <- pdf(p_reg, 0:6) head(expctd) expctd <- colMeans(expctd) cbind("observed" = obsrvd, "expected" = expctd)
Create an F distribution
FisherF(df1, df2, lambda = 0)
FisherF(df1, df2, lambda = 0)
df1 |
Numerator degrees of freedom. Can be any positive number. |
df2 |
Denominator degrees of freedom. Can be any positive number. |
lambda |
Non-centrality parameter. Can be any positive number.
Defaults to |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
TODO
A FisherF
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Generic function for fitting maximum-likelihood estimates (MLEs) of a distribution based on empirical data.
fit_mle(d, x, ...)
fit_mle(d, x, ...)
d |
An object. The package provides methods for distribution
objects such as those from |
x |
A vector of data to compute the likelihood. |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
A distribution (the same kind as d
) where the parameters
are the MLE estimates based on x
.
X <- Normal() fit_mle(X, c(-1, 0, 0, 0, 3))
X <- Normal() fit_mle(X, c(-1, 0, 0, 0, 3))
Fit a Bernoulli distribution to data
## S3 method for class 'Bernoulli' fit_mle(d, x, ...)
## S3 method for class 'Bernoulli' fit_mle(d, x, ...)
d |
A |
x |
A vector of zeroes and ones. |
... |
Unused. |
a Bernoulli
object
The fit distribution will inherit the same size
parameter as
the Binomial
object passed.
## S3 method for class 'Binomial' fit_mle(d, x, ...)
## S3 method for class 'Binomial' fit_mle(d, x, ...)
d |
A |
x |
A vector of zeroes and ones. |
... |
Unused. |
a Binomial
object
Fit an Exponential distribution to data
## S3 method for class 'Exponential' fit_mle(d, x, ...)
## S3 method for class 'Exponential' fit_mle(d, x, ...)
d |
An |
x |
A vector of data. |
... |
Unused. |
An Exponential
object.
Fit a Gamma distribution to data
## S3 method for class 'Gamma' fit_mle(d, x, ...)
## S3 method for class 'Gamma' fit_mle(d, x, ...)
d |
A |
x |
A vector to fit the Gamma distribution to. |
... |
Unused. |
a Gamma
object
Fit a Geometric distribution to data
## S3 method for class 'Geometric' fit_mle(d, x, ...)
## S3 method for class 'Geometric' fit_mle(d, x, ...)
d |
A |
x |
A vector of zeroes and ones. |
... |
Unused. |
a Geometric
object
Fit a Log Normal distribution to data
## S3 method for class 'LogNormal' fit_mle(d, x, ...)
## S3 method for class 'LogNormal' fit_mle(d, x, ...)
d |
A |
x |
A vector of data. |
... |
Unused. |
A LogNormal
object.
Other LogNormal distribution:
cdf.LogNormal()
,
pdf.LogNormal()
,
quantile.LogNormal()
,
random.LogNormal()
Fit a Normal distribution to data
## S3 method for class 'Normal' fit_mle(d, x, ...)
## S3 method for class 'Normal' fit_mle(d, x, ...)
d |
A |
x |
A vector of data. |
... |
Unused. |
A Normal
object.
Other Normal distribution:
cdf.Normal()
,
pdf.Normal()
,
quantile.Normal()
Fit an Poisson distribution to data
## S3 method for class 'Poisson' fit_mle(d, x, ...)
## S3 method for class 'Poisson' fit_mle(d, x, ...)
d |
An |
x |
A vector of data. |
... |
Unused. |
An Poisson
object.
The Frechet distribution is a special case of the \link{GEV}
distribution,
obtained when the GEV shape parameter is positive.
It may be referred to as a type II extreme value distribution.
Frechet(location = 0, scale = 1, shape = 1)
Frechet(location = 0, scale = 1, shape = 1)
location |
The location (minimum) parameter |
scale |
The scale parameter |
shape |
The shape parameter |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Frechet random variable with location
parameter
location
= , scale parameter
scale
=
, and shape parameter
shape
= .
A Frechet(
) distribution is equivalent to a
\link{GEV}
() distribution.
Support: .
Mean: , for
; undefined
otherwise.
Median: .
Variance:
for
; undefined otherwise.
Probability density function (p.d.f):
for . The p.d.f. is 0 for
.
Cumulative distribution function (c.d.f):
for . The c.d.f. is 0 for
.
A Frechet
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Several important distributions are special cases of the Gamma
distribution. When the shape parameter is 1
, the Gamma is an
exponential distribution with parameter . When the
and
, the Gamma is a equivalent to
a chi squared distribution with n degrees of freedom. Moreover, if
we have
is
and
is
, a function of these two variables
of the form
.
This last property frequently appears in another distributions, and it
has extensively been used in multivariate methods. More about the Gamma
distribution will be added soon.
Gamma(shape, rate = 1)
Gamma(shape, rate = 1)
shape |
The shape parameter. Can be any positive number. |
rate |
The rate parameter. Can be any positive number. Defaults
to |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a Gamma random variable
with parameters
shape
= and
rate
= .
Support:
Mean:
Variance:
Probability density function (p.m.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
A Gamma
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
The Geometric distribution can be thought of as a generalization
of the Bernoulli()
distribution where we ask: "if I keep flipping a
coin with probability p
of heads, what is the probability I need
flips before I get my first heads?" The Geometric
distribution is a special case of Negative Binomial distribution.
Geometric(p = 0.5)
Geometric(p = 0.5)
p |
The success probability for the distribution. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Geometric random variable with
success probability
p
= . Note that there are multiple
parameterizations of the Geometric distribution.
Support: 0 < p < 1,
Mean:
Variance:
Probability mass function (p.m.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
A Geometric
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
The GEV distribution arises from the Extremal Types Theorem, which is rather
like the Central Limit Theorem (see \link{Normal}
) but it relates to
the maximum of i.i.d. random variables rather than to the sum.
If, after a suitable linear rescaling, the distribution of this maximum
tends to a non-degenerate limit as
tends to infinity then this limit
must be a GEV distribution. The requirement that the variables are independent
can be relaxed substantially. Therefore, the GEV distribution is often used
to model the maximum of a large number of random variables.
GEV(mu = 0, sigma = 1, xi = 0)
GEV(mu = 0, sigma = 1, xi = 0)
mu |
The location parameter, written |
sigma |
The scale parameter, written |
xi |
The shape parameter, written |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a GEV random variable with location
parameter
mu
= , scale parameter
sigma
= and
shape parameter
xi
= .
Support:
for
;
for
;
and
, the set of all real numbers, for
.
Mean: for
;
for
, where
is Euler's constant, approximately equal to 0.57722; undefined otherwise.
Median: for
;
for
.
Variance:
for
;
for
; undefined otherwise.
Probability density function (p.d.f):
If then
for . The p.d.f. is 0 outside the
support.
In the (Gumbel) special case
for in
, the set of all real numbers.
Cumulative distribution function (c.d.f):
If then
for . The c.d.f. is 0 below the
support and 1 above the support.
In the (Gumbel) special case
for in
, the set of all real numbers.
A GEV
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
The GP distribution has a link to the \link{GEV}
distribution.
Suppose that the maximum of i.i.d. random variables has
approximately a GEV distribution. For a sufficiently large threshold
, the conditional distribution of the amount (the threshold
excess) by which a variable exceeds
given that it exceeds
has approximately a GP distribution. Therefore, the GP distribution is
often used to model the threshold excesses of a high threshold
.
The requirement that the variables are independent can be relaxed
substantially, but then exceedances of
may cluster.
GP(mu = 0, sigma = 1, xi = 0)
GP(mu = 0, sigma = 1, xi = 0)
mu |
The location parameter, written |
sigma |
The scale parameter, written |
xi |
The shape parameter, written |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a GP random variable with location
parameter
mu
= , scale parameter
sigma
= and
shape parameter
xi
= .
Support:
for
;
for
.
Mean: for
; undefined otherwise.
Median: for
;
for
.
Variance:
for
; undefined otherwise.
Probability density function (p.d.f):
If then
for . The p.d.f. is 0 outside the
support.
In the special case
for in [
). The p.d.f. is 0 outside the support.
Cumulative distribution function (c.d.f):
If then
for . The c.d.f. is 0 below the
support and 1 above the support.
In the special case
for in
, the set of all real numbers.
A GP
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
The Gumbel distribution is a special case of the \link{GEV}
distribution,
obtained when the GEV shape parameter is equal to 0.
It may be referred to as a type I extreme value distribution.
Gumbel(mu = 0, sigma = 1)
Gumbel(mu = 0, sigma = 1)
mu |
The location parameter, written |
sigma |
The scale parameter, written |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Gumbel random variable with location
parameter
mu
= , scale parameter
sigma
= .
Support: , the set of all real numbers.
Mean: , where
is Euler's
constant, approximately equal to 0.57722.
Median: .
Variance: .
Probability density function (p.d.f):
for in
, the set of all real numbers.
Cumulative distribution function (c.d.f):
In the (Gumbel) special case
for in
, the set of all real numbers.
A Gumbel
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Hurdle negative binomial distributions are frequently used to model counts with overdispersion and many zero observations.
HurdleNegativeBinomial(mu, theta, pi)
HurdleNegativeBinomial(mu, theta, pi)
mu |
Location parameter of the negative binomial component of the distribution. Can be any positive number. |
theta |
Overdispersion parameter of the negative binomial component of the distribution. Can be any positive number. |
pi |
Zero-hurdle probability, can be any value in |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a hurdle negative binomial random variable with parameters
mu
= and
theta
= .
Support:
Mean:
where is the c.d.f. of the
NegativeBinomial
distribution.
Variance:
where is the mean above.
Probability mass function (p.m.f.): and for
where is the p.m.f. of the
NegativeBinomial
distribution.
Cumulative distribution function (c.d.f.): and for
Moment generating function (m.g.f.):
Omitted for now.
A HurdleNegativeBinomial
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Hurdle Poisson distributions are frequently used to model counts with many zero observations.
HurdlePoisson(lambda, pi)
HurdlePoisson(lambda, pi)
lambda |
Parameter of the Poisson component of the distribution. Can be any positive number. |
pi |
Zero-hurdle probability, can be any value in |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a hurdle Poisson random variable with parameter
lambda
= .
Support:
Mean:
Variance: , where
is the mean above.
Probability mass function (p.m.f.): and for
where is the p.m.f. of the
Poisson
distribution.
Cumulative distribution function (c.d.f.): and for
where is the c.d.f. of the
Poisson
distribution.
Moment generating function (m.g.f.):
Omitted for now.
A HurdlePoisson
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
To understand the HyperGeometric distribution, consider a set of
objects, of which
are of the type I and
are of the type II. A sample with size
(
)
with no replacement is randomly chosen. The number of observed
type I elements observed in this sample is set to be our random
variable
. For example, consider that in a set of 20
car parts, there are 4 that are defective (type I).
If we take a sample of size 5 from those car parts, the
probability of finding 2 that are defective will be given by
the HyperGeometric distribution (needs double checking).
HyperGeometric(m, n, k)
HyperGeometric(m, n, k)
m |
The number of type I elements available. |
n |
The number of type II elements available. |
k |
The size of the sample taken. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a HyperGeometric random variable with
success probability
p
= .
Support:
Mean:
Variance:
Probability mass function (p.m.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
Not useful.
A HyperGeometric
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Generic functions for determining whether a certain probability distribution is discrete or continuous, respectively.
is_discrete(d, ...) is_continuous(d, ...)
is_discrete(d, ...) is_continuous(d, ...)
d |
An object. The package provides methods for distribution
objects such as those from |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
The generic function is_discrete
is intended to return TRUE
for every distribution whose entire support is discrete and FALSE
otherwise. Analogously, is_continuous
is intended to return TRUE
for every distribution whose entire support is continuous and FALSE
otherwise. For mixed discrete-continuous distributions both methods should
return FALSE
.
Methods for both generics are provided for all distribution
classes
set up in this package.
A logical vector indicating whether the distribution(s) in d
is/are discrete or continuous, respectively.
X <- Normal() is_discrete(X) is_continuous(X) Y <- Binomial(size = 10, p = c(0.2, 0.5, 0.8)) is_discrete(Y) is_continuous(Y)
X <- Normal() is_discrete(X) is_continuous(X) Y <- Binomial(size = 10, p = c(0.2, 0.5, 0.8)) is_discrete(Y) is_continuous(Y)
is_distribution
tests if x
inherits from "distribution"
.
is_distribution(x)
is_distribution(x)
x |
An object to test. |
Z <- Normal() is_distribution(Z) is_distribution(1L)
Z <- Normal() is_distribution(Z) is_distribution(1L)
Functions for computing the (log-)likelihood based on a distribution object and observed data. The log-likelihood is computed as the sum of log-density contributions and the likelihood by taking the exponential thereof.
log_likelihood(d, x, ...) likelihood(d, x, ...)
log_likelihood(d, x, ...) likelihood(d, x, ...)
d |
An object. The package provides methods for distribution
objects such as those from |
x |
A vector of data to compute the likelihood. |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
Numeric value of the (log-)likelihood.
## distribution object X <- Normal() ## sum of log_pdf() contributions log_likelihood(X, c(-1, 0, 0, 0, 3)) ## exp of log_likelihood() likelihood(X, c(-1, 0, 0, 0, 3))
## distribution object X <- Normal() ## sum of log_pdf() contributions log_likelihood(X, c(-1, 0, 0, 0, 3)) ## exp of log_likelihood() likelihood(X, c(-1, 0, 0, 0, 3))
A continuous distribution on the real line. For binary outcomes
the model given by where
is the Logistic
cdf()
is called logistic regression.
Logistic(location = 0, scale = 1)
Logistic(location = 0, scale = 1)
location |
The location parameter for the distribution. For Logistic distributions, the location parameter is the mean, median and also mode. Defaults to zero. |
scale |
The scale parameter for the distribution. Defaults to one. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Logistic random variable with
location
= and
scale
= .
Support: , the set of all real numbers
Mean:
Variance:
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
where is the Beta function.
A Logistic
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
A random variable created by exponentiating a Normal()
distribution. Taking the log of LogNormal data returns in
Normal()
data.
LogNormal(log_mu = 0, log_sigma = 1)
LogNormal(log_mu = 0, log_sigma = 1)
log_mu |
The location parameter, written |
log_sigma |
The scale parameter, written |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a LogNormal random variable with
success probability
p
= .
Support:
Mean:
Variance:
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f): Undefined.
A LogNormal
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
The multinomial distribution is a generalization of the binomial
distribution to multiple categories. It is perhaps easiest to think
that we first extend a Bernoulli()
distribution to include more
than two categories, resulting in a Categorical()
distribution.
We then extend repeat the Categorical experiment several ()
times.
Multinomial(size, p)
Multinomial(size, p)
size |
The number of trials. Must be an integer greater than or equal
to one. When |
p |
A vector of success probabilities for each trial. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Multinomial
random variable with success probability
p
= . Note that
is vector with
elements that sum to one. Assume
that we repeat the Categorical experiment
size
= times.
Support: Each is in
.
Mean: The mean of is
.
Variance: The variance of is
.
For
, the covariance of
and
is
.
Probability mass function (p.m.f):
Cumulative distribution function (c.d.f):
Omitted for multivariate random variables for the time being.
Moment generating function (m.g.f):
A Multinomial
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- Multinomial(size = 5, p = c(0.3, 0.4, 0.2, 0.1)) X random(X, 10) # pdf(X, 2) # log_pdf(X, 2)
set.seed(27) X <- Multinomial(size = 5, p = c(0.3, 0.4, 0.2, 0.1)) X random(X, 10) # pdf(X, 2) # log_pdf(X, 2)
A generalization of the geometric distribution. It is the number
of failures in a sequence of i.i.d. Bernoulli trials before
a specified target number () of successes occurs.
NegativeBinomial(size, p = 0.5, mu = size)
NegativeBinomial(size, p = 0.5, mu = size)
size |
The target number of successes (greater than |
p |
The success probability for a given trial. |
mu |
Alternative parameterization via the non-negative mean
of the distribution (instead of the probability |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a negative binomial random variable with
success probability
p
= .
Support:
Mean:
Variance:
Probability mass function (p.m.f.):
Cumulative distribution function (c.d.f.):
Omitted for now.
Moment generating function (m.g.f.):
Alternative parameterization: Sometimes, especially when used in
regression models, the negative binomial distribution is parameterized
by its mean (as listed above) plus the size parameter
.
This implies a success probability of
. This can
also be seen as a generalization of the Poisson distribution where the
assumption of equidispersion (i.e., variance equal to mean) is relaxed.
The negative binomial distribution is overdispersed (i.e., variance greater than mean)
and its variance can also be written as
. The Poisson
distribution is then obtained as
goes to infinity. Note that in this
view it is natural to also allow for non-integer
parameters.
The factorials in the equations above are then expressed in terms of the
gamma function.
A NegativeBinomial
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
The Normal distribution is ubiquitous in statistics, partially because of the central limit theorem, which states that sums of i.i.d. random variables eventually become Normal. Linear transformations of Normal random variables result in new random variables that are also Normal. If you are taking an intro stats course, you'll likely use the Normal distribution for Z-tests and in simple linear regression. Under regularity conditions, maximum likelihood estimators are asymptotically Normal. The Normal distribution is also called the gaussian distribution.
Normal(mu = 0, sigma = 1)
Normal(mu = 0, sigma = 1)
mu |
The location parameter, written |
sigma |
The scale parameter, written |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Normal random variable with mean
mu
= and standard deviation
sigma
= .
Support: , the set of all real numbers
Mean:
Variance:
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
The cumulative distribution function has the form
but this integral does not have a closed form solution and must be
approximated numerically. The c.d.f. of a standard Normal is sometimes
called the "error function". The notation also stands
for the c.d.f. of a standard Normal evaluated at
. Z-tables
list the value of
for various
.
Moment generating function (m.g.f):
A Normal
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Generic function for computing probability density function (PDF) contributions based on a distribution object and observed data.
pdf(d, x, drop = TRUE, ...) log_pdf(d, x, ...) pmf(d, x, ...)
pdf(d, x, drop = TRUE, ...) log_pdf(d, x, ...) pmf(d, x, ...)
d |
An object. The package provides methods for distribution
objects such as those from |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
The generic function pdf()
computes the probability density,
both for continuous and discrete distributions. pmf()
(for the
probability mass function) is an alias that just calls pdf()
internally.
For computing log-density contributions (e.g., to a log-likelihood)
either pdf(..., log = TRUE)
can be used or the generic function
log_pdf()
.
Probabilities corresponding to the vector x
.
## distribution object X <- Normal() ## probability density pdf(X, c(1, 2, 3, 4, 5)) pmf(X, c(1, 2, 3, 4, 5)) ## log-density pdf(X, c(1, 2, 3, 4, 5), log = TRUE) log_pdf(X, c(1, 2, 3, 4, 5))
## distribution object X <- Normal() ## probability density pdf(X, c(1, 2, 3, 4, 5)) pmf(X, c(1, 2, 3, 4, 5)) ## log-density pdf(X, c(1, 2, 3, 4, 5), log = TRUE) log_pdf(X, c(1, 2, 3, 4, 5))
Evaluate the probability mass function of a Bernoulli distribution
## S3 method for class 'Bernoulli' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Bernoulli' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Bernoulli' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Bernoulli' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the probability mass function of a Beta distribution
## S3 method for class 'Beta' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Beta' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Beta' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Beta' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the probability mass function of a Binomial distribution
## S3 method for class 'Binomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Binomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Binomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Binomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability mass function of a Categorical discrete distribution
## S3 method for class 'Categorical' pdf(d, x, ...) ## S3 method for class 'Categorical' log_pdf(d, x, ...)
## S3 method for class 'Categorical' pdf(d, x, ...) ## S3 method for class 'Categorical' log_pdf(d, x, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
A vector of probabilities, one for each element of x
.
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
Evaluate the probability mass function of a Cauchy distribution
## S3 method for class 'Cauchy' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Cauchy' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Cauchy' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Cauchy' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability mass function of a chi square distribution
## S3 method for class 'ChiSquare' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ChiSquare' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ChiSquare' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ChiSquare' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability mass function of an Erlang distribution
## S3 method for class 'Erlang' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Erlang' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Erlang' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Erlang' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
An |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability density function of an Exponential distribution
## S3 method for class 'Exponential' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Exponential' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Exponential' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Exponential' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
An |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability mass function of an F distribution
## S3 method for class 'FisherF' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'FisherF' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'FisherF' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'FisherF' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability mass function of a Frechet distribution
## S3 method for class 'Frechet' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Frechet' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Frechet' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Frechet' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the probability mass function of a Gamma distribution
## S3 method for class 'Gamma' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Gamma' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Gamma' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Gamma' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Please see the documentation of Geometric()
for some properties
of the Geometric distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'Geometric' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Geometric' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Geometric' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Geometric' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Geometric distribution:
cdf.Geometric()
,
quantile.Geometric()
,
random.Geometric()
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Evaluate the probability mass function of a GEV distribution
## S3 method for class 'GEV' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'GEV' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'GEV' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'GEV' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the probability mass function of a GP distribution
## S3 method for class 'GP' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'GP' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'GP' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'GP' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the probability mass function of a Gumbel distribution
## S3 method for class 'Gumbel' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Gumbel' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Gumbel' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Gumbel' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Evaluate the probability mass function of a hurdle negative binomial distribution
## S3 method for class 'HurdleNegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'HurdleNegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HurdleNegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'HurdleNegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the probability mass function of a hurdle Poisson distribution
## S3 method for class 'HurdlePoisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'HurdlePoisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HurdlePoisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'HurdlePoisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Please see the documentation of HyperGeometric()
for some properties
of the HyperGeometric distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'HyperGeometric' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'HyperGeometric' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HyperGeometric' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'HyperGeometric' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other HyperGeometric distribution:
cdf.HyperGeometric()
,
quantile.HyperGeometric()
,
random.HyperGeometric()
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Please see the documentation of Logistic()
for some properties
of the Logistic distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'Logistic' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Logistic' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Logistic' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Logistic' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Logistic distribution:
cdf.Logistic()
,
quantile.Logistic()
,
random.Logistic()
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Please see the documentation of LogNormal()
for some properties
of the LogNormal distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'LogNormal' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'LogNormal' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'LogNormal' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'LogNormal' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other LogNormal distribution:
cdf.LogNormal()
,
fit_mle.LogNormal()
,
quantile.LogNormal()
,
random.LogNormal()
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Please see the documentation of Multinomial()
for some properties
of the Multinomial distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'Multinomial' pdf(d, x, ...) ## S3 method for class 'Multinomial' log_pdf(d, x, ...)
## S3 method for class 'Multinomial' pdf(d, x, ...) ## S3 method for class 'Multinomial' log_pdf(d, x, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
A vector of probabilities, one for each element of x
.
Other Multinomial distribution:
random.Multinomial()
set.seed(27) X <- Multinomial(size = 5, p = c(0.3, 0.4, 0.2, 0.1)) X random(X, 10) # pdf(X, 2) # log_pdf(X, 2)
set.seed(27) X <- Multinomial(size = 5, p = c(0.3, 0.4, 0.2, 0.1)) X random(X, 10) # pdf(X, 2) # log_pdf(X, 2)
Evaluate the probability mass function of a NegativeBinomial distribution
## S3 method for class 'NegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'NegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'NegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'NegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other NegativeBinomial distribution:
cdf.NegativeBinomial()
,
quantile.NegativeBinomial()
,
random.NegativeBinomial()
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
Please see the documentation of Normal()
for some properties
of the Normal distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'Normal' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Normal' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Normal' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Normal' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Normal distribution:
cdf.Normal()
,
fit_mle.Normal()
,
quantile.Normal()
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability mass function of a Poisson distribution
## S3 method for class 'Poisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Poisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Poisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Poisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Evaluate the probability mass function of a PoissonBinomial distribution
## S3 method for class 'PoissonBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, log = FALSE, verbose = TRUE, ...) ## S3 method for class 'PoissonBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'PoissonBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, log = FALSE, verbose = TRUE, ...) ## S3 method for class 'PoissonBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
log , ...
|
|
verbose |
logical. Should a warning be issued if the normal approximation is applied because the PoissonBinomial package is not installed? |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
Evaluate the probability mass function of an RevWeibull distribution
## S3 method for class 'RevWeibull' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'RevWeibull' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'RevWeibull' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'RevWeibull' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Please see the documentation of StudentsT()
for some properties
of the StudentsT distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'StudentsT' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'StudentsT' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'StudentsT' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'StudentsT' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other StudentsT distribution:
cdf.StudentsT()
,
quantile.StudentsT()
,
random.StudentsT()
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
Evaluate the probability mass function of a continuous Uniform distribution
## S3 method for class 'Uniform' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Uniform' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Uniform' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Uniform' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Please see the documentation of Weibull()
for some properties
of the Weibull distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'Weibull' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Weibull' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Weibull' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'Weibull' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
Other Weibull distribution:
cdf.Weibull()
,
quantile.Weibull()
,
random.Weibull()
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Evaluate the probability mass function of a zero-inflated negative binomial distribution
## S3 method for class 'ZINegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZINegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZINegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZINegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the probability mass function of a zero-inflated Poisson distribution
## S3 method for class 'ZIPoisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZIPoisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZIPoisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZIPoisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the probability mass function of a zero-truncated negative binomial distribution
## S3 method for class 'ZTNegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZTNegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZTNegativeBinomial' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZTNegativeBinomial' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Evaluate the probability mass function of a zero-truncated Poisson distribution
## S3 method for class 'ZTPoisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZTPoisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZTPoisson' pdf(d, x, drop = TRUE, elementwise = NULL, ...) ## S3 method for class 'ZTPoisson' log_pdf(d, x, drop = TRUE, elementwise = NULL, ...)
d |
A |
x |
A vector of elements whose probabilities you would like to
determine given the distribution |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(x)
columns (if drop = FALSE
). In case of a vectorized distribution
object, a matrix with length(x)
columns containing all possible combinations.
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
A function to easily plot the CDF of a distribution using ggplot2
. Requires ggplot2
to be loaded.
plot_cdf(d, limits = NULL, p = 0.001, plot_theme = NULL)
plot_cdf(d, limits = NULL, p = 0.001, plot_theme = NULL)
d |
A |
limits |
either |
p |
If |
plot_theme |
specify theme of resulting plot using |
N1 <- Normal() plot_cdf(N1) N2 <- Normal(0, c(1, 2)) plot_cdf(N2) B1 <- Binomial(10, 0.2) plot_cdf(B1) B2 <- Binomial(10, c(0.2, 0.5)) plot_cdf(B2)
N1 <- Normal() plot_cdf(N1) N2 <- Normal(0, c(1, 2)) plot_cdf(N2) B1 <- Binomial(10, 0.2) plot_cdf(B1) B2 <- Binomial(10, c(0.2, 0.5)) plot_cdf(B2)
A function to easily plot the PDF of a distribution using ggplot2
. Requires ggplot2
to be loaded.
plot_pdf(d, limits = NULL, p = 0.001, plot_theme = NULL)
plot_pdf(d, limits = NULL, p = 0.001, plot_theme = NULL)
d |
A |
limits |
either |
p |
If |
plot_theme |
specify theme of resulting plot using |
N1 <- Normal() plot_pdf(N1) N2 <- Normal(0, c(1, 2)) plot_pdf(N2) B1 <- Binomial(10, 0.2) plot_pdf(B1) B2 <- Binomial(10, c(0.2, 0.5)) plot_pdf(B2)
N1 <- Normal() plot_pdf(N1) N2 <- Normal(0, c(1, 2)) plot_pdf(N2) B1 <- Binomial(10, 0.2) plot_pdf(B1) B2 <- Binomial(10, c(0.2, 0.5)) plot_pdf(B2)
Plot method for an object inheriting from class "distribution"
.
By default the probability density function (p.d.f.), for a continuous
variable, or the probability mass function (p.m.f.), for a discrete
variable, is plotted. The cumulative distribution function (c.d.f.)
will be plotted if cdf = TRUE
. Multiple functions are included
in the plot if any of the parameter vectors in x
has length greater
than 1. See the argument all
.
## S3 method for class 'distribution' plot( x, cdf = FALSE, p = c(0.1, 99.9), len = 1000, all = FALSE, legend_args = list(), ... )
## S3 method for class 'distribution' plot( x, cdf = FALSE, p = c(0.1, 99.9), len = 1000, all = FALSE, legend_args = list(), ... )
x |
an object of class |
cdf |
A logical scalar. If |
p |
A numeric vector. If |
len |
An integer scalar. If |
all |
A logical scalar. If |
legend_args |
A list of arguments to be passed to
|
... |
Further arguments to be passed to |
If xlim
is passed in ...
then this determines the
range of values of the variable to be plotted on the horizontal axis.
If x
is a discrete distribution object then the values for which
the p.m.f. or c.d.f. is plotted is the smallest set of consecutive
integers that contains both components of xlim
. Otherwise,
xlim
is used directly.
If xlim
is not passed in ...
then the range of values spans
the support of the distribution, with the following proviso: if the
lower (upper) endpoint of the distribution is -Inf
(Inf
)
then the lower (upper) limit of the plotting range is set to the
p[1]
\
If the name of x
is a single upper case letter then that name is
used to labels the axes of the plot. Otherwise, x
and
P(X = x)
or f(x)
are used.
A legend is included only if at least one of the parameter vectors in
x
has length greater than 1.
Plots of c.d.f.s are produced using calls to
approxfun
and plot.ecdf
.
An object with the same class as x
, in which the parameter
vectors have been expanded to contain a parameter combination for each
function plotted.
B <- Binomial(20, 0.7) plot(B) plot(B, cdf = TRUE) B2 <- Binomial(20, c(0.1, 0.5, 0.9)) plot(B2, legend_args = list(x = "top")) x <- plot(B2, cdf = TRUE) x$size x$p X <- Poisson(2) plot(X) plot(X, cdf = TRUE) G <- Gamma(c(1, 3), 1:2) plot(G) plot(G, all = TRUE) plot(G, cdf = TRUE) C <- Cauchy() plot(C, p = c(1, 99), len = 10000) plot(C, cdf = TRUE, p = c(1, 99))
B <- Binomial(20, 0.7) plot(B) plot(B, cdf = TRUE) B2 <- Binomial(20, c(0.1, 0.5, 0.9)) plot(B2, legend_args = list(x = "top")) x <- plot(B2, cdf = TRUE) x$size x$p X <- Poisson(2) plot(X) plot(X, cdf = TRUE) G <- Gamma(c(1, 3), 1:2) plot(G) plot(G, all = TRUE) plot(G, cdf = TRUE) C <- Cauchy() plot(C, p = c(1, 99), len = 10000) plot(C, cdf = TRUE, p = c(1, 99))
Poisson distributions are frequently used to model counts.
Poisson(lambda)
Poisson(lambda)
lambda |
The shape parameter, which is also the mean and the variance of the distribution. Can be any positive number. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a Poisson random variable with parameter
lambda
= .
Support:
Mean:
Variance:
Probability mass function (p.m.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
A Poisson
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
The Poisson binomial distribution is a generalization of the
Binomial
distribution. It is also a sum
of independent Bernoulli experiments. However, the success
probabilities can vary between the experiments so that they are
not identically distributed.
PoissonBinomial(...)
PoissonBinomial(...)
... |
An arbitrary number of numeric vectors or matrices
of success probabilities in |
The Poisson binomial distribution comes up when you consider the number of successes in independent binomial experiments (coin flips) with potentially varying success probabilities.
The PoissonBinomial
distribution class in distributions3
is mostly based on the PoissonBinomial package, providing fast
Rcpp implementations of efficient algorithms. Hence, it is
recommended to install the PoissonBinomial package when working
with this distribution. However, as a fallback for when the PoissonBinomial
package is not installed the methods for the PoissonBinomial
distribution employ a normal approximation.
We recommend reading the following documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a Poisson binomial random variable with
success probabilities
to
.
Support:
Mean:
Variance:
Probability mass function (p.m.f):
where the sum is taken over all sets with
elements from
.
is the complement
of
.
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
A PoissonBinomial
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
Generic function with methods for various model classes for extracting
fitted (in-sample) or predicted (out-of-sample) probability distributions3
objects.
prodist(object, ...) ## S3 method for class 'lm' prodist(object, ..., sigma = "ML") ## S3 method for class 'glm' prodist(object, ..., dispersion = NULL) ## S3 method for class 'distribution' prodist(object, ...)
prodist(object, ...) ## S3 method for class 'lm' prodist(object, ..., sigma = "ML") ## S3 method for class 'glm' prodist(object, ..., dispersion = NULL) ## S3 method for class 'distribution' prodist(object, ...)
object |
A model object. |
... |
Arguments passed on to methods, typically for calling the
underlying |
sigma |
character or numeric or |
dispersion |
character or numeric or |
To facilitate making probabilistic forecasts based on regression and time
series model objects, the function prodist
extracts fitted or
predicted probability distribution
objects. Currently, methods are
provided for objects fitted by lm
,
glm
, and arima
in base R as
well as glm.nb
from the MASS package and
hurdle
/zeroinfl
/zerotrunc
from the pscl or
countreg packages.
All methods essentially
proceed in two steps: First, the standard predict
method for these model objects is used to compute fitted (in-sample, default)
or predicted (out-of-sample) distribution parameters. Typically, this includes
the mean plus further parameters describing scale, dispersion, shape, etc.).
Second, the distributions
objects are set up using the generator
functions from distributions3.
Note that these probability distributions only reflect the random variation in the dependent variable based on the model employed (and its associated distributional assumpation for the dependent variable). This does not capture the uncertainty in the parameter estimates.
For both linear regression models and generalized linear models, estimated
by lm
and glm
respectively, there is some ambiguity as to which
estimate for the dispersion parameter of the model is to be used. While the
logLik
methods use the maximum-likelihood (ML) estimate
implicitly, the summary
methods report an estimate that is standardized
with the residual degrees of freedom, n - k (rather than the number of
observations, n). The prodist
methods for these objects follow
the logLik
method by default but the summary
behavior can be
mimicked by setting the sigma
or dispersion
arguments
accordingly.
An object inheriting from distribution
.
## Model: Linear regression ## Fit: lm ## Data: 1920s cars data data("cars", package = "datasets") ## Stopping distance (ft) explained by speed (mph) reg <- lm(dist ~ speed, data = cars) ## Extract fitted normal distributions (in-sample, with constant variance) pd <- prodist(reg) head(pd) ## Extract log-likelihood from model object logLik(reg) ## Replicate log-likelihood via distributions object sum(log_pdf(pd, cars$dist)) log_likelihood(pd, cars$dist) ## Compute corresponding medians and 90% interval qd <- quantile(pd, c(0.05, 0.5, 0.95)) head(qd) ## Visualize observations with predicted quantiles plot(dist ~ speed, data = cars) matplot(cars$speed, qd, add = TRUE, type = "l", col = 2, lty = 1) ## Sigma estimated by maximum-likelihood estimate (default, used in logLik) ## vs. least-squares estimate (used in summary) nd <- data.frame(speed = 50) prodist(reg, newdata = nd, sigma = "ML") prodist(reg, newdata = nd, sigma = "OLS") summary(reg)$sigma ## Model: Poisson generalized linear model ## Fit: glm ## Data: FIFA 2018 World Cup data data("FIFA2018", package = "distributions3") ## Number of goals per team explained by ability differences poisreg <- glm(goals ~ difference, data = FIFA2018, family = poisson) summary(poisreg) ## Interpretation: When the ratio of abilities increases by 1 percent, ## the expected number of goals increases by around 0.4 percent ## Predict fitted Poisson distributions for teams with equal ability (out-of-sample) nd <- data.frame(difference = 0) prodist(poisreg, newdata = nd) ## Extract fitted Poisson distributions (in-sample) pd <- prodist(poisreg) head(pd) ## Extract log-likelihood from model object logLik(poisreg) ## Replicate log-likelihood via distributions object sum(log_pdf(pd, FIFA2018$goals)) log_likelihood(pd, FIFA2018$goals) ## Model: Autoregressive integrated moving average model ## Fit: arima ## Data: Quarterly approval ratings of U.S. presidents (1945-1974) data("presidents", package = "datasets") ## ARMA(2,1) model arma21 <- arima(presidents, order = c(2, 0, 1)) ## Extract predicted normal distributions for next two years p <- prodist(arma21, n.ahead = 8) p ## Compute median (= mean) forecast along with 80% and 95% interval quantile(p, c(0.5, 0.1, 0.9, 0.025, 0.975))
## Model: Linear regression ## Fit: lm ## Data: 1920s cars data data("cars", package = "datasets") ## Stopping distance (ft) explained by speed (mph) reg <- lm(dist ~ speed, data = cars) ## Extract fitted normal distributions (in-sample, with constant variance) pd <- prodist(reg) head(pd) ## Extract log-likelihood from model object logLik(reg) ## Replicate log-likelihood via distributions object sum(log_pdf(pd, cars$dist)) log_likelihood(pd, cars$dist) ## Compute corresponding medians and 90% interval qd <- quantile(pd, c(0.05, 0.5, 0.95)) head(qd) ## Visualize observations with predicted quantiles plot(dist ~ speed, data = cars) matplot(cars$speed, qd, add = TRUE, type = "l", col = 2, lty = 1) ## Sigma estimated by maximum-likelihood estimate (default, used in logLik) ## vs. least-squares estimate (used in summary) nd <- data.frame(speed = 50) prodist(reg, newdata = nd, sigma = "ML") prodist(reg, newdata = nd, sigma = "OLS") summary(reg)$sigma ## Model: Poisson generalized linear model ## Fit: glm ## Data: FIFA 2018 World Cup data data("FIFA2018", package = "distributions3") ## Number of goals per team explained by ability differences poisreg <- glm(goals ~ difference, data = FIFA2018, family = poisson) summary(poisreg) ## Interpretation: When the ratio of abilities increases by 1 percent, ## the expected number of goals increases by around 0.4 percent ## Predict fitted Poisson distributions for teams with equal ability (out-of-sample) nd <- data.frame(difference = 0) prodist(poisreg, newdata = nd) ## Extract fitted Poisson distributions (in-sample) pd <- prodist(poisreg) head(pd) ## Extract log-likelihood from model object logLik(poisreg) ## Replicate log-likelihood via distributions object sum(log_pdf(pd, FIFA2018$goals)) log_likelihood(pd, FIFA2018$goals) ## Model: Autoregressive integrated moving average model ## Fit: arima ## Data: Quarterly approval ratings of U.S. presidents (1945-1974) data("presidents", package = "datasets") ## ARMA(2,1) model arma21 <- arima(presidents, order = c(2, 0, 1)) ## Extract predicted normal distributions for next two years p <- prodist(arma21, n.ahead = 8) p ## Compute median (= mean) forecast along with 80% and 95% interval quantile(p, c(0.5, 0.1, 0.9, 0.025, 0.975))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Bernoulli' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Bernoulli' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Beta' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Beta' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Binomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Binomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Shoul the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Categorical' quantile(x, probs, ...)
## S3 method for class 'Categorical' quantile(x, probs, ...)
x |
A |
probs |
A vector of probabilities. |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
A vector of quantiles, one for each element of probs
.
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
quantile()
is the inverse of cdf()
.
## S3 method for class 'Cauchy' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Cauchy' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'ChiSquare' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ChiSquare' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Erlang' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Erlang' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
An |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Exponential' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Exponential' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
An |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'FisherF' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'FisherF' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Frechet' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Frechet' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Gamma' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Gamma' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Determine quantiles of a Geometric distribution
## S3 method for class 'Geometric' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Geometric' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other Geometric distribution:
cdf.Geometric()
,
pdf.Geometric()
,
random.Geometric()
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
quantile()
is the inverse of cdf()
.
## S3 method for class 'GEV' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'GEV' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'GP' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'GP' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Gumbel' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Gumbel' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'HurdleNegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HurdleNegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
quantile()
is the inverse of cdf()
.
## S3 method for class 'HurdlePoisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HurdlePoisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Determine quantiles of a HyperGeometric distribution
## S3 method for class 'HyperGeometric' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'HyperGeometric' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other HyperGeometric distribution:
cdf.HyperGeometric()
,
pdf.HyperGeometric()
,
random.HyperGeometric()
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Determine quantiles of a Logistic distribution
## S3 method for class 'Logistic' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Logistic' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other Logistic distribution:
cdf.Logistic()
,
pdf.Logistic()
,
random.Logistic()
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Determine quantiles of a LogNormal distribution
## S3 method for class 'LogNormal' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'LogNormal' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other LogNormal distribution:
cdf.LogNormal()
,
fit_mle.LogNormal()
,
pdf.LogNormal()
,
random.LogNormal()
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Determine quantiles of a NegativeBinomial distribution
## S3 method for class 'NegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'NegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other NegativeBinomial distribution:
cdf.NegativeBinomial()
,
pdf.NegativeBinomial()
,
random.NegativeBinomial()
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
Please see the documentation of Normal()
for some properties
of the Normal distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
quantile()
## S3 method for class 'Normal' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Normal' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
This function returns the same values that you get from a Z-table. Note
quantile()
is the inverse of cdf()
. Please see the documentation of Normal()
for some properties
of the Normal distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other Normal distribution:
cdf.Normal()
,
fit_mle.Normal()
,
pdf.Normal()
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'Poisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Poisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
quantile()
is the inverse of cdf()
.
## S3 method for class 'PoissonBinomial' quantile( x, probs, drop = TRUE, elementwise = NULL, lower.tail = TRUE, log.p = FALSE, verbose = TRUE, ... )
## S3 method for class 'PoissonBinomial' quantile( x, probs, drop = TRUE, elementwise = NULL, lower.tail = TRUE, log.p = FALSE, verbose = TRUE, ... )
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Shoul the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
lower.tail , log.p , ...
|
|
verbose |
logical. Should a warning be issued if the normal approximation is applied because the PoissonBinomial package is not installed? |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
quantile()
is the inverse of cdf()
.
## S3 method for class 'RevWeibull' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'RevWeibull' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Please see the documentation of StudentsT()
for some properties
of the StudentsT distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
quantile()
## S3 method for class 'StudentsT' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'StudentsT' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
This function returns the same values that you get from a Z-table. Note
quantile()
is the inverse of cdf()
. Please see the documentation of
StudentsT()
for some properties
of the StudentsT distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other StudentsT distribution:
cdf.StudentsT()
,
pdf.StudentsT()
,
random.StudentsT()
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
Determine quantiles of a Tukey distribution
## S3 method for class 'Tukey' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Tukey' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A vector of elements whose cumulative probabilities you would
like to determine given the distribution |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other Tukey distribution:
cdf.Tukey()
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
quantile()
is the inverse of cdf()
.
## S3 method for class 'Uniform' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Uniform' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Determine quantiles of a Weibull distribution
## S3 method for class 'Weibull' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'Weibull' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
Other Weibull distribution:
cdf.Weibull()
,
pdf.Weibull()
,
random.Weibull()
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
quantile()
is the inverse of cdf()
.
## S3 method for class 'ZINegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZINegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
quantile()
is the inverse of cdf()
.
## S3 method for class 'ZIPoisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZIPoisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
quantile()
is the inverse of cdf()
.
## S3 method for class 'ZTNegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZTNegativeBinomial' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
quantile()
is the inverse of cdf()
.
## S3 method for class 'ZTPoisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
## S3 method for class 'ZTPoisson' quantile(x, probs, drop = TRUE, elementwise = NULL, ...)
x |
A |
probs |
A vector of probabilities. |
drop |
logical. Should the result be simplified to a vector if possible? |
elementwise |
logical. Should each distribution in |
... |
Arguments to be passed to |
In case of a single distribution object, either a numeric
vector of length probs
(if drop = TRUE
, default) or a matrix
with
length(probs)
columns (if drop = FALSE
). In case of a vectorized
distribution object, a matrix with length(probs)
columns containing all
possible combinations.
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Generic function for drawing random samples from distribution objects.
random(x, n = 1L, drop = TRUE, ...) ## S3 method for class 'distribution' simulate(object, nsim = 1L, seed = NULL, ...)
random(x, n = 1L, drop = TRUE, ...) ## S3 method for class 'distribution' simulate(object, nsim = 1L, seed = NULL, ...)
x , object
|
An object. The package provides methods for distribution
objects such as those from |
n , nsim
|
The number of samples to draw. Should be a positive
integer. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
seed |
An optional random seed that is to be set using |
random
is a new generic for drawing random samples from
the S3 distribution
objects provided in this package, such as
Normal
or Binomial
etc. The respective
methods typically call the "r" function for the corresponding
distribution functions provided in base R such as rnorm
,
rbinom
etc.
In addition to the new random
generic there is also a
simulate
method for distribution objects which simply
calls the random
method internally.
Random samples drawn from the distriubtion x
. The random
methods typically return either a matrix or, if possible, a vector. The
simulate
method always returns a data frame (with an attribute
"seed"
containing the .Random.seed
from before the simulation).
## distribution object X <- Normal() ## 10 random samples random(X, 10)
## distribution object X <- Normal() ## 10 random samples random(X, 10)
Draw a random sample from a Bernoulli distribution
## S3 method for class 'Bernoulli' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Bernoulli' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Bernoulli(0.7) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 0) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Draw a random sample from a Beta distribution
## S3 method for class 'Beta' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Beta' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
Values in [0, 1]
. In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Beta(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) mean(X) variance(X) skewness(X) kurtosis(X) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Draw a random sample from a Binomial distribution
## S3 method for class 'Binomial' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Binomial' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
Integers containing values between 0
and x$size
.
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Binomial(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2L) log_pdf(X, 2L) cdf(X, 4L) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from a Categorical distribution
## S3 method for class 'Categorical' random(x, n = 1L, ...)
## S3 method for class 'Categorical' random(x, n = 1L, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
A vector containing values from outcomes
of length n
.
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
set.seed(27) X <- Categorical(1:3, p = c(0.4, 0.1, 0.5)) X Y <- Categorical(LETTERS[1:4]) Y random(X, 10) random(Y, 10) pdf(X, 1) log_pdf(X, 1) cdf(X, 1) quantile(X, 0.5) # cdfs are only defined for numeric sample spaces. this errors! # cdf(Y, "a") # same for quantiles. this also errors! # quantile(Y, 0.7)
Draw a random sample from a Cauchy distribution
## S3 method for class 'Cauchy' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Cauchy' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Cauchy(10, 0.2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from a chi square distribution
## S3 method for class 'ChiSquare' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'ChiSquare' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- ChiSquare(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from an Erlang distribution
## S3 method for class 'Erlang' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Erlang' random(x, n = 1L, drop = TRUE, ...)
x |
An |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Erlang(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from an Exponential distribution
## S3 method for class 'Exponential' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Exponential' random(x, n = 1L, drop = TRUE, ...)
x |
An |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Exponential(5) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from an F distribution
## S3 method for class 'FisherF' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'FisherF' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- FisherF(5, 10, 0.2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from a Frechet distribution
## S3 method for class 'Frechet' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Frechet' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Frechet(0, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Draw a random sample from a Gamma distribution
## S3 method for class 'Gamma' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Gamma' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Gamma(5, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Please see the documentation of Geometric()
for some properties
of the Geometric distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'Geometric' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Geometric' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
Other Geometric distribution:
cdf.Geometric()
,
pdf.Geometric()
,
quantile.Geometric()
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Geometric(0.3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Draw a random sample from a GEV distribution
## S3 method for class 'GEV' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'GEV' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GEV(1, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Draw a random sample from a GP distribution
## S3 method for class 'GP' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'GP' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- GP(0, 2, 0.1) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Draw a random sample from a Gumbel distribution
## S3 method for class 'Gumbel' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Gumbel' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Gumbel(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Draw a random sample from a hurdle negative binomial distribution
## S3 method for class 'HurdleNegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'HurdleNegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle negative binomial distribution X <- HurdleNegativeBinomial(mu = 2.5, theta = 1, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Draw a random sample from a hurdle Poisson distribution
## S3 method for class 'HurdlePoisson' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'HurdlePoisson' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a hurdle Poisson distribution X <- HurdlePoisson(lambda = 2.5, pi = 0.75) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Please see the documentation of HyperGeometric()
for some properties
of the HyperGeometric distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'HyperGeometric' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'HyperGeometric' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
Other HyperGeometric distribution:
cdf.HyperGeometric()
,
pdf.HyperGeometric()
,
quantile.HyperGeometric()
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- HyperGeometric(4, 5, 8) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Draw a random sample from a Logistic distribution
## S3 method for class 'Logistic' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Logistic' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
Other Logistic distribution:
cdf.Logistic()
,
pdf.Logistic()
,
quantile.Logistic()
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Logistic(2, 4) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Draw a random sample from a LogNormal distribution
## S3 method for class 'LogNormal' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'LogNormal' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
Other LogNormal distribution:
cdf.LogNormal()
,
fit_mle.LogNormal()
,
pdf.LogNormal()
,
quantile.LogNormal()
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- LogNormal(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Draw a random sample from a Multinomial distribution
## S3 method for class 'Multinomial' random(x, n = 1L, ...)
## S3 method for class 'Multinomial' random(x, n = 1L, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
An integer vector of length n
.
Other Multinomial distribution:
pdf.Multinomial()
set.seed(27) X <- Multinomial(size = 5, p = c(0.3, 0.4, 0.2, 0.1)) X random(X, 10) # pdf(X, 2) # log_pdf(X, 2)
set.seed(27) X <- Multinomial(size = 5, p = c(0.3, 0.4, 0.2, 0.1)) X random(X, 10) # pdf(X, 2) # log_pdf(X, 2)
Draw a random sample from a negative binomial distribution
## S3 method for class 'NegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'NegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
Other NegativeBinomial distribution:
cdf.NegativeBinomial()
,
pdf.NegativeBinomial()
,
quantile.NegativeBinomial()
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
set.seed(27) X <- NegativeBinomial(size = 5, p = 0.1) X random(X, 10) pdf(X, 50) log_pdf(X, 50) cdf(X, 50) quantile(X, 0.7) ## alternative parameterization of X Y <- NegativeBinomial(mu = 45, size = 5) Y cdf(Y, 50) quantile(Y, 0.7)
Please see the documentation of Normal()
for some properties
of the Normal distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'Normal' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Normal' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Normal(5, 2) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided Z-test # here the null hypothesis is H_0: mu = 3 # and we assume sigma = 2 # exactly the same as: Z <- Normal(0, 1) Z <- Normal() # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the z-statistic z_stat <- (mean(x) - 3) / (2 / sqrt(nx)) z_stat # calculate the two-sided p-value 1 - cdf(Z, abs(z_stat)) + cdf(Z, -abs(z_stat)) # exactly equivalent to the above 2 * cdf(Z, -abs(z_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(Z, z_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(Z, z_stat) ### example: calculating a 88 percent Z CI for a mean # same `x` as before, still assume `sigma = 2` # lower-bound mean(x) - quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # upper-bound mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) # also equivalent to mean(x) + quantile(Z, 0.12 / 2) * 2 / sqrt(nx) mean(x) + quantile(Z, 1 - 0.12 / 2) * 2 / sqrt(nx) ### generating random samples and plugging in ks.test() set.seed(27) # generate a random sample ns <- random(Normal(3, 7), 26) # test if sample is Normal(3, 7) ks.test(ns, pnorm, mean = 3, sd = 7) # test if sample is gamma(8, 3) using base R pgamma() ks.test(ns, pgamma, shape = 8, rate = 3) ### MISC # note that the cdf() and quantile() functions are inverses cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from a Poisson distribution
## S3 method for class 'Poisson' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Poisson' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
set.seed(27) X <- Poisson(2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 7))
Draw a random sample from a PoissonBinomial distribution
## S3 method for class 'PoissonBinomial' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'PoissonBinomial' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
Integers containing values between 0
and x$size
.
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
set.seed(27) X <- PoissonBinomial(0.5, 0.3, 0.8) X mean(X) variance(X) skewness(X) kurtosis(X) random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 2) quantile(X, 0.8) cdf(X, quantile(X, 0.8)) quantile(X, cdf(X, 2)) ## equivalent definitions of four Poisson binomial distributions ## each summing up three Bernoulli probabilities p <- cbind( p1 = c(0.1, 0.2, 0.1, 0.2), p2 = c(0.5, 0.5, 0.5, 0.5), p3 = c(0.8, 0.7, 0.9, 0.8)) PoissonBinomial(p) PoissonBinomial(p[, 1], p[, 2], p[, 3]) PoissonBinomial(p[, 1:2], p[, 3])
Draw a random sample from an RevWeibull distribution
## S3 method for class 'RevWeibull' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'RevWeibull' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Please see the documentation of StudentsT()
for some properties
of the T distribution, as well as extensive examples
showing to how calculate p-values and confidence intervals.
## S3 method for class 'StudentsT' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'StudentsT' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
Other StudentsT distribution:
cdf.StudentsT()
,
pdf.StudentsT()
,
quantile.StudentsT()
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
Draw a random sample from a Tukey distribution
## S3 method for class 'Tukey' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Tukey' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
Draw a random sample from a continuous Uniform distribution
## S3 method for class 'Uniform' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Uniform' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
Values in [a, b]
. In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Draw a random sample from a Weibull distribution
## S3 method for class 'Weibull' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'Weibull' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
Other Weibull distribution:
cdf.Weibull()
,
pdf.Weibull()
,
quantile.Weibull()
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Draw a random sample from a zero-inflated negative binomial distribution
## S3 method for class 'ZINegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'ZINegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Draw a random sample from a zero-inflated Poisson distribution
## S3 method for class 'ZIPoisson' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'ZIPoisson' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Draw a random sample from a zero-truncated negative binomial distribution
## S3 method for class 'ZTNegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'ZTNegativeBinomial' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Draw a random sample from a zero-truncated Poisson distribution
## S3 method for class 'ZTPoisson' random(x, n = 1L, drop = TRUE, ...)
## S3 method for class 'ZTPoisson' random(x, n = 1L, drop = TRUE, ...)
x |
A |
n |
The number of samples to draw. Defaults to |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Unused. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
In case of a single distribution object or n = 1
, either a numeric
vector of length n
(if drop = TRUE
, default) or a matrix
with n
columns
(if drop = FALSE
).
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
The reversed (or negated) Weibull distribution is a special case of the
\link{GEV}
distribution, obtained when the GEV shape parameter
is negative. It may be referred to as a type III extreme value
distribution.
RevWeibull(location = 0, scale = 1, shape = 1)
RevWeibull(location = 0, scale = 1, shape = 1)
location |
The location (maximum) parameter |
scale |
The scale parameter |
shape |
The scale parameter |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a reversed Weibull random variable with
location parameter
location
= , scale parameter
scale
=
, and shape parameter
shape
= .
An RevWeibull(
) distribution is equivalent to a
\link{GEV}
() distribution.
If has an RevWeibull(
) distribution then
has a
\link{Weibull}
() distribution,
that is, a Weibull distribution with shape parameter
and scale
parameter
.
Support: .
Mean: .
Median: .
Variance:
.
Probability density function (p.d.f):
for . The p.d.f. is 0 for
.
Cumulative distribution function (c.d.f):
for . The c.d.f. is 1 for
.
A RevWeibull
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
StudentsT()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- RevWeibull(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Default method for simulating new responses from any model object
with a prodist
method (for extracting a
probability distribution object).
## Default S3 method: simulate(object, nsim = 1, seed = NULL, ...)
## Default S3 method: simulate(object, nsim = 1, seed = NULL, ...)
object |
An object for which a |
nsim |
The number of response vectors to simulate. Should be a positive integer. Defaults to 1. |
seed |
An optional random seed that is to be set using |
... |
Arguments passed to |
This default method simply combines two building blocks provided in this
package: (1) prodist
for extracting the probability
distribution from a fitted model object, (2) simulate.distribution
for simulating new observations from this distribution (internally calling
random
).
Thus, this enables simulation from any fitted model object that provides a
prodist
method. It waives the need to implement a dedicated
simulate
method for this model class.
A data frame with an attribute "seed"
containing the
.Random.seed
from before the simulation.
## Poisson GLM for FIFA 2018 goals data("FIFA2018", package = "distributions3") m <- glm(goals ~ difference, data = FIFA2018, family = poisson) ## simulate new goals via glm method set.seed(0) g_glm <- simulate(m, n = 3) ## alternatively use the new default method set.seed(0) g_default <- simulate.default(m, n = 3) ## same results all.equal(g_glm, g_default, check.attributes = FALSE)
## Poisson GLM for FIFA 2018 goals data("FIFA2018", package = "distributions3") m <- glm(goals ~ difference, data = FIFA2018, family = poisson) ## simulate new goals via glm method set.seed(0) g_glm <- simulate(m, n = 3) ## alternatively use the new default method set.seed(0) g_default <- simulate.default(m, n = 3) ## same results all.equal(g_glm, g_default, check.attributes = FALSE)
Fill out area under the curve for a plotted PDF
stat_auc( mapping = NULL, data = NULL, geom = "auc", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, from = -Inf, to = Inf, annotate = FALSE, digits = 3, ... ) geom_auc( mapping = NULL, data = NULL, stat = "auc", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, from = -Inf, to = Inf, annotate = FALSE, digits = 3, ... )
stat_auc( mapping = NULL, data = NULL, geom = "auc", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, from = -Inf, to = Inf, annotate = FALSE, digits = 3, ... ) geom_auc( mapping = NULL, data = NULL, stat = "auc", position = "identity", na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, from = -Inf, to = Inf, annotate = FALSE, digits = 3, ... )
mapping |
Set of aesthetic mappings created by |
data |
The data to be displayed in this layer. There are three options: If A A |
geom |
The geometric object to use to display the data for this layer.
When using a
|
position |
A position adjustment to use on the data for this layer. This
can be used in various ways, including to prevent overplotting and
improving the display. The
|
na.rm |
If |
show.legend |
logical. Should this layer be included in the legends?
|
inherit.aes |
If |
from |
Left end-point of interval |
to |
Right end-point of interval |
annotate |
Should P() be added in the upper left corner as an annotation? Works also with a colour character, e.g., "red". |
digits |
Number of digits shown in annotation |
... |
Other arguments passed on to
|
stat |
The statistical transformation to use on the data for this layer.
When using a
|
N1 <- Normal() plot_pdf(N1) + geom_auc(to = -0.645) plot_pdf(N1) + geom_auc(from = -0.645, to = 0.1, annotate = TRUE) N2 <- Normal(0, c(1, 2)) plot_pdf(N2) + geom_auc(to = 0) plot_pdf(N2) + geom_auc(from = -2, to = 2, annotate = TRUE)
N1 <- Normal() plot_pdf(N1) + geom_auc(to = -0.645) plot_pdf(N1) + geom_auc(from = -0.645, to = 0.1, annotate = TRUE) N2 <- Normal(0, c(1, 2)) plot_pdf(N2) + geom_auc(to = 0) plot_pdf(N2) + geom_auc(from = -2, to = 2, annotate = TRUE)
The Student's T distribution is closely related to the Normal()
distribution, but has heavier tails. As increases to
,
the Student's T converges to a Normal. The T distribution appears
repeatedly throughout classic frequentist hypothesis testing when
comparing group means.
StudentsT(df)
StudentsT(df)
df |
Degrees of freedom. Can be any positive number. Often
called |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Students T random variable with
df
= .
Support: , the set of all real numbers
Mean: Undefined unless , in which case the mean is
zero.
Variance:
Undefined if , infinite when
.
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
Nasty, omitted.
Moment generating function (m.g.f):
Undefined.
A StudentsT
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
Tukey()
,
Uniform()
,
Weibull()
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
set.seed(27) X <- StudentsT(3) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7) ### example: calculating p-values for two-sided T-test # here the null hypothesis is H_0: mu = 3 # data to test x <- c(3, 7, 11, 0, 7, 0, 4, 5, 6, 2) nx <- length(x) # calculate the T-statistic t_stat <- (mean(x) - 3) / (sd(x) / sqrt(nx)) t_stat # null distribution of statistic depends on sample size! T <- StudentsT(df = nx - 1) # calculate the two-sided p-value 1 - cdf(T, abs(t_stat)) + cdf(T, -abs(t_stat)) # exactly equivalent to the above 2 * cdf(T, -abs(t_stat)) # p-value for one-sided test # H_0: mu <= 3 vs H_A: mu > 3 1 - cdf(T, t_stat) # p-value for one-sided test # H_0: mu >= 3 vs H_A: mu < 3 cdf(T, t_stat) ### example: calculating a 88 percent T CI for a mean # lower-bound mean(x) - quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # upper-bound mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # equivalent to mean(x) + c(-1, 1) * quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx) # also equivalent to mean(x) + quantile(T, 0.12 / 2) * sd(x) / sqrt(nx) mean(x) + quantile(T, 1 - 0.12 / 2) * sd(x) / sqrt(nx)
Generic function for computing the sufficient statistics of a distribution based on empirical data.
suff_stat(d, x, ...)
suff_stat(d, x, ...)
d |
An object. The package provides methods for distribution
objects such as those from |
x |
A vector of data to compute the likelihood. |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
a named list of sufficient statistics
X <- Normal() suff_stat(X, c(-1, 0, 0, 0, 3))
X <- Normal() suff_stat(X, c(-1, 0, 0, 0, 3))
Compute the sufficient statistics for a Bernoulli distribution from data
## S3 method for class 'Bernoulli' suff_stat(d, x, ...)
## S3 method for class 'Bernoulli' suff_stat(d, x, ...)
d |
A |
x |
A vector of zeroes and ones. |
... |
Unused. |
A named list of the sufficient statistics of the Bernoulli distribution:
successes
: The number of successful trials (sum(x == 1)
)
failures
: The number of failed trials (sum(x == 0)
).
Compute the sufficient statistics for the Binomial distribution from data
## S3 method for class 'Binomial' suff_stat(d, x, ...)
## S3 method for class 'Binomial' suff_stat(d, x, ...)
d |
A |
x |
A vector of zeroes and ones. |
... |
Unused. |
A named list of the sufficient statistics of the Binomial distribution:
successes
: The total number of successful trials.
experiments
: The number of experiments run.
trials
: The number of trials run per experiment.
Compute the sufficient statistics of an Exponential distribution from data
## S3 method for class 'Exponential' suff_stat(d, x, ...)
## S3 method for class 'Exponential' suff_stat(d, x, ...)
d |
An |
x |
A vector of data. |
... |
Unused. |
A named list of the sufficient statistics of the exponential distribution:
sum
: The sum of the observations.
samples
: The number of observations.
sum
: The sum of the data.
log_sum
: The log of the sum of the data.
samples
: The number of samples in the data.
## S3 method for class 'Gamma' suff_stat(d, x, ...)
## S3 method for class 'Gamma' suff_stat(d, x, ...)
d |
A |
x |
A vector to fit the Gamma distribution to. |
... |
Unused. |
a Gamma
object
Compute the sufficient statistics for the Geometric distribution from data
## S3 method for class 'Geometric' suff_stat(d, x, ...)
## S3 method for class 'Geometric' suff_stat(d, x, ...)
d |
A |
x |
A vector of zeroes and ones. |
... |
Unused. |
A named list of the sufficient statistics of the Geometric distribution:
trials
: The total number of trials ran until the first success.
experiments
: The number of experiments run.
Compute the sufficient statistics for a Log-normal distribution from data
## S3 method for class 'LogNormal' suff_stat(d, x, ...)
## S3 method for class 'LogNormal' suff_stat(d, x, ...)
d |
A |
x |
A vector of data. |
... |
Unused. |
A named list of the sufficient statistics of the normal distribution:
mu
: The sample mean of the log of the data.
sigma
: The sample standard deviation of the log of the data.
samples
: The number of samples in the data.
Compute the sufficient statistics for a Normal distribution from data
## S3 method for class 'Normal' suff_stat(d, x, ...)
## S3 method for class 'Normal' suff_stat(d, x, ...)
d |
A |
x |
A vector of data. |
... |
Unused. |
A named list of the sufficient statistics of the normal distribution:
mu
: The sample mean of the data.
sigma
: The sample standard deviation of the data.
samples
: The number of samples in the data.
Compute the sufficient statistics of an Poisson distribution from data
## S3 method for class 'Poisson' suff_stat(d, x, ...)
## S3 method for class 'Poisson' suff_stat(d, x, ...)
d |
An |
x |
A vector of data. |
... |
Unused. |
A named list of the sufficient statistics of the Poisson distribution:
sum
: The sum of the data.
samples
: The number of samples in the data.
Generic function for computing the support interval (minimum and maximum) for a given probability distribution object.
support(d, drop = TRUE, ...)
support(d, drop = TRUE, ...)
d |
An object. The package provides methods for distribution
objects such as those from |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
A vector (or matrix) with two elements (or columns) indicating the range (minimum and maximum) of the support.
X <- Normal() support(X) Y <- Uniform(-1, 1:3) support(Y)
X <- Normal() support(X) Y <- Uniform(-1, 1:3) support(Y)
Return the support of the Bernoulli distribution
## S3 method for class 'Bernoulli' support(d, drop = TRUE, ...)
## S3 method for class 'Bernoulli' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Beta distribution
## S3 method for class 'Beta' support(d, drop = TRUE, ...)
## S3 method for class 'Beta' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Binomial distribution
## S3 method for class 'Binomial' support(d, drop = TRUE, ...)
## S3 method for class 'Binomial' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Shoul the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Cauchy distribution
## S3 method for class 'Cauchy' support(d, drop = TRUE, ...)
## S3 method for class 'Cauchy' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the ChiSquare distribution
## S3 method for class 'ChiSquare' support(d, drop = TRUE, ...)
## S3 method for class 'ChiSquare' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Erlang distribution
## S3 method for class 'Erlang' support(d, drop = TRUE, ...)
## S3 method for class 'Erlang' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Exponential distribution
## S3 method for class 'Exponential' support(d, drop = TRUE, ...)
## S3 method for class 'Exponential' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the FisherF distribution
## S3 method for class 'FisherF' support(d, drop = TRUE, ...)
## S3 method for class 'FisherF' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Frechet distribution
## S3 method for class 'Frechet' support(d, drop = TRUE, ...)
## S3 method for class 'Frechet' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
In case of a single distribution object, a numeric vector of length 2
with the minimum and maximum value of the support (if drop = TRUE
, default)
or a matrix
with 2 columns. In case of a vectorized distribution object, a
matrix with 2 columns containing all minima and maxima.
Return the support of the Gamma distribution
## S3 method for class 'Gamma' support(d, drop = TRUE, ...)
## S3 method for class 'Gamma' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Geometric distribution
## S3 method for class 'Geometric' support(d, drop = TRUE, ...)
## S3 method for class 'Geometric' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of a GEV distribution
## S3 method for class 'GEV' support(d, drop = TRUE, ...)
## S3 method for class 'GEV' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
In case of a single distribution object, a numeric vector of length 2
with the minimum and maximum value of the support (if drop = TRUE
, default)
or a matrix
with 2 columns. In case of a vectorized distribution object, a
matrix with 2 columns containing all minima and maxima.
Return the support of the GP distribution
## S3 method for class 'GP' support(d, drop = TRUE, ...)
## S3 method for class 'GP' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
In case of a single distribution object, a numeric vector of length 2
with the minimum and maximum value of the support (if drop = TRUE
, default)
or a matrix
with 2 columns. In case of a vectorized distribution object, a
matrix with 2 columns containing all minima and maxima.
Return the support of the Gumbel distribution
## S3 method for class 'Gumbel' support(d, drop = TRUE, ...)
## S3 method for class 'Gumbel' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
In case of a single distribution object, a numeric vector of length 2
with the minimum and maximum value of the support (if drop = TRUE
, default)
or a matrix
with 2 columns. In case of a vectorized distribution object, a
matrix with 2 columns containing all minima and maxima.
Return the support of the hurdle negative binomial distribution
## S3 method for class 'HurdleNegativeBinomial' support(d, drop = TRUE, ...)
## S3 method for class 'HurdleNegativeBinomial' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the hurdle Poisson distribution
## S3 method for class 'HurdlePoisson' support(d, drop = TRUE, ...)
## S3 method for class 'HurdlePoisson' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the HyperGeometric distribution
## S3 method for class 'HyperGeometric' support(d, drop = TRUE, ...)
## S3 method for class 'HyperGeometric' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Logistic distribution
## S3 method for class 'Logistic' support(d, drop = TRUE, ...)
## S3 method for class 'Logistic' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the LogNormal distribution
## S3 method for class 'LogNormal' support(d, drop = TRUE, ...)
## S3 method for class 'LogNormal' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the NegativeBinomial distribution
## S3 method for class 'NegativeBinomial' support(d, drop = TRUE, ...)
## S3 method for class 'NegativeBinomial' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Normal distribution
## S3 method for class 'Normal' support(d, drop = TRUE, ...)
## S3 method for class 'Normal' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
In case of a single distribution object, a numeric vector of length 2
with the minimum and maximum value of the support (if drop = TRUE
, default)
or a matrix
with 2 columns. In case of a vectorized distribution object, a
matrix with 2 columns containing all minima and maxima.
Return the support of the Poisson distribution
## S3 method for class 'Poisson' support(d, drop = TRUE, ...)
## S3 method for class 'Poisson' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the PoissonBinomial distribution
## S3 method for class 'PoissonBinomial' support(d, drop = TRUE, ...)
## S3 method for class 'PoissonBinomial' support(d, drop = TRUE, ...)
d |
A |
drop |
logical. Shoul the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the RevWeibull distribution
## S3 method for class 'RevWeibull' support(d, drop = TRUE, ...)
## S3 method for class 'RevWeibull' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the StudentsT distribution
## S3 method for class 'StudentsT' support(d, drop = TRUE, ...)
## S3 method for class 'StudentsT' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Tukey distribution
## S3 method for class 'Tukey' support(d, drop = TRUE, ...)
## S3 method for class 'Tukey' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Uniform distribution
## S3 method for class 'Uniform' support(d, drop = TRUE, ...)
## S3 method for class 'Uniform' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the Weibull distribution
## S3 method for class 'Weibull' support(d, drop = TRUE, ...)
## S3 method for class 'Weibull' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the zero-inflated negative binomial distribution
## S3 method for class 'ZINegativeBinomial' support(d, drop = TRUE, ...)
## S3 method for class 'ZINegativeBinomial' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the zero-inflated Poisson distribution
## S3 method for class 'ZIPoisson' support(d, drop = TRUE, ...)
## S3 method for class 'ZIPoisson' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the zero-truncated negative binomial distribution
## S3 method for class 'ZTNegativeBinomial' support(d, drop = TRUE, ...)
## S3 method for class 'ZTNegativeBinomial' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Return the support of the zero-truncated Poisson distribution
## S3 method for class 'ZTPoisson' support(d, drop = TRUE, ...)
## S3 method for class 'ZTPoisson' support(d, drop = TRUE, ...)
d |
An |
drop |
logical. Should the result be simplified to a vector if possible? |
... |
Currently not used. |
A vector of length 2 with the minimum and maximum value of the support.
Tukey's studentized range distribution, used for Tukey's honestly significant differences test in ANOVA.
Tukey(nmeans, df, nranges)
Tukey(nmeans, df, nranges)
nmeans |
Sample size for each range. |
df |
Degrees of freedom. |
nranges |
Number of groups being compared. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
Support: , the set of positive real numbers.
Other properties of Tukey's Studentized Range Distribution are omitted, largely because the distribution is not fun to work with.
A Tukey
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Uniform()
,
Weibull()
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Tukey(4L, 16L, 2L) X cdf(X, 4) quantile(X, 0.7)
A distribution with constant density on an interval. The
continuous analogue to the Categorical()
distribution.
Uniform(a = 0, b = 1)
Uniform(a = 0, b = 1)
a |
The a parameter. |
b |
The a parameter. |
A Uniform
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Weibull()
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
set.seed(27) X <- Uniform(1, 2) X random(X, 10) pdf(X, 0.7) log_pdf(X, 0.7) cdf(X, 0.7) quantile(X, 0.7) cdf(X, quantile(X, 0.7)) quantile(X, cdf(X, 0.7))
Generic functions for computing moments (variance, skewness, excess kurtosis) from probability distributions.
variance(x, ...) skewness(x, ...) kurtosis(x, ...)
variance(x, ...) skewness(x, ...) kurtosis(x, ...)
x |
An object. The package provides methods for distribution
objects such as those from |
... |
Arguments passed to methods. Unevaluated arguments will generate a warning to catch mispellings or other possible errors. |
The functions variance
, skewness
, and kurtosis
are new
generic functions for computing moments of probability distributions such as
those provided in this package. Additionally, the probability distributions
from distributions3 all have methods for the mean
generic. Moreover, quantiles can be computed with methods for
quantile
. For examples illustrating the usage with
probability distribution objects, see the manual pages of the respective
distributions, e.g., Normal
or Binomial
etc.
Numeric vector with the values of the moments.
Generalization of the gamma distribution. Often used in survival and time-to-event analyses.
Weibull(shape, scale)
Weibull(shape, scale)
shape |
The shape parameter |
scale |
The scale parameter |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail and much greater clarity.
In the following, let be a Weibull random variable with
success probability
p
= .
Support: and zero.
Mean: , where
is
the gamma function.
Variance:
Probability density function (p.d.f):
Cumulative distribution function (c.d.f):
Moment generating function (m.g.f):
A Weibull
object.
Other continuous distributions:
Beta()
,
Cauchy()
,
ChiSquare()
,
Erlang()
,
Exponential()
,
FisherF()
,
Frechet()
,
GEV()
,
GP()
,
Gamma()
,
Gumbel()
,
LogNormal()
,
Logistic()
,
Normal()
,
RevWeibull()
,
StudentsT()
,
Tukey()
,
Uniform()
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
set.seed(27) X <- Weibull(0.3, 2) X random(X, 10) pdf(X, 2) log_pdf(X, 2) cdf(X, 4) quantile(X, 0.7)
Zero-inflated negative binomial distributions are frequently used to model counts with overdispersion and many zero observations.
ZINegativeBinomial(mu, theta, pi)
ZINegativeBinomial(mu, theta, pi)
mu |
Location parameter of the negative binomial component of the distribution. Can be any positive number. |
theta |
Overdispersion parameter of the negative binomial component of the distribution. Can be any positive number. |
pi |
Zero-inflation probability, can be any value in |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a zero-inflated negative binomial random variable with parameters
mu
= and
theta
= .
Support:
Mean:
Variance:
Probability mass function (p.m.f.):
where is the indicator function for zero and
is the p.m.f. of the
NegativeBinomial
distribution.
Cumulative distribution function (c.d.f.):
where is the c.d.f. of the
NegativeBinomial
distribution.
Moment generating function (m.g.f.):
Omitted for now.
A ZINegativeBinomial
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
,
ZTPoisson()
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated negative binomial distribution X <- ZINegativeBinomial(mu = 2.5, theta = 1, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Zero-inflated Poisson distributions are frequently used to model counts with many zero observations.
ZIPoisson(lambda, pi)
ZIPoisson(lambda, pi)
lambda |
Parameter of the Poisson component of the distribution. Can be any positive number. |
pi |
Zero-inflation probability, can be any value in |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a zero-inflated Poisson random variable with parameter
lambda
= .
Support:
Mean:
Variance:
Probability mass function (p.m.f.):
where is the indicator function for zero and
is the p.m.f. of the
Poisson
distribution.
Cumulative distribution function (c.d.f.):
where is the c.d.f. of the
Poisson
distribution.
Moment generating function (m.g.f.):
A ZIPoisson
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZTNegativeBinomial()
,
ZTPoisson()
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-inflated Poisson distribution X <- ZIPoisson(lambda = 2.5, pi = 0.25) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Zero-truncated negative binomial distributions are frequently used to model counts where zero observations cannot occur or have been excluded.
ZTNegativeBinomial(mu, theta)
ZTNegativeBinomial(mu, theta)
mu |
Location parameter of the negative binomial component of the distribution. Can be any positive number. |
theta |
Overdispersion parameter of the negative binomial component of the distribution. Can be any positive number. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a zero-truncated negative binomial random variable with parameter
mu
= .
Support:
Mean:
where is the c.d.f. of the
NegativeBinomial
distribution.
Variance: , where
is the mean above.
Probability mass function (p.m.f.):
where is the p.m.f. of the
NegativeBinomial
distribution.
Cumulative distribution function (c.d.f.):
Moment generating function (m.g.f.):
Omitted for now.
A ZTNegativeBinomial
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTPoisson()
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated negative binomial distribution X <- ZTNegativeBinomial(mu = 2.5, theta = 1) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
Zero-truncated Poisson distributions are frequently used to model counts where zero observations cannot occur or have been excluded.
ZTPoisson(lambda)
ZTPoisson(lambda)
lambda |
Parameter of the underlying untruncated Poisson distribution. Can be any positive number. |
We recommend reading this documentation on https://alexpghayes.github.io/distributions3/, where the math will render with additional detail.
In the following, let be a zero-truncated Poisson random variable with parameter
lambda
= .
Support:
Mean:
Variance: , where
is the mean above.
Probability mass function (p.m.f.):
where is the p.m.f. of the
Poisson
distribution.
Cumulative distribution function (c.d.f.):
where is the c.d.f. of the
Poisson
distribution.
Moment generating function (m.g.f.):
A ZTPoisson
object.
Other discrete distributions:
Bernoulli()
,
Binomial()
,
Categorical()
,
Geometric()
,
HurdleNegativeBinomial()
,
HurdlePoisson()
,
HyperGeometric()
,
Multinomial()
,
NegativeBinomial()
,
Poisson()
,
PoissonBinomial()
,
ZINegativeBinomial()
,
ZIPoisson()
,
ZTNegativeBinomial()
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)
## set up a zero-truncated Poisson distribution X <- ZTPoisson(lambda = 2.5) X ## standard functions pdf(X, 0:8) cdf(X, 0:8) quantile(X, seq(0, 1, by = 0.25)) ## cdf() and quantile() are inverses for each other quantile(X, cdf(X, 3)) ## density visualization plot(0:8, pdf(X, 0:8), type = "h", lwd = 2) ## corresponding sample with histogram of empirical frequencies set.seed(0) x <- random(X, 500) hist(x, breaks = -1:max(x) + 0.5)