Title: | Mixture and Composite Distributions |
---|---|
Description: | A flexible computational framework for mixture distributions with the focus on the composite models. |
Authors: | Lukas Sablica [aut, cre] , Kurt Hornik [aut] |
Maintainer: | Lukas Sablica <[email protected]> |
License: | GPL-3 |
Version: | 0.0.6 |
Built: | 2024-12-16 07:01:45 UTC |
Source: | CRAN |
A system offering object oriented handling of univariate distributions with focus on composite models.
Lukas Sablica, [email protected]
Kurt Hornik, [email protected]
Maintainer: Lukas Sablica, [email protected]
The functions plot the CDF, PDF and QQ-plot of a fitted distribution object together with the empirical values.
autoplot.comp_fit( x, which = "all", layout = matrix(c(1, 2, 1, 3), nrow = 2), empir_color = "#F9D607", empir_alpha = 0.4, ... )
autoplot.comp_fit( x, which = "all", layout = matrix(c(1, 2, 1, 3), nrow = 2), empir_color = "#F9D607", empir_alpha = 0.4, ... )
x |
distribution object. |
which |
whether to plot only CDF, PDF, qq or all three, default: 'all'. |
layout |
layout of plots, default: matrix(c(1, 2, 1, 3), nrow = 2). |
empir_color |
color of empirical data, default: '#F9D607'. |
empir_alpha |
alpha of empirical data, default: 0.4. |
... |
further arguments to be passed. |
ggplot object if which = "cdf"
or which = "pdf"
or which = "qq"
.
If all are plotted, the plots are merged using multiplot()
function and a list with all plots is invisibly returned.
The function autoplot
plots the CDF and PDF of a given distribution object.
autoplot.dist(x, which = "all", ncols = 2, ...)
autoplot.dist(x, which = "all", ncols = 2, ...)
x |
distribution object. |
which |
whether to plot only CDF, PDF or both, default: 'all'. |
ncols |
in how many columns should the plots be merged, default: 2. |
... |
further arguments to be passed. |
The function is a wrapper of the internal plotting function plotgg. For more
details see plotgg
.
ggplot object if which = "cdf" or which = "pdf". If both are plotted, the plots are
merged using multiplot()
function and a list with both plots is invisibly returned.
## Not run: N <- normdist() autoplot(N) # manipulating cdf plot B <- binomdist(12, 0.5) autoplot(-3*B, which = "cdf", xlim1 = c(-30, -10)) # manipulating pdf plot autoplot(-3*B, which = "pdf", xlim2 = c(-30, -10)) ## End(Not run)
## Not run: N <- normdist() autoplot(N) # manipulating cdf plot B <- binomdist(12, 0.5) autoplot(-3*B, which = "cdf", xlim1 = c(-30, -10)) # manipulating pdf plot autoplot(-3*B, which = "pdf", xlim2 = c(-30, -10)) ## End(Not run)
The function creates an object which represents the beta distribution.
betadist(shape1 = 2, shape2 = 2)
betadist(shape1 = 2, shape2 = 2)
shape1 |
shape parameter, default: 2. |
shape2 |
shape parameter, default: 2. |
See Beta
.
Object of class betadist.
B <- betadist(2, 2) d(B, c(2, 3, 4, NA)) r(B, 5)
B <- betadist(2, 2) d(B, c(2, 3, 4, NA)) r(B, 5)
The function creates an object which represents the binomial distribution.
binomdist(size = 10, prob = 0.5)
binomdist(size = 10, prob = 0.5)
size |
size parameter, default: 10. |
prob |
probability parameter, default: 0.5. |
See Binomial
.
Object of class binomdist.
B <- binomdist(10, 0.4) d(B, c(2, 3, 4, NA)) r(B, 5)
B <- binomdist(10, 0.4) d(B, c(2, 3, 4, NA)) r(B, 5)
breakpoints
is a generic function which extracts breakpoints from mistr
composite distribution objects.
breakpoints(O) ## S3 method for class 'compdist' breakpoints(O) ## S3 method for class 'trans_compdist' breakpoints(O) ## S3 method for class 'comp_fit' breakpoints(O)
breakpoints(O) ## S3 method for class 'compdist' breakpoints(O) ## S3 method for class 'trans_compdist' breakpoints(O) ## S3 method for class 'comp_fit' breakpoints(O)
O |
an object for which the extraction of model breakpoints is meaningful. |
Vector of extracted breakpoints form object.
N <- normdist(1, 3) C <- cauchydist() CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) breakpoints(CC)
N <- normdist(1, 3) C <- cauchydist() CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) breakpoints(CC)
Density, distribution function, quantile function and random generation for the Burr distribution with parameters shape1 and shape2.
dburr(x, shape1, shape2, log = FALSE) pburr(q, shape1, shape2, lower.tail = TRUE, log.p = FALSE) qburr(p, shape1, shape2, lower.tail = TRUE, log.p = FALSE) rburr(n, shape1, shape2)
dburr(x, shape1, shape2, log = FALSE) pburr(q, shape1, shape2, lower.tail = TRUE, log.p = FALSE) qburr(p, shape1, shape2, lower.tail = TRUE, log.p = FALSE) rburr(n, shape1, shape2)
x , q
|
vector of quantiles. |
shape1 |
shape parameter. |
shape2 |
shape parameter. |
log , log.p
|
logical; if TRUE, probabilities |
lower.tail |
logical; if TRUE, probabilities are |
p |
vector of probabilities. |
n |
number of observations. |
The Burr distribution function with shape1 parameter c and shape2 parameter k has density given by
for . The cumulative distribution function is
on .
See https://en.wikipedia.org/wiki/Burr_distribution for more details.
dburr
gives the density, pburr
gives the distribution function, qburr
gives the quantile function,
and rburr
generates random deviates.
Invalid arguments will result in return value NaN, with a warning.
dburr(seq(1, 5), 2, 2) qburr(pburr(seq(1, 5), 2, 2), 2 ,2) rburr(5, 2, 2)
dburr(seq(1, 5), 2, 2) qburr(pburr(seq(1, 5), 2, 2), 2 ,2) rburr(5, 2, 2)
The function creates an object which represents the Burr distribution.
burrdist(shape1 = 2, shape2 = 2)
burrdist(shape1 = 2, shape2 = 2)
shape1 |
shape parameter, default: 2. |
shape2 |
shape parameter, default: 2. |
See Burr
.
Object of class burrdist.
B <- burrdist(2, 2) d(B, c(2, 3, 4, NA)) r(B, 5)
B <- burrdist(2, 2) d(B, c(2, 3, 4, NA)) r(B, 5)
The function creates an object which represents the Cauchy distribution.
cauchydist(location = 0, scale = 1)
cauchydist(location = 0, scale = 1)
location |
location parameter, default: 0. |
scale |
scale parameter, default: 1. |
See Cauchy
.
Object of class cauchydist.
C <- cauchydist(0, 1) d(C, c(2, 3, 4, NA)) r(C, 5)
C <- cauchydist(0, 1) d(C, c(2, 3, 4, NA)) r(C, 5)
The function creates an object which represents the chi-squared distribution.
chisqdist(df = 2)
chisqdist(df = 2)
df |
degrees of freedom parameter, default: 2. |
See Chisquare
.
Object of class chisqdist.
C <- chisqdist(2) d(C, c(2, 3, 4, NA)) r(C, 5)
C <- chisqdist(2) d(C, c(2, 3, 4, NA)) r(C, 5)
compdist
creates an object which represents the composite distribution.
compdist(..., weights, breakpoints, break.spec, all.left = FALSE) ## S3 method for class 'dist' compdist(..., weights, breakpoints, break.spec, all.left = FALSE) ## Default S3 method: compdist(dist, params, weights, breakpoints, break.spec, all.left = FALSE, ...)
compdist(..., weights, breakpoints, break.spec, all.left = FALSE) ## S3 method for class 'dist' compdist(..., weights, breakpoints, break.spec, all.left = FALSE) ## Default S3 method: compdist(dist, params, weights, breakpoints, break.spec, all.left = FALSE, ...)
... |
distribution objects. |
weights |
vector of weights for the components. |
breakpoints |
vector of breakpoints for the composite models, first and last breakpoints ( |
break.spec |
vector of breakpoints specifications with values "L" or "R", breakpoints specifications corresponding to
|
all.left |
if TRUE, all break.spec are set to "L", default: FALSE. |
dist |
vector of distribution names. |
params |
list of parameters. |
A CDF of a composite distribution function is
, where
is the weight of the i-th component,
is the CDF of the i-th component
and
is the interval specified by the breakpoints. Clearly, the composite models are a
specific case of the mixture models, where the corresponding probability distribution
functions are truncated to some disjoint support.
The objects can be specified in two ways, either the user may enter objects representing distributions or a vector of names and list of parameters. See the examples below.
The argument break.spec
defines if the breakpoint should be included to the distribution
to the right ("R") or to the left ("L") of the breakpoint. This feature is of course useful
only in the case where at least one of the adjacent components is discrete. By default
the intervals are left-closed (all break.spec
values are "R").
The function permits to use the same breakpoint twice. This possibility allows to define a partition on a singleton, and hence to create a mass of probability. If this feature is used, the break.spec needs to be specified with "R" and "L", for the first and the second identical breakpoints, respectively, or not set at all.
Object of class compdist.
# using the objects C <- compdist(normdist(1, 3), expdist(4), weights = c(0.7, 0.3), breakpoints = 2) C # using the names and parameters C2 <- compdist(c("norm","exp"), list(c(mean = 1, sd = 3), c(rate = 4)), weights = c(0.7, 0.3), breakpoints = 2) C2 # more complicated model where break.spec is useful C3 <- compdist(-GPDdist(1,0.15,0.7), normdist(-1,1), binomdist(5,0.5), geomdist(0.3) + 2, weights = c(0.075, 0.425, 0.425, 0.075), breakpoints = c(-2.5, 0,3), break.spec = c("L", "R", "R")) C3 # same breakpoint twice C4 <- compdist(-expdist(2),poisdist(),expdist(2), weights = c(0.25, 0.5, 0.25), breakpoints = c(0, 0)) C4
# using the objects C <- compdist(normdist(1, 3), expdist(4), weights = c(0.7, 0.3), breakpoints = 2) C # using the names and parameters C2 <- compdist(c("norm","exp"), list(c(mean = 1, sd = 3), c(rate = 4)), weights = c(0.7, 0.3), breakpoints = 2) C2 # more complicated model where break.spec is useful C3 <- compdist(-GPDdist(1,0.15,0.7), normdist(-1,1), binomdist(5,0.5), geomdist(0.3) + 2, weights = c(0.075, 0.425, 0.425, 0.075), breakpoints = c(-2.5, 0,3), break.spec = c("L", "R", "R")) C3 # same breakpoint twice C4 <- compdist(-expdist(2),poisdist(),expdist(2), weights = c(0.25, 0.5, 0.25), breakpoints = c(0, 0)) C4
d
is a generic function that evaluates the density function of a distribution object at given values.
## S3 method for class 'compdist' d(O, x, log = FALSE) ## S3 method for class 'trans_compdist' d(O, x, log = FALSE) ## S3 method for class 'mixdist' d(O, x, log = FALSE) ## S3 method for class 'trans_mixdist' d(O, x, log = FALSE) d(O, x, log = FALSE) ## S3 method for class 'standist' d(O, x, log = FALSE) ## S3 method for class 'trans_contdist' d(O, x, log = FALSE) ## S3 method for class 'trans_discrdist' d(O, x, log = FALSE)
## S3 method for class 'compdist' d(O, x, log = FALSE) ## S3 method for class 'trans_compdist' d(O, x, log = FALSE) ## S3 method for class 'mixdist' d(O, x, log = FALSE) ## S3 method for class 'trans_mixdist' d(O, x, log = FALSE) d(O, x, log = FALSE) ## S3 method for class 'standist' d(O, x, log = FALSE) ## S3 method for class 'trans_contdist' d(O, x, log = FALSE) ## S3 method for class 'trans_discrdist' d(O, x, log = FALSE)
O |
distribution object. |
x |
vector of quantiles. |
log |
logical; if TRUE, probabilities |
Methods of d
function evaluates any offered
distribution from the package mistr
. The function makes use of the d[sufix] functions
as dnorm
or dbeta
and thus, if a new distribution is added,
these functions must be reachable through the search path.
Vector of computed results.
N <- normdist(1, 3) d(N, c(NA, 1, 3, 5)) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) d(M, c(NA, 1, 3, 5)) CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 d(CCC, c(NA, 1, 3, 5))
N <- normdist(1, 3) d(N, c(NA, 1, 3, 5)) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) d(M, c(NA, 1, 3, 5)) CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 d(CCC, c(NA, 1, 3, 5))
distribution
is a generic function which extracts the distribution with fitted parameters from fitted objects.
distribution(O) ## S3 method for class 'comp_fit' distribution(O)
distribution(O) ## S3 method for class 'comp_fit' distribution(O)
O |
an object for which the extraction of distribution is meaningful. |
Object representing the distribution.
The functions plot the CDF and PDF of a given distribution object.
## S3 method for class 'compdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 1, lty2 = 1, lwd1 = 2, lwd2 = 2, lty_abline = 3, mtext_cex = 1, ...) ## S3 method for class 'trans_compdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 1, lty2 = 1, lwd1 = 2, lwd2 = 2, lty_abline = 3, mtext_cex = 1, ...) ## S3 method for class 'contdist' plot(x, which = "all", pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'trans_contdist' plot(x, which = "all", pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'discrdist' plot(x, which = "all", col = "#122e94", xlim1 = q(x,c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = NULL, type2 = NULL, lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'trans_discrdist' plot(x, which = "all", col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = "p", type2 = "p", lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'contmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...) ## S3 method for class 'trans_contmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...) ## S3 method for class 'discrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 2 * (diff(xlim2)), col = "#122e94", xlim1 = q(x,c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 3, lwd2 = 3, ...) ## S3 method for class 'trans_discrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 2 * (diff(xlim2)), col = "#122e94", xlim1 = q(x,c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 3, lwd2 = 3, ...) ## S3 method for class 'contdiscrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...) ## S3 method for class 'trans_contdiscrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...)
## S3 method for class 'compdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 1, lty2 = 1, lwd1 = 2, lwd2 = 2, lty_abline = 3, mtext_cex = 1, ...) ## S3 method for class 'trans_compdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 1, lty2 = 1, lwd1 = 2, lwd2 = 2, lty_abline = 3, mtext_cex = 1, ...) ## S3 method for class 'contdist' plot(x, which = "all", pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'trans_contdist' plot(x, which = "all", pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'discrdist' plot(x, which = "all", col = "#122e94", xlim1 = q(x,c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = NULL, type2 = NULL, lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'trans_discrdist' plot(x, which = "all", col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = "p", type2 = "p", lty1 = NULL, lty2 = NULL, lwd1 = NULL, lwd2 = NULL, ...) ## S3 method for class 'contmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...) ## S3 method for class 'trans_contmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...) ## S3 method for class 'discrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 2 * (diff(xlim2)), col = "#122e94", xlim1 = q(x,c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 3, lwd2 = 3, ...) ## S3 method for class 'trans_discrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 2 * (diff(xlim2)), col = "#122e94", xlim1 = q(x,c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PMF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 3, lwd2 = 3, ...) ## S3 method for class 'contdiscrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...) ## S3 method for class 'trans_contdiscrmixdist' plot(x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#122e94", xlim1 = q(x, c(0.01, 0.99)), ylim1 = c(0, 1), xlim2 = xlim1, ylim2 = NULL, xlab1 = "x", ylab1 = expression(P(X <= x)), xlab2 = "x", ylab2 = "P(X = x)", main1 = "CDF", main2 = "PDF", type1 = "l", type2 = "l", lty1 = 3, lty2 = 3, lwd1 = 2, lwd2 = 2, ...)
x |
distribution object. |
which |
whether to plot only CDF, PDF or both, default: 'all'. |
only_mix |
whether to plot only mixture/composite model and not also the components, default: FALSE. |
pp1 |
number of points at which CDF is evaluated, default: 1000. |
pp2 |
number of points at which PDF is evaluated, default: 1000. |
col |
color used in plot, default: '#122e94'. |
xlim1 |
xlim of CDF plot, default: q(x, c(0.01, 0.99)). |
ylim1 |
ylim of CDF plot, default: NULL. |
xlim2 |
xlim of PDF plot, default: xlim1. |
ylim2 |
ylim of PDF plot, default: NULL. |
xlab1 |
xlab of CDF plot, default: 'x'. |
ylab1 |
ylab of CDF plot, default: expression(P(X <= x)). |
xlab2 |
xlab of PDF plot, default: 'x'. |
ylab2 |
ylab of PDF plot, default: 'P(X = x)'. |
main1 |
title of CDF plot, default: 'CDF'. |
main2 |
title of PDF plot, default: 'PDF'/'PMF'. |
type1 |
type of CDF plot. |
type2 |
type of PDF plot. |
lty1 |
lty used in CDF plot. |
lty2 |
lty used in PDF plot. |
lwd1 |
lwd used in CDF plot. |
lwd2 |
lwd used in PDF plot. |
lty_abline |
lty of abline if ablines are part of plot (composite and discrete distributions). |
mtext_cex |
cex parameter for mtexts used in the plots of composite distributions, default: 1. |
... |
further arguments to be passed. |
N <- normdist() plot(N) # manipulating cdf plot B <- binomdist(12, 0.5) plot(-3*B, which = "cdf", xlim1 = c(-30, -10)) # manipulating pdf plot plot(-3*B, which = "pdf", xlim1 = c(-30, -10))
N <- normdist() plot(N) # manipulating cdf plot B <- binomdist(12, 0.5) plot(-3*B, which = "cdf", xlim1 = c(-30, -10)) # manipulating pdf plot plot(-3*B, which = "pdf", xlim1 = c(-30, -10))
Displays a useful description of a distribution object from mistr
.
## S3 method for class 'standist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'trans_standist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'mixdist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'trans_mixdist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'compdist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'trans_compdist' summary(object, level = 1, space = 2, additional_list, truncation, ...)
## S3 method for class 'standist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'trans_standist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'mixdist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'trans_mixdist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'compdist' summary(object, level = 1, space = 2, additional_list, truncation, ...) ## S3 method for class 'trans_compdist' summary(object, level = 1, space = 2, additional_list, truncation, ...)
object |
distribution object to summarize. |
level |
adds 3*(level-1) spaces before the print, default: 1. |
space |
number of blank lines between outputs, default: 2. |
additional_list , truncation , ...
|
additional information that may be passed to summary. |
summary
prints useful description of a distribution object. This feature might
be useful when working with a more complicated distribution that contains
mixture and composite distributions as components and the print function does not
offer enough information.
Arguments level
, additional_list
and truncation
are present for recursive usage that is done for more complicated models
automatically by the function.
The methods for arithmetic operators +, -, *, /, ^, log, exp, sqrt
, which perform
a transformation of a given random variable.
## S3 method for class 'univdist' e1 + e2 = NULL ## S3 method for class 'trans_univdist' e1 + e2 = NULL ## S3 method for class 'univdist' e1 * e2 ## S3 method for class 'trans_univdist' e1 * e2 ## S3 method for class 'dist' e1 / e2 ## S3 method for class 'dist' e1 - e2 = NULL ## S3 method for class 'dist' sqrt(x) ## S3 method for class 'univdist' log(x, base = exp(1)) ## S3 method for class 'trans_univdist' log(x, base = exp(1)) ## S3 method for class 'univdist' exp(x) ## S3 method for class 'trans_univdist' exp(x) ## S3 method for class 'univdist' e1 ^ e2 ## S3 method for class 'trans_univdist' e1 ^ e2 ## S3 method for class 'normdist' e1 + e2 ## S3 method for class 'normdist' e1 * e2 ## S3 method for class 'normdist' exp(x) ## S3 method for class 'expdist' e1 * e2 ## S3 method for class 'expdist' e1 ^ e2 ## S3 method for class 'unifdist' e1 + e2 ## S3 method for class 'unifdist' e1 * e2 ## S3 method for class 'tdist' e1 ^ e2 ## S3 method for class 'fdist' e1 ^ e2 ## S3 method for class 'betadist' e1 - e2 = NULL ## S3 method for class 'binomdist' e1 - e2 = NULL ## S3 method for class 'gammadist' e1 * e2 ## S3 method for class 'cauchydist' e1 + e2 ## S3 method for class 'cauchydist' e1 * e2 ## S3 method for class 'cauchydist' e1 ^ e2 ## S3 method for class 'lnormdist' e1 * e2 ## S3 method for class 'lnormdist' log(x, base = exp(1)) ## S3 method for class 'lnormdist' e1 ^ e2 ## S3 method for class 'weibulldist' e1 * e2 ## S3 method for class 'gumbeldist' e1 + e2 ## S3 method for class 'gumbeldist' e1 * e2 ## S3 method for class 'frechetdist' e1 + e2 ## S3 method for class 'frechetdist' e1 * e2 ## S3 method for class 'paretodist' e1 * e2 ## S3 method for class 'GPDdist' e1 + e2 ## S3 method for class 'GPDdist' e1 * e2
## S3 method for class 'univdist' e1 + e2 = NULL ## S3 method for class 'trans_univdist' e1 + e2 = NULL ## S3 method for class 'univdist' e1 * e2 ## S3 method for class 'trans_univdist' e1 * e2 ## S3 method for class 'dist' e1 / e2 ## S3 method for class 'dist' e1 - e2 = NULL ## S3 method for class 'dist' sqrt(x) ## S3 method for class 'univdist' log(x, base = exp(1)) ## S3 method for class 'trans_univdist' log(x, base = exp(1)) ## S3 method for class 'univdist' exp(x) ## S3 method for class 'trans_univdist' exp(x) ## S3 method for class 'univdist' e1 ^ e2 ## S3 method for class 'trans_univdist' e1 ^ e2 ## S3 method for class 'normdist' e1 + e2 ## S3 method for class 'normdist' e1 * e2 ## S3 method for class 'normdist' exp(x) ## S3 method for class 'expdist' e1 * e2 ## S3 method for class 'expdist' e1 ^ e2 ## S3 method for class 'unifdist' e1 + e2 ## S3 method for class 'unifdist' e1 * e2 ## S3 method for class 'tdist' e1 ^ e2 ## S3 method for class 'fdist' e1 ^ e2 ## S3 method for class 'betadist' e1 - e2 = NULL ## S3 method for class 'binomdist' e1 - e2 = NULL ## S3 method for class 'gammadist' e1 * e2 ## S3 method for class 'cauchydist' e1 + e2 ## S3 method for class 'cauchydist' e1 * e2 ## S3 method for class 'cauchydist' e1 ^ e2 ## S3 method for class 'lnormdist' e1 * e2 ## S3 method for class 'lnormdist' log(x, base = exp(1)) ## S3 method for class 'lnormdist' e1 ^ e2 ## S3 method for class 'weibulldist' e1 * e2 ## S3 method for class 'gumbeldist' e1 + e2 ## S3 method for class 'gumbeldist' e1 * e2 ## S3 method for class 'frechetdist' e1 + e2 ## S3 method for class 'frechetdist' e1 * e2 ## S3 method for class 'paretodist' e1 * e2 ## S3 method for class 'GPDdist' e1 + e2 ## S3 method for class 'GPDdist' e1 * e2
e1 |
distribution object or numeric of length one. |
e2 |
distribution object or numeric of length one. |
x |
distribution object. |
base |
a positive number: the base with respect to which logarithms are computed. |
The offered arithmetic operators +, -, *, /, ^, log, exp, sqrt
create
an object that represents transformed random variable.
The functions, using the expressions manipulation, prepare expressions for transformation, inverse transformation, derivative of the inverse transformation and print. These expressions are then used later when the distribution is evaluated.
The transformation framework also keeps track on history of the transformations and so is able to recognize some inverse transformations of previous transformations or update the last transformation. Additionally, the methods are able to recognize some invariant and direct transformations, and so rather change the parameters or distribution family than to loose this information.
Object representing a transformed random variable.
# transformation B <- binomdist(10, 0.3) B2 <- - 3*log(B) B2 # invariant transformation N <- normdist(1, 3) N2 <- - 3*N + 5 N2 # direct transformation N3 <- exp(N2) N3 # recognize inverse B3 <- exp(B2/-3) B3 # update B4 <- B + 5 B4 + 3
# transformation B <- binomdist(10, 0.3) B2 <- - 3*log(B) B2 # invariant transformation N <- normdist(1, 3) N2 <- - 3*N + 5 N2 # direct transformation N3 <- exp(N2) N3 # recognize inverse B3 <- exp(B2/-3) B3 # update B4 <- B + 5 B4 + 3
The function creates an object which represents the exponential distribution.
expdist(rate = 1)
expdist(rate = 1)
rate |
rate parameter, default: 1. |
See Exponential
.
Object of class expdist.
E <- expdist(1) d(E, c(2, 3, 4, NA)) r(E, 5)
E <- expdist(1) d(E, c(2, 3, 4, NA)) r(E, 5)
The function creates an object which represents the F distribution.
fdist(df1 = 2, df2 = 2)
fdist(df1 = 2, df2 = 2)
df1 |
degrees of freedom parameter, default: 2. |
df2 |
degrees of freedom parameter, default: 2. |
See FDist
.
Object of class fdist.
f <- fdist(2, 2) d(f, c(2, 3, 4, NA)) r(f, 5)
f <- fdist(2, 2) d(f, c(2, 3, 4, NA)) r(f, 5)
Density, distribution function, quantile function and random generation for the Frechet distribution with location, scale and shape parameters.
dfrechet(x, loc = 0, scale = 1, shape = 1, log = FALSE) pfrechet(q, loc = 0, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) qfrechet(p, loc = 0, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) rfrechet(n, loc = 0, scale = 1, shape = 1)
dfrechet(x, loc = 0, scale = 1, shape = 1, log = FALSE) pfrechet(q, loc = 0, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) qfrechet(p, loc = 0, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) rfrechet(n, loc = 0, scale = 1, shape = 1)
x , q
|
vector of quantiles. |
loc |
location parameter. |
scale |
scale parameter. |
shape |
shape parameter. |
log , log.p
|
logical; if TRUE, probabilities |
lower.tail |
logical; if TRUE, probabilities are |
p |
vector of probabilities. |
n |
number of observations. |
The Frechet distribution function with location parameter , scale parameter
and shape parameter
has density given by
for , where
. The cumulative distribution function is
for , with
as stated above.
See https://en.wikipedia.org/wiki/Frechet_distribution for more details.
dfrechet
gives the density, pfrechet
gives the distribution function, qfrechet
gives the quantile function, and
rfrechet
generates random deviates.
Invalid arguments will result in return value NaN, with a warning.
dfrechet(seq(1, 5), 0, 1, 1) qfrechet(pfrechet(seq(1, 5), 0, 1, 1), 0, 1, 1) rfrechet(5, 0, 1, 1)
dfrechet(seq(1, 5), 0, 1, 1) qfrechet(pfrechet(seq(1, 5), 0, 1, 1), 0, 1, 1) rfrechet(5, 0, 1, 1)
The function creates an object which represents the Frechet distribution.
frechetdist(loc = 0, scale = 1, shape = 1)
frechetdist(loc = 0, scale = 1, shape = 1)
loc |
location parameter, default: 0. |
scale |
scale parameter, default: 1. |
shape |
shape parameter, default: 1. |
See Frechet
.
Object of class frechetdist.
Fr <- frechetdist(0, 1, 2) d(Fr, c(2, 3, 4, NA)) r(Fr, 5)
Fr <- frechetdist(0, 1, 2) d(Fr, c(2, 3, 4, NA)) r(Fr, 5)
The function creates an object which represents the gamma distribution.
gammadist(shape = 2, rate, scale)
gammadist(shape = 2, rate, scale)
shape |
shape parameter, default: 2. |
rate |
rate parameter, an alternative way to specify the scale. |
scale |
scale parameter. |
See GammaDist
.
Object of class gammadist.
G <- gammadist(shape = 2, scale = 3) d(G, c(2, 3, 4, NA)) r(G, 5)
G <- gammadist(shape = 2, scale = 3) d(G, c(2, 3, 4, NA)) r(G, 5)
The function creates an object which represents the geometric distribution.
geomdist(prob = 0.5)
geomdist(prob = 0.5)
prob |
probability parameter, default: 0.5. |
See Geometric
.
Object of class geomdist.
G <- geomdist(0.5) d(G, c(2, 3, 4, NA)) r(G, 5)
G <- geomdist(0.5) d(G, c(2, 3, 4, NA)) r(G, 5)
Function can be used to extract the parameters used in mistr
.
get_opt(...)
get_opt(...)
... |
characteristic strings of desired parameters. Possible values "sub", "add", "tol". |
named vector with values.
get_opt("sub", "tol")
get_opt("sub", "tol")
GNG_fit
is used to fit three components composite models with components GPD, normal and GPD.
GNG_fit( data, start = c(break1 = -0.02, break2 = 0.02, mean = 0, sd = 0.0115, shape1 = 0.15, shape2 = 0.15), break_fix = FALSE, midd = mean(data), ... )
GNG_fit( data, start = c(break1 = -0.02, break2 = 0.02, mean = 0, sd = 0.0115, shape1 = 0.15, shape2 = 0.15), break_fix = FALSE, midd = mean(data), ... )
data |
vector of values to which the density is optimized. |
start |
named vector (break1, break2, mean, sd, shape1, shape2) of values that are used to start the optimization, default: c(break1 = -0.02, break2 = 0.02, mean = 0, sd = 0.0115, shape1 = 0.15,shape2 = 0.15). |
break_fix |
logical, fix the breakpoints at the values from start?, default: FALSE. |
midd |
split reals into two subintervals, the first breakpoint is then optimized on the left of |
... |
further arguments to be passed to the optimizer. |
The GNG model is the GPD-Normal-GPD model. This means
that a transformation of a GPD random variable will be used for the left tail,
normal distribution for the center and again GPD for the right tail.
The code uses the maximum likelihood estimation technique to estimate the six parameters from the start vector
(break1, break2, mean, sd, shape1, shape2
). The other parameters (location and scale parameters of the GPD) are
computed in each step such that the function is continuous. Weights are estimated in every step as a proportion
of points that correspond to each of the truncated region. If the breakpoints are fixed (i.e. break_fix = TRUE
),
the weights are computed before the optimization procedure.
Optimization is handled by the mle2
function.
A list of class comp_fit.
## Not run: GNG_fit(stocks$SAP) GNG_fit(stocks$MSFT) autoplot(GNG_fit(stocks$ADS)) GNG_fit(stocks$GSPC, start = c(break1=-0.0075, break2=0.0075, mean=0, sd=0.0115, shape1=0.15, shape2=0.15), control = list(maxit = 20000)) GNG_fit(stocks$DJI, start = c(break1=-0.0055, break2=0.0055, mean=-0.001, sd=0.0055,shape1=0.15,shape2=0.15), method = "CG",control = list(maxit = 1000)) ## End(Not run)
## Not run: GNG_fit(stocks$SAP) GNG_fit(stocks$MSFT) autoplot(GNG_fit(stocks$ADS)) GNG_fit(stocks$GSPC, start = c(break1=-0.0075, break2=0.0075, mean=0, sd=0.0115, shape1=0.15, shape2=0.15), control = list(maxit = 20000)) GNG_fit(stocks$DJI, start = c(break1=-0.0055, break2=0.0055, mean=-0.001, sd=0.0055,shape1=0.15,shape2=0.15), method = "CG",control = list(maxit = 1000)) ## End(Not run)
Density, distribution function, quantile function and random generation for the generalized Pareto distribution with location, scale and shape parameters.
dGPD(x, loc = 0, scale = 1, shape = 0, log = FALSE) pGPD(q, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) qGPD(p, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) rGPD(n, loc = 0, scale = 1, shape = 0)
dGPD(x, loc = 0, scale = 1, shape = 0, log = FALSE) pGPD(q, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) qGPD(p, loc = 0, scale = 1, shape = 0, lower.tail = TRUE, log.p = FALSE) rGPD(n, loc = 0, scale = 1, shape = 0)
x , q
|
vector of quantiles. |
loc |
location parameter. |
scale |
scale parameter. |
shape |
shape parameter. |
log , log.p
|
logical; if TRUE, probabilities |
lower.tail |
logical; if TRUE, probabilities are |
p |
vector of probabilities. |
n |
number of observations. |
The generalized Pareto distribution function with location parameter , scale parameter
and shape parameter
has density given by
for and
,
or
and
,
where
. In the case where
, the density is equal to
for
.
The cumulative distribution function is
for and
,
or
and
,
with
as stated above. If
the CDF has form
.
See https://en.wikipedia.org/wiki/Generalized_Pareto_distribution for more details.
dGPD
gives the density, pGPD
gives the distribution function, qGPD
gives the quantile function, and
rGPD
generates random deviates.
Invalid arguments will result in return value NaN, with a warning.
dGPD(seq(1, 5), 0, 1, 1) qGPD(pGPD(seq(1, 5), 0, 1, 1), 0, 1 ,1) rGPD(5, 0, 1, 1)
dGPD(seq(1, 5), 0, 1, 1) qGPD(pGPD(seq(1, 5), 0, 1, 1), 0, 1 ,1) rGPD(5, 0, 1, 1)
The function creates an object which represents the generalized Pareto distribution.
GPDdist(loc = 0, scale = 1, shape = 0)
GPDdist(loc = 0, scale = 1, shape = 0)
loc |
location parameter, default: 0. |
scale |
scale parameter, default: 1. |
shape |
shape parameter, default: 0. |
See GPD
.
Object of class GPDdist.
G <- GPDdist(0, 1, 0) d(G, c(2, 3, 4, NA)) r(G, 5)
G <- GPDdist(0, 1, 0) d(G, c(2, 3, 4, NA)) r(G, 5)
Density, distribution function, quantile function and random generation for the Gumbel distribution with location and scale parameters.
dgumbel(x, loc, scale, log = FALSE) pgumbel(q, loc, scale, lower.tail = TRUE, log.p = FALSE) qgumbel(p, loc, scale, lower.tail = TRUE, log.p = FALSE) rgumbel(n, loc, scale)
dgumbel(x, loc, scale, log = FALSE) pgumbel(q, loc, scale, lower.tail = TRUE, log.p = FALSE) qgumbel(p, loc, scale, lower.tail = TRUE, log.p = FALSE) rgumbel(n, loc, scale)
x , q
|
vector of quantiles. |
loc |
location parameter. |
scale |
scale parameter. |
log , log.p
|
logical; if TRUE, probabilities |
lower.tail |
logical; if TRUE, probabilities are |
p |
vector of probabilities. |
n |
number of observations. |
The Gumbel distribution function with location parameter and scale parameter
has density given by
, where . The cumulative distribution function is
with as stated above.
See https://en.wikipedia.org/wiki/Gumbel_distribution for more details.
dgumbel
gives the density, pgumbel
gives the distribution function, qgumbel
gives the quantile function, and
rgumbel
generates random deviates.
Invalid arguments will result in return value NaN, with a warning.
dgumbel(seq(1, 5), 0, 1) qgumbel(pgumbel(seq(1, 5), 0, 1), 0 ,1) rgumbel(5, 0, 1)
dgumbel(seq(1, 5), 0, 1) qgumbel(pgumbel(seq(1, 5), 0, 1), 0 ,1) rgumbel(5, 0, 1)
The function creates an object which represents the Burr distribution.
gumbeldist(loc = 0, scale = 1)
gumbeldist(loc = 0, scale = 1)
loc |
location parameter, default: 0. |
scale |
scale parameter, default: 1. |
See Gumbel
.
Object of class gumbeldist.
G <- gumbeldist(1, 2) d(G, c(2, 3, 4, NA)) r(G, 5)
G <- gumbeldist(1, 2) d(G, c(2, 3, 4, NA)) r(G, 5)
The function creates an object which represents the hypergeometric distribution.
hyperdist(m = 10, n = 10, k = 5)
hyperdist(m = 10, n = 10, k = 5)
m |
the number of white balls in the urn, default: 10. |
n |
the number of black balls in the urn, default: 10. |
k |
the number of balls drawn from the urn, default: 5. |
See Hypergeometric
.
Object of class hyperdist.
H <- hyperdist(0.5) d(H, c(2, 3, 4, NA)) r(H, 5)
H <- hyperdist(0.5) d(H, c(2, 3, 4, NA)) r(H, 5)
Reports whether O is a composite distribution object.
is.composite(O)
is.composite(O)
O |
an object to test. |
Reports whether O is a continuous distribution object.
is.contin(O)
is.contin(O)
O |
an object to test. |
Reports whether O is a discrete distribution object.
is.discrete(O)
is.discrete(O)
O |
an object to test. |
Reports whether O is a distribution object.
is.dist(O)
is.dist(O)
O |
an object to test. |
Reports whether O is a mixture distribution object.
is.mixture(O)
is.mixture(O)
O |
an object to test. |
Reports whether O is a standard distribution object.
is.standard(O)
is.standard(O)
O |
an object to test. |
Reports whether O is a transformed distribution object.
is.transformed(O)
is.transformed(O)
O |
an object to test. |
Function returns a vector of points where a mass of probability is present.
These points are then used in plot
and plotgg
calls.
jumps(O, interval) ## S3 method for class 'discrdist' jumps(O, interval) ## S3 method for class 'trans_discrdist' jumps(O, interval) ## S3 method for class 'contdist' jumps(O, interval) ## S3 method for class 'trans_contdist' jumps(O, interval) ## S3 method for class 'mixdist' jumps(O, interval) ## S3 method for class 'trans_mixdist' jumps(O, interval) ## S3 method for class 'compdist' jumps(O, interval) ## S3 method for class 'trans_compdist' jumps(O, interval)
jumps(O, interval) ## S3 method for class 'discrdist' jumps(O, interval) ## S3 method for class 'trans_discrdist' jumps(O, interval) ## S3 method for class 'contdist' jumps(O, interval) ## S3 method for class 'trans_contdist' jumps(O, interval) ## S3 method for class 'mixdist' jumps(O, interval) ## S3 method for class 'trans_mixdist' jumps(O, interval) ## S3 method for class 'compdist' jumps(O, interval) ## S3 method for class 'trans_compdist' jumps(O, interval)
O |
distribution object. |
interval |
interval in which the support of discrete elements should be found. |
Vector of values.
The function is designed in a way that it rather returns more than less. Thus it might return a value that is close to the interval but not in. This is for use of the package not a problem as jumps is internally used only in plots and quantile function of a mixture distribution where an additional value can not influence the output.
B <- binomdist(12, 0.4) P <- poisdist(2) I <- c(-7, 16.8) jumps(B, I) jumps(P, I)
B <- binomdist(12, 0.4) P <- poisdist(2) I <- c(-7, 16.8) jumps(B, I) jumps(P, I)
Function returns the last element from history list.
last_history(O, t)
last_history(O, t)
O |
transformed distribution object. |
t |
which characterization should be extracted. |
Expression if t is set to "expre", "iexpre", "oldprint" and "oldderiv". Numeric and string if t is equal to "value" and "operation", respectively.
B <- binomdist(10, 0.3) B2 <- -3*log(B) last_history(B2, "value") last_history(B2, "operation")
B <- binomdist(10, 0.3) B2 <- -3*log(B) last_history(B2, "value") last_history(B2, "operation")
The function creates an object which represents the log normal distribution.
lnormdist(meanlog = 0, sdlog = 1)
lnormdist(meanlog = 0, sdlog = 1)
meanlog |
mean parameter, default: 0. |
sdlog |
standard deviation parameter, default: 1. |
See Lognormal
.
Object of class lnormdist.
L <- lnormdist(0, 1) d(L, c(2, 3, 4, NA)) r(L, 5)
L <- lnormdist(0, 1) d(L, c(2, 3, 4, NA)) r(L, 5)
The functions mistr_d
, mistr_p
, mistr_q
, mistr_r
are wrappers
for d
, p
, q
and r
, respectively.
mistr_d(O, x, log = FALSE) mistr_p(O, q, lower.tail = TRUE, log.p = FALSE) mistr_q(O, p, lower.tail = TRUE, log.p = FALSE, ...) mistr_r(O, n)
mistr_d(O, x, log = FALSE) mistr_p(O, q, lower.tail = TRUE, log.p = FALSE) mistr_q(O, p, lower.tail = TRUE, log.p = FALSE, ...) mistr_r(O, n)
O |
distribution object. |
x , q
|
vector of quantiles. |
log , log.p
|
logical; if TRUE, probabilities |
lower.tail |
logical; if TRUE, probabilities are |
p |
vector of probabilities. |
... |
further arguments to be passed. |
n |
number of observations. |
Wrappers are offered as a consequence of R-Studio in Windows OS
where the q()
calls in the console are caught
and terminate the R
session.
Vector of computed results.
Theme for plots that use ggplot2.
mistr_theme(grey = FALSE, blue = FALSE, legend.position = "right", ...)
mistr_theme(grey = FALSE, blue = FALSE, legend.position = "right", ...)
grey |
logical, if TRUE grey palette is used, default: FALSE. |
blue |
logical, if TRUE blue palette is used, default: FALSE. |
legend.position |
position of legend, default: "right". |
... |
further arguments to be passed. |
ggplot theme.
mixdist
creates an object which represents the mixture distribution.
mixdist(..., weights) ## S3 method for class 'dist' mixdist(..., weights) ## Default S3 method: mixdist(dist, params, weights, ...)
mixdist(..., weights) ## S3 method for class 'dist' mixdist(..., weights) ## Default S3 method: mixdist(dist, params, weights, ...)
... |
distribution objects. |
weights |
vector of weights for the components. |
dist |
vector of distribution names. |
params |
list of parameters for each component. |
A CDF of a mixture distribution function is
, where
is the weight of the i-th component and
is the CDF of the i-th component.
The objects can be specified in two ways, either the user may enter distribution objects or a vector of names and list of parameters. See the examples below.
Object of class mixdist.
# using the objects M <- mixdist(normdist(1, 3), expdist(4), weights = c(0.7, 0.3)) M # using the names and parameters M2 <- mixdist(c("norm", "exp"), list(c(mean = 1, sd = 3), c(rate = 4)), weights = c(0.7, 0.3)) M2
# using the objects M <- mixdist(normdist(1, 3), expdist(4), weights = c(0.7, 0.3)) M # using the names and parameters M2 <- mixdist(c("norm", "exp"), list(c(mean = 1, sd = 3), c(rate = 4)), weights = c(0.7, 0.3)) M2
Function checks whether the transformation is increasing or decreasing.
monot(O) ## S3 method for class 'trans_univdist' monot(O)
monot(O) ## S3 method for class 'trans_univdist' monot(O)
O |
transforms distribution object. |
1 for increasing and -1 for decreasing.
The function creates an object which represents the multinomial distribution.
multinomdist(size = 10, prob = c(0.5, 0.5))
multinomdist(size = 10, prob = c(0.5, 0.5))
size |
size parameter, default: 10. |
prob |
probability parameter vector, default: c(0.5, 0.5). |
See Multinomial
.
Object of class multinomdist.
M <- multinomdist(10, c(0.5, 0.5)) d(M, c(7, 3)) r(M, 5)
M <- multinomdist(10, c(0.5, 0.5)) d(M, c(7, 3)) r(M, 5)
The function creates an object which represents the negative binomial distribution.
nbinomdist(size = 10, prob, mu)
nbinomdist(size = 10, prob, mu)
size |
size parameter, default: 10. |
prob |
probability parameter. |
mu |
alternative parametrization via mean, see |
See NegBinomial
.
Object of class nbinomdist.
N <- nbinomdist(10, 0.5) d(N, c(2, 3, 4, NA)) r(N, 5)
N <- nbinomdist(10, 0.5) d(N, c(2, 3, 4, NA)) r(N, 5)
The function creates distribution objects that satisfy the naming convention used in package mistr.
new_dist( name, from, to, by = NULL, parameters = mget(names(eval(quote(match.call()), parent)[-1]), parent), class = deparse(sys.calls()[[sys.nframe() - 1]][[1]]), parent = parent.frame() )
new_dist( name, from, to, by = NULL, parameters = mget(names(eval(quote(match.call()), parent)[-1]), parent), class = deparse(sys.calls()[[sys.nframe() - 1]][[1]]), parent = parent.frame() )
name |
string containing the name of the distribution. |
from |
numeric representing where the support of distribution starts. |
to |
numeric representing where the support of distribution ends. |
by |
numeric representing the deterministic step between support values. If NULL: continuous distribution is assumed. If the value is specified: discrete distribution with specified step is assumed, default: NULL. |
parameters |
named list of parameters of the distribution, default: mget(names(eval(quote(match.call()),parent)[-1]),parent). |
class |
class of the distribution, this should be set in [name]dist convention (e.g. normdist, tdist), default: deparse(sys.calls()[[sys.nframe() - 1]][[1]]). |
parent |
parent environment, default: parent.frame(). |
The function can be used in two ways. Either it can be called from the creator functions as for example
normdist
or unifdist
, or directly from any function or enviroment. In the former,
only arguments "name", "from" and "to" must be set. Other arguments will be filled according to the parent calls.
If this function is called directly, the arguments "parameters" and "class" have to be specified also.
distribution object.
## Not run: # using creator function unifdist <- function(min = 0, max = 1) { if (!is.numeric(min) || !is.numeric(max)) stop("Parameters must be a numeric") if (min >= max) stop("min must be smaller than max.") new_dist(name = "Uniform", from = min, to = max) } #directly U <- new_dist(name = "Uniform", from = 1, to = 6, parameters = list(min = 1, max = 6), class = "unifdist") ## End(Not run)
## Not run: # using creator function unifdist <- function(min = 0, max = 1) { if (!is.numeric(min) || !is.numeric(max)) stop("Parameters must be a numeric") if (min >= max) stop("min must be smaller than max.") new_dist(name = "Uniform", from = min, to = max) } #directly U <- new_dist(name = "Uniform", from = 1, to = 6, parameters = list(min = 1, max = 6), class = "unifdist") ## End(Not run)
The function creates an object which represents the normal distribution.
normdist(mean = 0, sd = 1)
normdist(mean = 0, sd = 1)
mean |
mean parameter, default: 0. |
sd |
standard deviation parameter, default: 1. |
See Normal
.
Object of class normdist.
N <- normdist(1, 5) d(N, c(2, 3, 4, NA)) r(N, 5)
N <- normdist(1, 5) d(N, c(2, 3, 4, NA)) r(N, 5)
p
is a generic function that evaluates the distribution function of a distribution object at given values.
## S3 method for class 'compdist' p(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'mixdist' p(O, q, lower.tail = TRUE, log.p = FALSE) p(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'standist' p(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'trans_univdist' p(O, q, lower.tail = TRUE, log.p = FALSE)
## S3 method for class 'compdist' p(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'mixdist' p(O, q, lower.tail = TRUE, log.p = FALSE) p(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'standist' p(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'trans_univdist' p(O, q, lower.tail = TRUE, log.p = FALSE)
O |
distribution object. |
q |
vector of quantiles. |
lower.tail |
logical; if TRUE, probabilities are |
log.p |
logical; if TRUE, probabilities |
Methods of p
function evaluates any offered
distribution from the package mistr
. The function makes use of the p[sufix] functions
as pnorm
or pbeta
and thus, if a new distribution is added,
these functions must be reachable through the search path.
Vector of computed results.
N <- normdist(1,3) p(N, c(NA,1,3,5)) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) p(M, c(NA,1,3,5)) CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 p(CCC, c(NA,1,3,5))
N <- normdist(1,3) p(N, c(NA,1,3,5)) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) p(M, c(NA,1,3,5)) CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 p(CCC, c(NA,1,3,5))
parameters
is a generic function which extracts parameters from mistr
distribution objects.
parameters(O) ## S3 method for class 'standist' parameters(O) ## S3 method for class 'trans_standist' parameters(O) ## S3 method for class 'mixdist' parameters(O) ## S3 method for class 'trans_mixdist' parameters(O) ## S3 method for class 'compdist' parameters(O) ## S3 method for class 'trans_compdist' parameters(O) ## S3 method for class 'comp_fit' parameters(O)
parameters(O) ## S3 method for class 'standist' parameters(O) ## S3 method for class 'trans_standist' parameters(O) ## S3 method for class 'mixdist' parameters(O) ## S3 method for class 'trans_mixdist' parameters(O) ## S3 method for class 'compdist' parameters(O) ## S3 method for class 'trans_compdist' parameters(O) ## S3 method for class 'comp_fit' parameters(O)
O |
an object for which the extraction of model parameters is meaningful. |
Vector (for standard distributions) or list (in the case of mixture/composite distribution) of parameters extracted from the object.
For a fitted object of class comp_fit returns vector of fitted parameters.
N <- normdist(1, 3) parameters(N) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) parameters(M)
N <- normdist(1, 3) parameters(N) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) parameters(M)
Density, distribution function, quantile function and random generation for the Pareto distribution with scale and shape parameters.
dpareto(x, scale = 1, shape = 1, log = FALSE) ppareto(q, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) qpareto(p, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) rpareto(n, scale = 1, shape = 1)
dpareto(x, scale = 1, shape = 1, log = FALSE) ppareto(q, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) qpareto(p, scale = 1, shape = 1, lower.tail = TRUE, log.p = FALSE) rpareto(n, scale = 1, shape = 1)
x , q
|
vector of quantiles. |
scale |
scale parameter. |
shape |
shape parameter. |
log , log.p
|
logical; if TRUE, probabilities |
lower.tail |
logical; if TRUE, probabilities are |
p |
vector of probabilities. |
n |
number of observations. |
The Pareto distribution function with scale parameter and shape parameter
has density given by
for . The cumulative distribution function is
for . See https://en.wikipedia.org/wiki/Pareto_distribution
for more details.
dpareto
gives the density, ppareto
gives the distribution function, qpareto
gives the quantile function, and
rpareto
generates random deviates.
Invalid arguments will result in return value NaN, with a warning.
dpareto(seq(1, 5), 1, 1) qpareto(ppareto(seq(1, 5), 1, 1), 1 ,1) rpareto(5, 1, 1)
dpareto(seq(1, 5), 1, 1) qpareto(ppareto(seq(1, 5), 1, 1), 1 ,1) rpareto(5, 1, 1)
The function creates an object which represents the Pareto distribution.
paretodist(scale = 1, shape = 1)
paretodist(scale = 1, shape = 1)
scale |
scale parameter, default: 1. |
shape |
shape parameter, default: 1. |
See Pareto
.
Object of class paretodist.
P <- paretodist(1, 1) d(P, c(2, 3, 4, NA)) r(P, 5)
P <- paretodist(1, 1) d(P, c(2, 3, 4, NA)) r(P, 5)
plim
is a generic function that evaluates the left-hand limit of distribution function
for a distribution object at given values.
## S3 method for class 'compdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'mixdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'discrdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'trans_univdist' plim(O, q, lower.tail = TRUE, log.p = FALSE)
## S3 method for class 'compdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'mixdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'discrdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contdist' plim(O, q, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'trans_univdist' plim(O, q, lower.tail = TRUE, log.p = FALSE)
O |
distribution object. |
q |
vector of quantiles. |
lower.tail |
logical; if TRUE, probabilities are |
log.p |
logical; if TRUE, probabilities |
Methods of plim
function evaluates the left-hand limit of any offered
distribution from the package mistr
. The left-hand limit is defined as
.
The function makes use of the p[sufix] and q[sufix] functions
as
pnorm
or qbeta
and thus, if a new distribution is added,
these functions must be reachable through the search path.
Vector of computed results.
B <- binomdist(10, 0.3) plim(B, c(NA, 1, 3, 5)) P <- poisdist() M <- mixdist(B, P, weights = c(0.5, 0.5)) plim(M, c(NA, 1, 3, 5)) CC <- compdist(B, P, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*CC+5 plim(CCC, c(NA, 1, 3, 5))
B <- binomdist(10, 0.3) plim(B, c(NA, 1, 3, 5)) P <- poisdist() M <- mixdist(B, P, weights = c(0.5, 0.5)) plim(M, c(NA, 1, 3, 5)) CC <- compdist(B, P, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*CC+5 plim(CCC, c(NA, 1, 3, 5))
The function plots the CDF, PDF and QQ-plot of a fitted distribution object together with the empirical values.
## S3 method for class 'comp_fit' plot( x, which = "all", layout = matrix(c(1, 2, 1, 3), nrow = 2), empir_color = "#122e94", mtext_cex = sett, ... )
## S3 method for class 'comp_fit' plot( x, which = "all", layout = matrix(c(1, 2, 1, 3), nrow = 2), empir_color = "#122e94", mtext_cex = sett, ... )
x |
distribution object. |
which |
whether to plot only CDF, PDF, qq or all three, default: 'all'. |
layout |
layout of plots, default: matrix(c(1, 2, 1, 3), nrow = 2). |
empir_color |
color of empirical data, default: '#122e94'. |
mtext_cex |
cex parameter for mtexts used in the plots. |
... |
further arguments to be passed. |
The function plotgg
plots the CDF and PDF of a given distribution object.
plotgg(x, which = "all", ...) ## S3 method for class 'contdist' plotgg( x, which = "all", pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.7, alpha2 = 0.7, ... ) ## S3 method for class 'trans_contdist' plotgg( x, which = "all", pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.7, alpha2 = 0.7, ... ) ## S3 method for class 'discrdist' plotgg( x, which = "all", col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 3.3, size2 = 3.3, alpha1 = 0.9, alpha2 = 0.9, col_segment = "#b05e0b", ... ) ## S3 method for class 'trans_discrdist' plotgg( x, which = "all", col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 3.3, size2 = 3.3, alpha1 = 0.9, alpha2 = 0.9, col_segment = "#b05e0b", ... ) ## S3 method for class 'contmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'trans_contmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'discrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.9, legend.position1 = "none", legend.position2 = "none", width = 0.25, ... ) ## S3 method for class 'trans_discrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.9, legend.position1 = "none", legend.position2 = "none", width = 0.25, ... ) ## S3 method for class 'contdiscrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'trans_contdiscrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'compdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", text_ylim = -0.01, col_segment = "white", lty_segment = 3, lwd_segment = 1.8, ... ) ## S3 method for class 'trans_compdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", text_ylim = -0.01, col_segment = "white", lty_segment = 3, lwd_segment = 1.8, ... )
plotgg(x, which = "all", ...) ## S3 method for class 'contdist' plotgg( x, which = "all", pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.7, alpha2 = 0.7, ... ) ## S3 method for class 'trans_contdist' plotgg( x, which = "all", pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.7, alpha2 = 0.7, ... ) ## S3 method for class 'discrdist' plotgg( x, which = "all", col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 3.3, size2 = 3.3, alpha1 = 0.9, alpha2 = 0.9, col_segment = "#b05e0b", ... ) ## S3 method for class 'trans_discrdist' plotgg( x, which = "all", col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 3.3, size2 = 3.3, alpha1 = 0.9, alpha2 = 0.9, col_segment = "#b05e0b", ... ) ## S3 method for class 'contmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'trans_contmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1, size2 = 1, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'discrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.9, legend.position1 = "none", legend.position2 = "none", width = 0.25, ... ) ## S3 method for class 'trans_discrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PMF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.9, legend.position1 = "none", legend.position2 = "none", width = 0.25, ... ) ## S3 method for class 'contdiscrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'trans_contdiscrmixdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", ... ) ## S3 method for class 'compdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", text_ylim = -0.01, col_segment = "white", lty_segment = 3, lwd_segment = 1.8, ... ) ## S3 method for class 'trans_compdist' plotgg( x, which = "all", only_mix = FALSE, pp1 = 1000, pp2 = 1000, col = "#F9D607", xlim1 = q(x, c(0.01, 0.99)), ylim1 = NULL, xlim2 = xlim1, ylim2 = NULL, xlab1 = NULL, ylab1 = NULL, xlab2 = NULL, ylab2 = NULL, main1 = "CDF", main2 = "PDF", size1 = 1.6, size2 = 1.6, alpha1 = 0.4, alpha2 = 0.4, legend.position1 = "none", legend.position2 = "none", text_ylim = -0.01, col_segment = "white", lty_segment = 3, lwd_segment = 1.8, ... )
x |
distribution object. |
which |
whether to plot only CDF, PDF or both, default: 'all'. |
... |
further arguments to be passed. |
pp1 |
number of points at which CDF is evaluated, default: 1000. |
pp2 |
number of points at which PDF is evaluated, default: 1000. |
col |
color used in plot, default: '#122e94'. |
xlim1 |
xlim of CDF plot, default: q(x, c(0.01, 0.99)). |
ylim1 |
ylim of CDF plot, default: NULL. |
xlim2 |
xlim of PDF plot, default: xlim1. |
ylim2 |
ylim of PDF plot, default: NULL. |
xlab1 |
xlab of CDF plot, default: NULL. |
ylab1 |
ylab of CDF plot, default: NULL. |
xlab2 |
xlab of PDF plot, default: NULL. |
ylab2 |
ylab of PDF plot, default: NULL. |
main1 |
title of CDF plot, default: 'CDF'. |
main2 |
title of PDF plot, default: 'PDF'/'PMF'. |
size1 |
size used in CDF plot. |
size2 |
size used in PDF plot. |
alpha1 |
alpha used in CDF plot. |
alpha2 |
alpha used in PDF plot. |
col_segment |
col of additional segment if contained in the plot (composite and discrete distributions). |
only_mix |
whether to plot only mixture/composite model and not also the components, default: FALSE. |
legend.position1 |
legend.position used in CDF plot. |
legend.position2 |
legend.position used in PDF plot. |
width |
width of the bars that are used to plot discrete mixtures, default: 0.25. |
text_ylim |
y coordinate for text annotation, default: -0.01. |
lty_segment |
lty of additional segment if contained in the plot (composite and discrete distributions). |
lwd_segment |
lwd of additional segment if contained in the plot (composite and discrete distributions). |
ggplot object if which = "cdf" or which = "pdf". If both are plotted, the plots are
merged using multiplot()
function and a list with both plots is invisibly returned.
## Not run: N <- normdist() autoplot(N) # manipulating cdf plot B <- binomdist(12, 0.5) autoplot(-3*B, which = "cdf", xlim1 = c(-30, -10)) # manipulating pdf plot autoplot(-3*B, which = "pdf", xlim2 = c(-30, -10)) ## End(Not run)
## Not run: N <- normdist() autoplot(N) # manipulating cdf plot B <- binomdist(12, 0.5) autoplot(-3*B, which = "cdf", xlim1 = c(-30, -10)) # manipulating pdf plot autoplot(-3*B, which = "pdf", xlim2 = c(-30, -10)) ## End(Not run)
GNG_fit
is used to fit three components composite models with components Pareto, normal and Pareto.
PNP_fit( data, start = c(break1 = -0.02, break2 = 0.02, mean = 0, sd = 0.012), ... )
PNP_fit( data, start = c(break1 = -0.02, break2 = 0.02, mean = 0, sd = 0.012), ... )
data |
vector of values to which the density is optimized. |
start |
named vector (break1, break2, mean, sd) of values that are used to start the optimization, default: c(break1 = -0.02, break2 = 0.02, mean = 0, sd = 0.012). |
... |
further arguments to be passed to optimizer. |
The PNP model is the Pareto-Normal-Pareto model. This means
that a transformation of a Pareto random variable will be used for the left tail,
normal distribution for the center and again Pareto for the right tail.
The code uses the maximum likelihood estimation technique to estimate the four parameters from the start vector
(break1, break2, mean, sd
). The other parameters (shape parameters of Pareto distribution) are
computed in each step such that the function is continuous. Weights are estimated in every step as a proportion
of points that correspond to each of the truncated region.
Optimization is handled by the mle2
function.
A list of class comp_fit.
## Not run: PNP_fit(stocks$SAP) PNP_fit(stocks$MSFT) autoplot(PNP_fit(stocks$ADS)) PNP_fit(stocks$GSPC, method = "BFGS") PNP_fit(stocks$DJI, start = c(-0.01,0.01,0,0.008)) ## End(Not run)
## Not run: PNP_fit(stocks$SAP) PNP_fit(stocks$MSFT) autoplot(PNP_fit(stocks$ADS)) PNP_fit(stocks$GSPC, method = "BFGS") PNP_fit(stocks$DJI, start = c(-0.01,0.01,0,0.008)) ## End(Not run)
The function creates an object which represents the Poisson distribution.
poisdist(lambda = 1)
poisdist(lambda = 1)
lambda |
mean parameter, default: 1. |
See Poisson
.
Object of class poisdist.
P <- poisdist(1) d(P, c(2, 3, 4, NA)) r(P, 5)
P <- poisdist(1) d(P, c(2, 3, 4, NA)) r(P, 5)
q_approxfun
is a generic function that for a given object generates function to approximate the quantile function.
q_approxfun(O, range = q(O, c(0.005, 0.995)), n = 1000) ## S3 method for class 'dist' q_approxfun(O, range = q(O, c(0.005, 0.995)), n = 1000)
q_approxfun(O, range = q(O, c(0.005, 0.995)), n = 1000) ## S3 method for class 'dist' q_approxfun(O, range = q(O, c(0.005, 0.995)), n = 1000)
O |
distribution object. |
range |
interval on which the grid is defined, q(O, c(0.005, 0.995)). |
n |
number of points within the grid, default: 1000. |
Function q_approxfun
generates a grid of values on which the CDF of the object is evaluated.
The function returns a quantile function that uses approx
and the values
of the grid to approximate the quantiles. This function is designed mostly for the mixture distributions
where the standard q
method may be slow and thus allows to trade the accuracy for the speed.
The returned function takes the arguments p
, lower.tail
and log.p
, see q
.
Function.
N <- normdist(1, 3) N2 <- normdist(8, 3) M <- mixdist(N, N2, weights = c(0.5, 0.5)) q_app <- q_approxfun(M) q_app(c(.2, .5, .7)) q_app(c(.2, .5, .7), lower.tail = FALSE)
N <- normdist(1, 3) N2 <- normdist(8, 3) M <- mixdist(N, N2, weights = c(0.5, 0.5)) q_app <- q_approxfun(M) q_app(c(.2, .5, .7)) q_app(c(.2, .5, .7), lower.tail = FALSE)
q
is a generic function that evaluates the quantile function of a distribution object at given values.
## S3 method for class 'compdist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...) q(O, p, lower.tail = TRUE, log.p = FALSE, ...) ## S3 method for class 'standist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...) ## S3 method for class 'trans_univdist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...)
## S3 method for class 'compdist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...) q(O, p, lower.tail = TRUE, log.p = FALSE, ...) ## S3 method for class 'standist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...) ## S3 method for class 'trans_univdist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...)
O |
distribution object. |
p |
vector of probabilities. |
lower.tail |
logical; if TRUE, probabilities are |
log.p |
logical; if TRUE, probabilities |
... |
further arguments to be passed. |
Methods of q
function evaluates any offered
distribution from package mistr
. The function makes use of the q[sufix] functions
as qnorm
or qbeta
and thus, if a new distribution is added,
these functions must be reachable through the search path.
The mixture method q.mixdist
and the default
method q.default
have its own help page.
Vector of computed results.
N <- normdist(1, 3) q(N, c(NA, 1, 3, 5)) C <- cauchydist() CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 q(CCC, c(NA, 1, 3, 5))
N <- normdist(1, 3) q(N, c(NA, 1, 3, 5)) C <- cauchydist() CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 q(CCC, c(NA, 1, 3, 5))
The default method q.default
terminates the current R session.
## Default S3 method: q( O = save, p = status, lower.tail = runLast, log.p = FALSE, save = "default", status = 0, runLast = TRUE, ... )
## Default S3 method: q( O = save, p = status, lower.tail = runLast, log.p = FALSE, save = "default", status = 0, runLast = TRUE, ... )
O |
place holder for generic, by default set to save, default: save. |
p |
place holder for generic, by default set to status, default: status. |
lower.tail |
place holder for generic, by default set to runLast, default: runLast. |
log.p |
place holder for generic, default: FALSE. |
save |
a character string indicating whether the environment (workspace) should be saved, one of "no", "yes", "ask" or "default", default: 'default'. |
status |
the (numerical) error status to be returned to the operating system, where relevant. Conventionally 0 indicates successful completion, default: 0. |
runLast |
should .Last() be executed?, default: TRUE. |
... |
further arguments to be passed. |
This method is designed to quit R if the q()
without a distribution is called.
The reason for such an implementation is R-Studio in Linux and Mac systems, where
the software calls q()
(rather than base::q()
) once the R-Studio window
is closed. Such implementation solves the issued with the overwriting of q()
.
q.mixdist
is a method that evaluates the quantile function of a mixture distribution object at given values.
## S3 method for class 'mixdist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...)
## S3 method for class 'mixdist' q(O, p, lower.tail = TRUE, log.p = FALSE, ...)
O |
mixture distribution object. |
p |
vector of probabilities. |
lower.tail |
logical; if TRUE, probabilities are |
log.p |
logical; if TRUE, probabilities |
... |
further arguments to be passed. |
Methods of q
function evaluates any offered
distribution from the package mistr
. The function makes use of the p[sufix] and q[sufix] functions
as pnorm
or qbeta
and thus, if a new distribution is added,
these functions must be reachable through the search path.
The values are numerically found using the uniroot
function, while the starting intervals are found
automatically. The option parameter tol
specifies the tolerance for the uniroot
.
Options parameter sub
is used to test whether the CDF at computed values minus sub
is not the same and thus the given value is not an
infimum. In such case, the root is found one more time for the value p - sub
.
Other methods q
and the default
method q.default
have its own help page.
Vector of computed results.
DM <- mixdist(3*binomdist(12, 0.4), -2*poisdist(2)+12, weights=c(0.5, 0.5)) y <- c(0.4, p(DM, c(5, 10, 15, 18)), 0.95) x <- q(DM, y) plot(DM, which = "cdf", only_mix=TRUE, xlim1 = c(0, 37)) points(x, y)
DM <- mixdist(3*binomdist(12, 0.4), -2*poisdist(2)+12, weights=c(0.5, 0.5)) y <- c(0.4, p(DM, c(5, 10, 15, 18)), 0.95) x <- q(DM, y) plot(DM, which = "cdf", only_mix=TRUE, xlim1 = c(0, 37)) points(x, y)
qlim
is a generic function that evaluates the right-hand limit of quantile function
for a distribution object at given values.
## S3 method for class 'compdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'discrdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'trans_univdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE)
## S3 method for class 'compdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'discrdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'trans_univdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE)
O |
distribution object. |
p |
vector of probabilities. |
lower.tail |
logical; if TRUE, probabilities are |
log.p |
logical; if TRUE, probabilities |
Methods of qlim
function evaluates the right-hand limit of any offered
distribution object from the package mistr
. The right-hand limit
of a quantile function is defined as
The function makes use of the p[sufix] and q[sufix] functions
as pnorm
, pbeta
, qnorm
, qbeta
, and thus, if a new distribution is added,
these functions must be reachable through the search path.
Methods for mixtures
have its own help page.
Vector of computed results.
B <- binomdist(10, 0.3) qlim(B, plim(B, c(NA, 1, 3, 5))) P <- poisdist() M <- mixdist(B, P, weights = c(0.5, 0.5)) qlim(M, plim(M, c(NA, 1, 3, 5))) CC <- compdist(B, P, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*CC+5 qlim(CCC, plim(CCC, c(NA, 1, 3, 5)))
B <- binomdist(10, 0.3) qlim(B, plim(B, c(NA, 1, 3, 5))) P <- poisdist() M <- mixdist(B, P, weights = c(0.5, 0.5)) qlim(M, plim(M, c(NA, 1, 3, 5))) CC <- compdist(B, P, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*CC+5 qlim(CCC, plim(CCC, c(NA, 1, 3, 5)))
qlim.mixdist
is a method that evaluates the right-hand limit of quantile function for a mixture distribution object at given values.
## S3 method for class 'discrmixdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contdiscrmixdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contmixdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE)
## S3 method for class 'discrmixdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contdiscrmixdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE) ## S3 method for class 'contmixdist' qlim(O, p, lower.tail = TRUE, log.p = FALSE)
O |
mixture distribution object. |
p |
vector of probabilities. |
lower.tail |
logical; if TRUE, probabilities are |
log.p |
logical; if TRUE, probabilities |
Methods of qlim
function evaluates the right-hand limit of a quantile function for any offered
distribution object from the package mistr
. The right-hand limit
of a quantile function is defined as
The function makes use of the p[sufix] and q[sufix] functions
as pnorm
, pbeta
, qnorm
, qbeta
, and thus, if a new distribution will be added,
these functions must be reachable through the search path.
The values are numerically found using the uniroot
function, while the starting intervals are found
automatically. The option parameter tol
specifies the tolerance for the uniroot
.
Options parameter sub
is used to test whether the CDF at computed value minus sub
is not the same and thus the given value is not an
infimum. In such case, the root is found one more time for the value p - sub
.
Other methods qlim
have its own help page.
Vector of computed results.
# q() of a negative transformed random variable uses qlim() DM <- mixdist(3*binomdist(12,0.4), -2*poisdist(2)+12, weights=c(0.5, 0.5)) y <- c(0.05, 0.4, p(-DM, c(-5, -10, -15, -18)), 0.95) x <- q(-DM, y) plot(-DM, which = "cdf", only_mix=TRUE, xlim1 = c(-37, 0)) points(x, y)
# q() of a negative transformed random variable uses qlim() DM <- mixdist(3*binomdist(12,0.4), -2*poisdist(2)+12, weights=c(0.5, 0.5)) y <- c(0.05, 0.4, p(-DM, c(-5, -10, -15, -18)), 0.95) x <- q(-DM, y) plot(-DM, which = "cdf", only_mix=TRUE, xlim1 = c(-37, 0)) points(x, y)
QQplot is a generic function that produces QQ plot of two datasets, distribution and dataset or two distributions.
QQplot( d1, d2, line = TRUE, col = "#122e94", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab, main = "Q-Q plot", lwd = 2, ... ) ## Default S3 method: QQplot( d1, d2, line = TRUE, col = "#122e94", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = deparse(substitute(d2)), main = "Q-Q plot", lwd = 2, ... ) ## S3 method for class 'dist' QQplot( d1, d2, line = TRUE, col = "#122e94", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = ylabe, main = "Q-Q plot", lwd = 2, CI = re, conf = 0.95, n = 100, CI_col = "grey80", ... ) QQnorm(d2, xlab = "Standard Normal", ylab = deparse(substitute(d2)), ...)
QQplot( d1, d2, line = TRUE, col = "#122e94", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab, main = "Q-Q plot", lwd = 2, ... ) ## Default S3 method: QQplot( d1, d2, line = TRUE, col = "#122e94", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = deparse(substitute(d2)), main = "Q-Q plot", lwd = 2, ... ) ## S3 method for class 'dist' QQplot( d1, d2, line = TRUE, col = "#122e94", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = ylabe, main = "Q-Q plot", lwd = 2, CI = re, conf = 0.95, n = 100, CI_col = "grey80", ... ) QQnorm(d2, xlab = "Standard Normal", ylab = deparse(substitute(d2)), ...)
d1 |
distribution object or dataset. |
d2 |
distribution object or dataset. |
line |
if qqline should be included, default: TRUE. |
col |
color of points, default: '#122e94'. |
line_col |
color of qqline, default: '#f28df9'. |
xlab |
xlab, default: deparse(substitute(d1)). |
ylab |
ylab, default: deparse(substitute(d2)). |
main |
title, default: 'Q-Q plot'. |
lwd |
lwd of qqline, default: 2. |
... |
further arguments to be passed. |
CI |
if confidence bound should be included. |
conf |
confidence level for confidence bound, default: 0.95. |
n |
number of points at which quantile functions are evaluated if two distributions are compared, default: 100. |
CI_col |
color of confidence bound, default: 'grey80'. |
QQplot
is able to compare any combination of dataset and distributions.
QQnorm
is a wrapper around QQplot
, where d1 is set to normdist()
.
If quantiles of a continuous distribution are compared with a sample, a confidence bound for data is offered. This confidence "envelope" is based on the asymptotic results of the order statistics. For more details see https://en.wikipedia.org/wiki/Order_statistic.
# sample vs sample QQplot(r(normdist(), 10000), r(tdist(df = 4), 10000)) # distribution vs sample QQplot(normdist(), r(tdist(df = 4), 10000)) # distribution vs distribution QQplot(normdist(), tdist(df = 4))
# sample vs sample QQplot(r(normdist(), 10000), r(tdist(df = 4), 10000)) # distribution vs sample QQplot(normdist(), r(tdist(df = 4), 10000)) # distribution vs distribution QQplot(normdist(), tdist(df = 4))
QQplotgg is a generic function that produces QQ plot of two datasets, distribution and dataset or two distributions.
QQplotgg( d1, d2, line = TRUE, col = "#F9D607", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab, main = "Q-Q plot", alpha, lwd = 1, ... ) ## Default S3 method: QQplotgg( d1, d2, line = TRUE, col = "#F9D607", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = deparse(substitute(d2)), main = "Q-Q plot", alpha = 0.5, lwd = 1, ... ) ## S3 method for class 'dist' QQplotgg( d1, d2, line = TRUE, col = "#F9D607", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = ylabe, main = "Q-Q plot", alpha = 0.7, lwd = 1, CI = re, CI_alpha = 0.4, CI_col = line_col, conf = 0.95, n = 100, ... ) QQnormgg(d2, xlab = "Standard Normal", ylab = deparse(substitute(d2)), ...)
QQplotgg( d1, d2, line = TRUE, col = "#F9D607", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab, main = "Q-Q plot", alpha, lwd = 1, ... ) ## Default S3 method: QQplotgg( d1, d2, line = TRUE, col = "#F9D607", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = deparse(substitute(d2)), main = "Q-Q plot", alpha = 0.5, lwd = 1, ... ) ## S3 method for class 'dist' QQplotgg( d1, d2, line = TRUE, col = "#F9D607", line_col = "#f28df9", xlab = deparse(substitute(d1)), ylab = ylabe, main = "Q-Q plot", alpha = 0.7, lwd = 1, CI = re, CI_alpha = 0.4, CI_col = line_col, conf = 0.95, n = 100, ... ) QQnormgg(d2, xlab = "Standard Normal", ylab = deparse(substitute(d2)), ...)
d1 |
distribution object or dataset. |
d2 |
distribution object or dataset. |
line |
if qqline should be included, default: TRUE. |
col |
color of points, default: '#F9D607'. |
line_col |
color of qqline, default: '#f28df9'. |
xlab |
xlab, default: deparse(substitute(d1)). |
ylab |
ylab. default: deparse(substitute(d2)). |
main |
title, default: 'Q-Q plot'. |
alpha |
alpha of points, default: 0.7. |
lwd |
lwd of qqline, default: 1. |
... |
further arguments to be passed. |
CI |
if confidence bound should be included. |
CI_alpha |
alpha of confidence bound, default: 0.4. |
CI_col |
color of confidence bound , default: line_col. |
conf |
confidence level for confidence bound, default: 0.95. |
n |
number of points at which quantile functions are evaluated if two distributions are compared, default: 100. |
QQplotgg
is able to compare any combination of dataset and distributions.
QQnormgg
is a wrapper around QQplotgg
, where d1 is set to normdist()
.
If quantiles of a continuous distribution are compared with a sample, a confidence bound for data is offered. This confidence "envelope" is based on the asymptotic results of the order statistics. For more details see https://en.wikipedia.org/wiki/Order_statistic.
ggplot object.
# sample vs sample QQplotgg(r(normdist(), 10000), r(tdist(df = 4), 10000)) # distribution vs sample QQplotgg(normdist(), r(tdist(df = 4), 10000)) # distribution vs distribution QQplotgg(normdist(), tdist(df = 4))
# sample vs sample QQplotgg(r(normdist(), 10000), r(tdist(df = 4), 10000)) # distribution vs sample QQplotgg(normdist(), r(tdist(df = 4), 10000)) # distribution vs distribution QQplotgg(normdist(), tdist(df = 4))
r
is a generic function that generates random deviates of a distribution object.
## S3 method for class 'compdist' r(O, n) ## S3 method for class 'mixdist' r(O, n) r(O, n) ## S3 method for class 'standist' r(O, n) ## S3 method for class 'hyperdist' r(O, n) ## S3 method for class 'wilcoxdist' r(O, n) ## S3 method for class 'trans_univdist' r(O, n)
## S3 method for class 'compdist' r(O, n) ## S3 method for class 'mixdist' r(O, n) r(O, n) ## S3 method for class 'standist' r(O, n) ## S3 method for class 'hyperdist' r(O, n) ## S3 method for class 'wilcoxdist' r(O, n) ## S3 method for class 'trans_univdist' r(O, n)
O |
distribution object. |
n |
number of observations. |
Methods of r
function generates random deviates of offered
distribution from the package mistr
. The function makes use of the r[sufix] functions
as rnorm
or rbeta
and thus, if a new distribution is added,
these functions must be reachable through the search path.
For more complicated composite distributions, where one of the components is a mixture distribution, the function performs a rejection sampling of mixture random numbers to improve the speed.
Vector of computed results.
N <- normdist(1, 3) r(N, 5) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) r(M, 5) CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 r(CCC, 5)
N <- normdist(1, 3) r(N, 5) C <- cauchydist() M <- mixdist(N, C, weights = c(0.5, 0.5)) r(M, 5) CC <- compdist(N, C, weights = c(0.5, 0.5), breakpoints = 1) CCC <- 2*C+5 r(CCC, 5)
risk
computes the VaR, ES and expectiles at a given level for fitted distribution.
risk( model, alpha, expectile = TRUE, plot = FALSE, ggplot = FALSE, text_ylim = -0.15, size = 1 ) ## S3 method for class 'PNP' risk( model, alpha = 0.05, expectile = TRUE, plot = FALSE, ggplot = FALSE, text_ylim = -0.15, size = 1 ) ## S3 method for class 'GNG' risk( model, alpha = 0.05, expectile = TRUE, plot = FALSE, ggplot = FALSE, text_ylim = -0.15, size = 1 )
risk( model, alpha, expectile = TRUE, plot = FALSE, ggplot = FALSE, text_ylim = -0.15, size = 1 ) ## S3 method for class 'PNP' risk( model, alpha = 0.05, expectile = TRUE, plot = FALSE, ggplot = FALSE, text_ylim = -0.15, size = 1 ) ## S3 method for class 'GNG' risk( model, alpha = 0.05, expectile = TRUE, plot = FALSE, ggplot = FALSE, text_ylim = -0.15, size = 1 )
model |
output object of |
alpha |
levels of risk measures. |
expectile |
logical, if also expectiles should be computed, default: TRUE. |
plot |
plot the results?, default: FALSE. |
ggplot |
plot the results with ggplot2?, default: FALSE. |
text_ylim |
y coordinate for annotation in ggplot2, default: -0.15. |
size |
size of the text indicating the risk measures in the plot, default: 1. |
VaR are computed using the q()
call of the fitted distribution.
ES is computed directly (i.e. the integrals are precomputed, not numerically) as an integral of the quantile function.
Expectiles can be obtained as a unit-root solution of the identity between quantiles
and expectiles. These are equivalent for corresponding and
if
where
is mean,
is the quantile function and
.
List of class risk_measures.
## Not run: GNG <- GNG_fit(stocks$SAP) PNP <- PNP_fit(stocks$MSFT) risk(PNP, alpha = c(0.01,0.05,0.08,0.1)) risk(GNG, alpha = c(0.01,0.05,0.08,0.1), plot = TRUE) ## End(Not run)
## Not run: GNG <- GNG_fit(stocks$SAP) PNP <- PNP_fit(stocks$MSFT) risk(PNP, alpha = c(0.01,0.05,0.08,0.1)) risk(GNG, alpha = c(0.01,0.05,0.08,0.1), plot = TRUE) ## End(Not run)
Function can be used to set the parameters used in mistr
.
set_opt(...)
set_opt(...)
... |
arguments in tag = value form, or a list of tagged values. |
The function can set the values for:
sub parameter: small value that is used in mixture quantile function to test if the computed value is infimum, default: 1e-10.
add parameter: small value that is added to values that are in the image of CDF in qlim
function, default: 1e-08.
tol parameter: tolerance for uniroot used in mixture quantile function, default: .Machine$double.eps^0.5.
When parameters are set, their previous values are returned in an invisible named list.
a <- set_opt(sub = 1e-5, tol = 1e-10) get_opt("sub", "tol") set_opt(a)
a <- set_opt(sub = 1e-5, tol = 1e-10) get_opt("sub", "tol") set_opt(a)
A dataset containing the log-returns of adjusted closing prices from 04.01.2007 to 30.10.2017. The dataset contains data of Microsoft, SAP, Adidas, S&P 500 (index) and Dow Jones Industrial Average (index).
stocks
stocks
A data frame with 2726 rows and 5 variables:
Microsoft Corporation
Systems, Applications & Products in Data Processing
Adidas
S&P 500
Dow Jones Industrial Average
Package: quantmod
sudo_support
is a generic function that returns the two boundary values
of object's support.
sudo_support(O) ## S3 method for class 'discrdist' sudo_support(O) ## S3 method for class 'contdist' sudo_support(O) ## S3 method for class 'mixdist' sudo_support(O) ## S3 method for class 'compdist' sudo_support(O) ## S3 method for class 'trans_univdist' sudo_support(O)
sudo_support(O) ## S3 method for class 'discrdist' sudo_support(O) ## S3 method for class 'contdist' sudo_support(O) ## S3 method for class 'mixdist' sudo_support(O) ## S3 method for class 'compdist' sudo_support(O) ## S3 method for class 'trans_univdist' sudo_support(O)
O |
distribution object. |
Methods of sudo_support
function calculate the support's boundary
values for any distribution in the package mistr
. This technique
is particularly useful when dealing with a transformed distribution.
Named vector containing two values.
B <- binomdist(10, 0.3) sudo_support(B) B2 <- -3*log(B) sudo_support(B2) sudo_support( mixdist(B2, normdist(), weights = c(0.5, 0.5)))
B <- binomdist(10, 0.3) sudo_support(B) B2 <- -3*log(B) sudo_support(B2) sudo_support( mixdist(B2, normdist(), weights = c(0.5, 0.5)))
Displays a useful description of a fitted object.
## S3 method for class 'comp_fit' summary(object, ...)
## S3 method for class 'comp_fit' summary(object, ...)
object |
distribution object to summarize. |
... |
additional arguments. |
Function returns summary of the fit, offered by bbmle package for class mle2-class
.
The function creates an object which represents the Student-t distribution.
tdist(df = 2)
tdist(df = 2)
df |
degrees of freedom parameter, default: 2. |
See TDist
.
Object of class tdist.
t <- tdist(2) d(t, c(2, 3, 4, NA)) r(t, 5)
t <- tdist(2) d(t, c(2, 3, 4, NA)) r(t, 5)
The function modifies the given object and adds the transformation expressions.
trafo(O, type = "new", trans, invtrans, print, deriv, operation, value = 0)
trafo(O, type = "new", trans, invtrans, print, deriv, operation, value = 0)
O |
distribution object. |
type |
type of modification to be performed, default: 'new'. |
trans |
transformation expression. |
invtrans |
inverse transformation expression. |
print |
print expression. |
deriv |
derivative expression. |
operation |
string indicating which operation is performed. |
value |
numeric value used in operation, default: 0. |
trafo
is the main function used in the transformation framework. The function
offers four types of possible modifications. Note, that all expressions must use X to indicate the object in the transformation.
type = "init": Initializes the needed lists for transformations and adds the first expressions. This type should be used only with yet untransformed distributions as the first modification. All arguments must be set.
type = "new": Adds a new transformation to the current ones. This must be used only on already transformed distributions. All arguments must be set.
type = "update": Updates previous expression. This is useful when same transformation is used twice in a row. All arguments except operation must be set.
type = "go_back": Uses to history to reverse the previous transformation. Useful if inverse of previous transformation is evaluated. Only object and type must be specified.
Transformed distribution object.
#init P <- poisdist(5) ; x <- 5 P2 <- trafo(P, type = "init", trans = bquote(X + .(x)), invtrans = bquote(X - .(x)), print = bquote(X + .(x)), deriv = quote(1), operation = "+", value = x) P2 #new x = 3 P3 <- trafo(P2, type = "new", trans = bquote(.(x) * X), invtrans = bquote(X/.(x)), print = bquote(.(x) * X), deriv = bquote(1/.(x)), operation = "*", value = x) P3 #update x = 7 P4 <- trafo(P3, type = "update", trans = bquote(.(x) * X), invtrans = bquote(X/.(x)), print = bquote(.(x) * X), deriv = bquote(1/.(x)), value = x) P4 #go_back P5 <- trafo(P4, type = "go_back") P5
#init P <- poisdist(5) ; x <- 5 P2 <- trafo(P, type = "init", trans = bquote(X + .(x)), invtrans = bquote(X - .(x)), print = bquote(X + .(x)), deriv = quote(1), operation = "+", value = x) P2 #new x = 3 P3 <- trafo(P2, type = "new", trans = bquote(.(x) * X), invtrans = bquote(X/.(x)), print = bquote(.(x) * X), deriv = bquote(1/.(x)), operation = "*", value = x) P3 #update x = 7 P4 <- trafo(P3, type = "update", trans = bquote(.(x) * X), invtrans = bquote(X/.(x)), print = bquote(.(x) * X), deriv = bquote(1/.(x)), value = x) P4 #go_back P5 <- trafo(P4, type = "go_back") P5
The function creates an object which represents the uniform distribution.
unifdist(min = 0, max = 1)
unifdist(min = 0, max = 1)
min |
minimum parameter, default: 0. |
max |
maximum parameter, default: 1. |
See Uniform
.
Object of class unifdist.
U <- unifdist(1, 5) d(U, c(2, 3, 4, NA)) r(U, 5)
U <- unifdist(1, 5) d(U, c(2, 3, 4, NA)) r(U, 5)
untrafo
is a generic function that returns the untransformed random variable, if a transformed object
is given.
untrafo(O) ## S3 method for class 'trans_standist' untrafo(O) ## S3 method for class 'trans_mixdist' untrafo(O) ## S3 method for class 'trans_compdist' untrafo(O)
untrafo(O) ## S3 method for class 'trans_standist' untrafo(O) ## S3 method for class 'trans_mixdist' untrafo(O) ## S3 method for class 'trans_compdist' untrafo(O)
O |
transformed distribution object. |
Untransformed distribution object.
B <- binomdist(10, 0.3) B2 <- -3*log(B) B2 untrafo(B2)
B <- binomdist(10, 0.3) B2 <- -3*log(B) B2 untrafo(B2)
The function creates an object which represents the Weibull distribution.
weibulldist(shape = 1, scale = 1)
weibulldist(shape = 1, scale = 1)
shape |
shape parameter, default: 1. |
scale |
scale parameter, default: 1. |
See Weibull
.
Object of class weibulldist.
W <- weibulldist(1, 1) d(W, c(2, 3, 4, NA)) r(W, 5)
W <- weibulldist(1, 1) d(W, c(2, 3, 4, NA)) r(W, 5)
The function creates an object which represents the Wilcoxon distribution.
wilcoxdist(m, n)
wilcoxdist(m, n)
m |
number of observations in the first sample. |
n |
number of observations in the second sample. |
See Wilcoxon
.
Object of class wilcoxdist.
W <- wilcoxdist(20, 15) d(W, c(2, 3, 4, NA)) r(W, 5)
W <- wilcoxdist(20, 15) d(W, c(2, 3, 4, NA)) r(W, 5)