distributions | R Documentation |
A collection of S4 classes that provide a flexible and structured way to work with probability distributions.
d(distr, x, ...)
p(distr, q, ...)
qn(distr, p, ...)
r(distr, n, ...)
distr |
an object of class |
x |
For the density function, |
... |
extra arguments. |
q |
numeric. Vector of quantiles. |
p |
numeric. Vector of probabilities. |
n |
number of observations. If |
These S4 generic methods can work both as functions and as functionals
(functions that return functions). The available distribution families are
coded as S4 classes, specifically subclasses of the Distribution
superclass. The methods can be used in two ways:
Option 1: If both the distr
argument and x
or n
are supplied, then the
function is evaluated directly, as usual.
Option 2: If only the distr
argument is supplied, the method returns a
function that takes as input the missing argument x
or n
, allowing the
user to work with the function object itself. See examples.
Looking for a specific distribution family? This help page is general. Use the help page of each distribution to see the available methods for the class, details, and examples. Check the See Also section.
Each type of function returns a different type of object:
Distribution Functions: When supplied with one argument (distr
), the
d()
, p()
, q()
, r()
, ll()
functions return the density, cumulative
probability, quantile, random sample generator, and log-likelihood functions,
respectively. When supplied with both arguments (distr
and x
), they
evaluate the aforementioned functions directly.
Moments: Returns a numeric, either vector or matrix depending on the moment
and the distribution. The moments()
function returns a list with all the
available methods.
Estimation: Returns a list, the estimators of the unknown parameters. Note that in distribution families like the binomial, multinomial, and negative binomial, the size is not returned, since it is considered known.
Variance: Returns a named matrix. The asymptotic covariance matrix of the estimator.
d()
: density function
p()
: cumulative distribution function
qn()
: generalized inverse distribution function
r()
: random sample generator function
moments, loglikelihood, estimation, Bern, Beta, Binom, Cat, Cauchy, Chisq, Dir, Exp, Fisher, Gam, Geom, Laplace, Lnorm, Multigam, Multinom, Nbinom, Norm, Pois, Stud, Unif, Weib
# -----------------------------------------------------
# Beta Distribution Example
# -----------------------------------------------------
# Create the distribution
a <- 3
b <- 5
D <- Beta(a, b)
# ------------------
# dpqr Functions
# ------------------
d(D, c(0.3, 0.8, 0.5)) # density function
p(D, c(0.3, 0.8, 0.5)) # distribution function
qn(D, c(0.4, 0.8)) # inverse distribution function
x <- r(D, 100) # random generator function
# alternative way to use the function
df <- d(D) ; df(x) # df is a function itself
# ------------------
# Moments
# ------------------
mean(D) # Expectation
var(D) # Variance
sd(D) # Standard Deviation
skew(D) # Skewness
kurt(D) # Excess Kurtosis
entro(D) # Entropy
finf(D) # Fisher Information Matrix
# List of all available moments
mom <- moments(D)
mom$mean # expectation
# ------------------
# Point Estimation
# ------------------
ll(D, x)
llbeta(x, a, b)
ebeta(x, type = "mle")
ebeta(x, type = "me")
ebeta(x, type = "same")
mle(D, x)
me(D, x)
same(D, x)
e(D, x, type = "mle")
mle("beta", x) # the distr argument can be a character
# ------------------
# Estimator Variance
# ------------------
vbeta(a, b, type = "mle")
vbeta(a, b, type = "me")
vbeta(a, b, type = "same")
avar_mle(D)
avar_me(D)
avar_same(D)
v(D, type = "mle")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.