Title: | Pearson Distribution System |
---|---|
Description: | Implementation of the Pearson distribution system, including full support for the (d,p,q,r)-family of functions for probability distributions and fitting via method of moments and maximum likelihood method. |
Authors: | Martin Becker [aut, cre] , Stefan Klößner [aut] , Joel Heinrich [ctb] |
Maintainer: | Martin Becker <[email protected]> |
License: | GPL (>= 2) |
Version: | 1.3.1 |
Built: | 2025-01-29 06:09:19 UTC |
Source: | https://github.com/cran/PearsonDS |
Implementation of the d,p,q,r
function family, calculation of moments,
and fitting via (empirical) moment matching as well as maximum likelihood
method for the Pearson distribution system.
If at all possible, package gsl
should be installed.
In this case, the functions for Pearson type IV
distributions make use of lngamma_complex
(see Gamma
).
If package gsl
is not installed, some
calculations for Pearson type IV distributions with (more or less) extreme
parameters (ie, big nu
and/or m
) may slow down by factors of
more than 1000.
Martin Becker [email protected] and Stefan Klößner [email protected]
Maintainer: Martin Becker [email protected]
[1] Abramowitz, M. and I. A. Stegun (1972) Handbook of mathematical functions, National Bureau of Standards, Applied Mathematics Series - 55, Tenth Printing, Washington D.C.
[2] Heinrich, J. (2004) A Guide to the Pearson Type IV Distribution, Univ. Pennsylvania, Philadelphia, Tech. Rep. CDF/Memo/Statistics/Public/6820 http://www-cdf.fnal.gov/physics/statistics/notes/cdf6820_pearson4.pdf
[3] Hida, Y., X. S. Li and D. H. Bailey (2000) Algorithms for quad-double precision floating point arithmetic, Lawrence Berkeley National Laboratory. Paper LBNL-48597.
[4] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 1, Wiley Series in Probability and Mathematical Statistics, Wiley
[5] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 2, Wiley Series in Probability and Mathematical Statistics, Wiley
[6] Willink, R. (2008) A Closed-form Expression for the Pearson Type IV Distribution Function, Aust. N. Z. J. Stat. 50 (2), pp. 199-205
Pearson
for d,p,q,r
function family for Pearson
distributions,
pearsonFitM
and pearsonFitML
for fitting
Pearson distributions,
pearsonMSC
for model selection,
pearsonMoments
for calculation of (first four) moments.
## see documentation of individual functions
## see documentation of individual functions
Calculates the first four empirical moments (mean, variance, skewness, kurtosis) of a numeric vector.
empMoments(x)
empMoments(x)
x |
(numeric) vector containing the data set. |
Named vector of length 4 containing mean
, variance
,
skewness
and kurtosis
(in this order).
Martin Becker [email protected]
## Generate sample with given (theoretical) moments DATA <- rpearson(25000,moments=c(mean=1,variance=2,skewness=1,kurtosis=5)) ## Calculate corresponding empirical moments empMoments(DATA)
## Generate sample with given (theoretical) moments DATA <- rpearson(25000,moments=c(mean=1,variance=2,skewness=1,kurtosis=5)) ## Calculate corresponding empirical moments empMoments(DATA)
For a given incomplete (skewness or kurtosis are missing) set of moments, the complete set of moments (mean, variance, skewness, and kurtosis) is calculated, using a given distribution type (if possible). Either the complete set of moments or the distribution parameters are returned.
matchMoments(mean, variance, skewness = NA, kurtosis = NA, type, moments, skewness.sign = c("+", "-"), return.distribution = FALSE)
matchMoments(mean, variance, skewness = NA, kurtosis = NA, type, moments, skewness.sign = c("+", "-"), return.distribution = FALSE)
mean |
target mean. |
variance |
target variance. |
skewness |
target skewness (maybe |
kurtosis |
target kurtosis (not excess kurtosis, maybe |
type |
required distribution type (either one of the numbers 0, 1, ..., 7 or one of
|
moments |
optional vector/list of mean, variance, skewness, kurtosis (not excess
kurtosis) in this order. Overrides the input parameters |
skewness.sign |
|
return.distribution |
|
If return.distribution==TRUE
: list of parameters for Pearson
distribution. First entry gives type of distribution (0 for type 0,
1 for type I, ..., 7 for type VII), remaining entries give distribution
parameters (depending on distribution type).
If return.distribution==FALSE
: numeric vector with named elements
mean
, variance
, skewness
, kurtosis
corresponding
to a Pearson distribution of type type
.
If the specified subset of moments does not match the distribution type or if too many moments are missing, an error is issued.
Martin Becker [email protected]
[1] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 1, Wiley Series in Probability and Mathematical Statistics, Wiley
[2] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 2, Wiley Series in Probability and Mathematical Statistics, Wiley
PearsonDS-package
,
Pearson
,
pearsonFitM
,
pearsonMoments
matchMoments(mean=0,variance=1,kurtosis=4.5,type=3,return.distribution = TRUE) matchMoments(mean=0,variance=1,kurtosis=4.5,type="III") matchMoments(mean=0,variance=1,kurtosis=4.5,type="III",skewness.sign="-") matchMoments(mean=0,variance=1,skewness=-2,type="III",return.distribution = TRUE) pearsonFitM(moments=matchMoments(mean=0,variance=1,skewness=-2,type="III")) matchMoments(mean=0,variance=1,skewness=-2,type="III")
matchMoments(mean=0,variance=1,kurtosis=4.5,type=3,return.distribution = TRUE) matchMoments(mean=0,variance=1,kurtosis=4.5,type="III") matchMoments(mean=0,variance=1,kurtosis=4.5,type="III",skewness.sign="-") matchMoments(mean=0,variance=1,skewness=-2,type="III",return.distribution = TRUE) pearsonFitM(moments=matchMoments(mean=0,variance=1,skewness=-2,type="III")) matchMoments(mean=0,variance=1,skewness=-2,type="III")
Density, distribution function, quantile function and random generation for the Pearson distribution system.
dpearson(x, params, moments, log = FALSE, ...) ppearson(q, params, moments, lower.tail = TRUE, log.p = FALSE, ...) qpearson(p, params, moments, lower.tail = TRUE, log.p = FALSE, ...) rpearson(n, params, moments, ...)
dpearson(x, params, moments, log = FALSE, ...) ppearson(q, params, moments, lower.tail = TRUE, log.p = FALSE, ...) qpearson(p, params, moments, lower.tail = TRUE, log.p = FALSE, ...) rpearson(n, params, moments, ...)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
params |
vector/list of parameters for Pearson distribution. First entry gives type of distribution (0 for type 0, 1 for type I, ..., 7 for type VII), remaining entries give distribution parameters (depending on distribution type). |
moments |
optional vector/list of mean, variance, skewness, kurtosis
(not excess kurtosis).
Overrides |
log , log.p
|
logical; if |
lower.tail |
logical; if |
... |
further parameters for underlying functions (currently only used for distributions of type IV). |
These are the wrapper functions for the (d,p,q,r)-functions of the Pearson distribution system sub-classes.
dpearson
gives the density, ppearson
gives the distribution
function, qpearson
gives the quantile function, and rpearson
generates random deviates.
Martin Becker [email protected]
PearsonDS-package
,
Pearson0
, PearsonI
, PearsonII
,
PearsonIII
, PearsonIV
, PearsonV
,
PearsonVI
, PearsonVII
, pearsonFitM
,
pearsonFitML
, pearsonMSC
## Define moments of distribution moments <- c(mean=1,variance=2,skewness=1,kurtosis=5) ## Generate some random variates rpearson(5,moments=moments) ## evaluate distribution function ppearson(seq(-2,3,by=1),moments=moments) ## evaluate density function dpearson(seq(-2,3,by=1),moments=moments) ## evaluate quantile function qpearson(seq(0.1,0.9,by=0.2),moments=moments)
## Define moments of distribution moments <- c(mean=1,variance=2,skewness=1,kurtosis=5) ## Generate some random variates rpearson(5,moments=moments) ## evaluate distribution function ppearson(seq(-2,3,by=1),moments=moments) ## evaluate density function dpearson(seq(-2,3,by=1),moments=moments) ## evaluate quantile function qpearson(seq(0.1,0.9,by=0.2),moments=moments)
Density, distribution function, quantile function and random generation for the Pearson type 0 (aka Normal) distribution.
dpearson0(x, mean, sd, params, log = FALSE) ppearson0(q, mean, sd, params, lower.tail = TRUE, log.p = FALSE) qpearson0(p, mean, sd, params, lower.tail = TRUE, log.p = FALSE) rpearson0(n, mean, sd, params)
dpearson0(x, mean, sd, params, log = FALSE) ppearson0(q, mean, sd, params, lower.tail = TRUE, log.p = FALSE) qpearson0(p, mean, sd, params, lower.tail = TRUE, log.p = FALSE) rpearson0(n, mean, sd, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
mean |
location parameter (and expectation) |
sd |
scale parameter (and standard deviation) |
params |
optional vector/list containing distribution parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
Distributions of type 0 have been added to the Pearson Distribution system
in order to have the normal distributions not only nested as limits of other
distribution types.
The functions are only wrappers for dnorm
, pnorm
, qnorm
and rnorm
contained in package stats
.
dpearson0
gives the density, ppearson0
gives the distribution
function, qpearson0
gives the quantile function, and rpearson0
generates random deviates.
Martin Becker [email protected]
See the references in Normal
.
Normal
,
PearsonDS-package
,
Pearson
## define Pearson type 0 parameter set with mean=-1, sd=2 p0pars <- list(mean=-1, sd=2) ## calculate probability density function dpearson0(-4:1,params=p0pars) ## calculate cumulative distribution function ppearson0(-4:1,params=p0pars) ## calculate quantile function qpearson0(seq(0.1,0.9,by=0.2),params=p0pars) ## generate random numbers rpearson0(5,params=p0pars)
## define Pearson type 0 parameter set with mean=-1, sd=2 p0pars <- list(mean=-1, sd=2) ## calculate probability density function dpearson0(-4:1,params=p0pars) ## calculate cumulative distribution function ppearson0(-4:1,params=p0pars) ## calculate quantile function qpearson0(seq(0.1,0.9,by=0.2),params=p0pars) ## generate random numbers rpearson0(5,params=p0pars)
2D-Plot of the regions for the different types of Pearson distributions, depending on (squared) skewness and kurtosis.
pearsonDiagram(max.skewness = sqrt(14), max.kurtosis = 24, squared.skewness = TRUE, lwd = 2, legend = TRUE, n = 301)
pearsonDiagram(max.skewness = sqrt(14), max.kurtosis = 24, squared.skewness = TRUE, lwd = 2, legend = TRUE, n = 301)
max.skewness |
maximal value for the skewness. |
max.kurtosis |
maximal value for the kurtosis (not excess kurtosis!). |
squared.skewness |
plot squared skewness on x-axis (default: |
lwd |
line width for distributions of type II, III, V, VII. |
legend |
include legend in the plot (default: |
n |
number of points for |
The label of the x-axis is for squared skewness and
for regular skewness. The label of the
y-axis is
.
Nothing useful. Function called for its side-effects.
Martin Becker [email protected] and Stefan Klößner [email protected]
[1] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 1, Wiley Series in Probability and Mathematical Statistics, Wiley
## Show me the regions for the different distribution types! pearsonDiagram()
## Show me the regions for the different distribution types! pearsonDiagram()
This function calculates the method of moments estimator for Pearson distribution, ie, it generates a Pearson distribution with moments exactly (up to rounding errors) matching the input moments mean, variance, skewness and kurtosis.
pearsonFitM(mean, variance, skewness, kurtosis, moments)
pearsonFitM(mean, variance, skewness, kurtosis, moments)
mean |
target mean. |
variance |
target variance. |
skewness |
target skewness. |
kurtosis |
target kurtosis (not excess kurtosis!). |
moments |
optional vector/list of mean, variance, skewness, kurtosis (not excess kurtosis) in this order. Overrides all other input parameters, if given. |
List of parameters for Pearson distribution. First entry gives type of distribution (0 for type 0, 1 for type I, ..., 7 for type VII), remaining entries give distribution parameters (depending on distribution type).
Martin Becker [email protected]
[1] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 1, Wiley Series in Probability and Mathematical Statistics, Wiley
[2] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 2, Wiley Series in Probability and Mathematical Statistics, Wiley
PearsonDS-package
,
Pearson
,
pearsonFitML
,
pearsonMoments
,
pearsonMSC
## Define moments of distribution moments <- c(mean=1,variance=2,skewness=1,kurtosis=5) ## find Pearson distribution with these parameters ppar <- pearsonFitM(moments=moments) print(unlist(ppar)) ## check moments pearsonMoments(params=ppar)
## Define moments of distribution moments <- c(mean=1,variance=2,skewness=1,kurtosis=5) ## find Pearson distribution with these parameters ppar <- pearsonFitM(moments=moments) print(unlist(ppar)) ## check moments pearsonMoments(params=ppar)
This function tries to find the Maximum Likelihood estimator within the
Pearson distribution system. ML estimation is done for all sub-classes of
the distribution system via numerical optimization
(with nlminb
). The sub-class with the
optimal likelihood function value and the corresponding parameters are
returned.
pearsonFitML(x, ...)
pearsonFitML(x, ...)
x |
empirical data (numerical vector) for MLE. |
... |
parameters for |
Starting values for each sub-class are found in a three-step procedure. First, the empirical moments of the input vector are calculated. In the second step, the moments are altered, such that the moment restrictions for the current sub-class are fulfilled (if necessary), and the method of moments estimator is calculated to obtain starting values for the optimizer. In the last step, the starting values are adjusted (if necessary) in order to assure that the whole sample lies in the support of the distribution.
List of parameters for Pearson distribution. First entry gives type of distribution (0 for type 0, 1 for type I, ..., 7 for type VII), remaining entries give distribution parameters (depending on distribution type).
The implementation is VERY preliminary (and slow). No analytical results are used, ie. no analytical solutions for ML estimators and no analytical gradients. Most of the distribution types (0, II, III, V, VII) should rather be neglected (for speed reasons), because they will contain the MLE with probability of 0.
Martin Becker [email protected]
[1] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 1, Wiley Series in Probability and Mathematical Statistics, Wiley
[2] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 2, Wiley Series in Probability and Mathematical Statistics, Wiley
PearsonDS-package
,
Pearson
,
pearsonFitM
,
pearsonMSC
,
pearsonMoments
## Generate sample DATA <- rpearson(1000,moments=c(mean=1,variance=2,skewness=1,kurtosis=5)) ## find Pearson distribution with these parameters ppar <- pearsonFitML(DATA) print(unlist(ppar)) ## compare with method of moments estimator print(unlist(pearsonFitM(moments=empMoments(DATA))))
## Generate sample DATA <- rpearson(1000,moments=c(mean=1,variance=2,skewness=1,kurtosis=5)) ## find Pearson distribution with these parameters ppar <- pearsonFitML(DATA) print(unlist(ppar)) ## compare with method of moments estimator print(unlist(pearsonFitM(moments=empMoments(DATA))))
Density, distribution function, quantile function and random generation for the Pearson type I (aka Beta) distribution.
dpearsonI(x, a, b, location, scale, params, log = FALSE) ppearsonI(q, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonI(p, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonI(n, a, b, location, scale, params)
dpearsonI(x, a, b, location, scale, params, log = FALSE) ppearsonI(q, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonI(p, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonI(n, a, b, location, scale, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
a |
first shape parameter of Pearson type I distribution. |
b |
second shape parameter of Pearson type I distribution. |
location |
location parameter of Pearson type I distribution. |
scale |
scale parameter of Pearson type I distribution. |
params |
vector/list of length 4 containing parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
Essentially, Pearson type I distributions are (location-scale transformations
of) Beta distributions, the above
functions are thus simple wrappers for dbeta
, pbeta
,
qbeta
and rbeta
contained in package stats
.
The probability density function with parameters a
, b
,
scale
and
location
is given by
for ,
,
,
.
dpearsonI
gives the density, ppearsonI
gives the
distribution function, qpearsonI
gives the quantile function,
and rpearsonI
generates random deviates.
Negative values for scale
are not excluded, albeit negative skewness
is usually obtained by switching a
and b
(such that a
>b
) and not by using negative values for
scale
(and a
<b
).
Martin Becker [email protected]
See the references in Beta
.
Beta
,
PearsonDS-package
,
Pearson
## define Pearson type I parameter set with a=2, b=3, location=1, scale=2 pIpars <- list(a=2, b=3, location=1, scale=2) ## calculate probability density function dpearsonI(seq(1,3,by=0.5),params=pIpars) ## calculate cumulative distribution function ppearsonI(seq(1,3,by=0.5),params=pIpars) ## calculate quantile function qpearsonI(seq(0.1,0.9,by=0.2),params=pIpars) ## generate random numbers rpearsonI(5,params=pIpars)
## define Pearson type I parameter set with a=2, b=3, location=1, scale=2 pIpars <- list(a=2, b=3, location=1, scale=2) ## calculate probability density function dpearsonI(seq(1,3,by=0.5),params=pIpars) ## calculate cumulative distribution function ppearsonI(seq(1,3,by=0.5),params=pIpars) ## calculate quantile function qpearsonI(seq(0.1,0.9,by=0.2),params=pIpars) ## generate random numbers rpearsonI(5,params=pIpars)
Density, distribution function, quantile function and random generation for the Pearson type II (aka symmetric Beta) distribution.
dpearsonII(x, a, location, scale, params, log = FALSE) ppearsonII(q, a, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonII(p, a, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonII(n, a, location, scale, params)
dpearsonII(x, a, location, scale, params, log = FALSE) ppearsonII(q, a, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonII(p, a, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonII(n, a, location, scale, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
a |
shape parameter of Pearson type II distribution. |
location |
location parameter of Pearson type II distribution. |
scale |
scale parameter of Pearson type II distribution. |
params |
vector/list of length 3 containing parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
Essentially, Pearson type II distributions are (location-scale transformations
of) symmetric Beta distributions, the above
functions are thus simple wrappers for dbeta
, pbeta
,
qbeta
and rbeta
contained in package stats
.
The probability density function with parameters a
,
scale
and
location
is given by
for ,
,
.
dpearsonII
gives the density, ppearsonII
gives the
distribution function, qpearsonII
gives the quantile function,
and rpearsonII
generates random deviates.
Martin Becker [email protected]
See the references in Beta
.
Beta
,
PearsonDS-package
,
Pearson
## define Pearson type II parameter set with a=2, location=1, scale=2 pIIpars <- list(a=2, location=1, scale=2) ## calculate probability density function dpearsonII(seq(1,3,by=0.5),params=pIIpars) ## calculate cumulative distribution function ppearsonII(seq(1,3,by=0.5),params=pIIpars) ## calculate quantile function qpearsonII(seq(0.1,0.9,by=0.2),params=pIIpars) ## generate random numbers rpearsonII(5,params=pIIpars)
## define Pearson type II parameter set with a=2, location=1, scale=2 pIIpars <- list(a=2, location=1, scale=2) ## calculate probability density function dpearsonII(seq(1,3,by=0.5),params=pIIpars) ## calculate cumulative distribution function ppearsonII(seq(1,3,by=0.5),params=pIIpars) ## calculate quantile function qpearsonII(seq(0.1,0.9,by=0.2),params=pIIpars) ## generate random numbers rpearsonII(5,params=pIIpars)
Density, distribution function, quantile function and random generation for the Pearson type III (aka Gamma) distribution.
dpearsonIII(x, shape, location, scale, params, log = FALSE) ppearsonIII(q, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonIII(p, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonIII(n, shape, location, scale, params)
dpearsonIII(x, shape, location, scale, params, log = FALSE) ppearsonIII(q, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonIII(p, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonIII(n, shape, location, scale, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
shape |
shape parameter of Pearson type III distribution. |
location |
location parameter of Pearson type III distribution. |
scale |
scale parameter of Pearson type III distribution. |
params |
vector/list of length 3 containing parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
Essentially, the above functions are wrappers for dgamma
,
pgamma
, qgamma
and rgamma
contained in package
stats
.
As a minor (but important) extension, negative scale
parameters
(which reflect the distribution at location
) are
permitted to allow for negative skewness.
The probability density function with parameters shape
,
scale
and
location
is thus given by
for ,
and
.
dpearsonIII
gives the density, ppearsonIII
gives the
distribution function, qpearsonIII
gives the quantile function,
and rpearsonIII
generates random deviates.
Martin Becker [email protected]
See the references in GammaDist
.
GammaDist
,
PearsonDS-package
,
Pearson
## define Pearson type III parameter set with shape=3, location=1, scale=-2 pIIIpars <- list(shape=3, location=1, scale=-0.5) ## calculate probability density function dpearsonIII(-4:1,params=pIIIpars) ## calculate cumulative distribution function ppearsonIII(-4:1,params=pIIIpars) ## calculate quantile function qpearsonIII(seq(0.1,0.9,by=0.2),params=pIIIpars) ## generate random numbers rpearsonIII(5,params=pIIIpars)
## define Pearson type III parameter set with shape=3, location=1, scale=-2 pIIIpars <- list(shape=3, location=1, scale=-0.5) ## calculate probability density function dpearsonIII(-4:1,params=pIIIpars) ## calculate cumulative distribution function ppearsonIII(-4:1,params=pIIIpars) ## calculate quantile function qpearsonIII(seq(0.1,0.9,by=0.2),params=pIIIpars) ## generate random numbers rpearsonIII(5,params=pIIIpars)
Density, distribution function, quantile function and random generation for the Pearson type IV distribution.
dpearsonIV(x, m, nu, location, scale, params, log = FALSE) ppearsonIV(q, m, nu, location, scale, params, lower.tail = TRUE, log.p = FALSE, tol = 1e-08, ...) qpearsonIV(p, m, nu, location, scale, params, lower.tail = TRUE, log.p = FALSE, tol = 1e-08, ...) rpearsonIV(n, m, nu, location, scale, params)
dpearsonIV(x, m, nu, location, scale, params, log = FALSE) ppearsonIV(q, m, nu, location, scale, params, lower.tail = TRUE, log.p = FALSE, tol = 1e-08, ...) qpearsonIV(p, m, nu, location, scale, params, lower.tail = TRUE, log.p = FALSE, tol = 1e-08, ...) rpearsonIV(n, m, nu, location, scale, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
m |
first shape parameter of Pearson type IV distribution. |
nu |
second shape parameter (skewness) of Pearson type IV distribution. |
location |
location parameter of Pearson type IV distribution. |
scale |
scale parameter of Pearson type IV distribution. |
params |
vector/list of length 4 containing parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
tol |
relative tolerance for evaluation of hypergeometric function 2F1
( |
... |
further parameters for underlying hypergeometric function. |
The Pearson type IV distribution with location parameter
location
,
scale parameter
scale
, and shape parameters
and
can
be obtained by its probability density function
for ,
,
(
corresponds to the Pearson type VII distribution family).
The normalizing constant, which involves the complex Gamma function, is
calculated with lngamma_complex
(see Gamma
) of
package gsl
, if package gsl
is installed.
Section 5.1 of [2] contains an algorithm (C code) for the calculation of the
normalizing constant, which is used otherwise, but this will be very slow for
large absolute values of .
The generation of random numbers (rpearsonIV
) uses the C code from
section 7 of [2]. It is (thus) restricted to distributions with .
For the cumulative distribution function (ppearsonIV
), numerical
integration of the density function is used, if package gsl
is not
available.
If package gsl
is installed, three different
methods are used, depending on the parameter constellation (the corresponding
parameter regions were obtained by comprehensive benchmarks):
numerical integration of the density function
cdf representation of Heinrich [2]
cdf representation of Willink [4]
The hypergeometric functions involved in the latter two representations are
approximated
via partial sums of the corresponding series (see [1], 15.1.1, p. 556).
Depending on the parameter constellation, transformation 15.3.5 of [1]
(p. 559) is applied for Heinrich's method.
The evaluation of the partial sums is first carried out in (ordinary)
double arithmetic. If cancellation reduces accuracy beyond tol
, the
evaluation is redone in double-double arithmetics. If cancellation still
reduces accuracy beyond tol
, the evaluation is again redone in
quad-double arithmetic. Code for double-double and quad-double arithmetics
is based on [3].
For Willink's representation, the hypergeometric function in the denominator
of in equation (10) is evaluated via complex gamma
functions (see [1], 15.1.20, p. 556), which is fast and much more stable.
A warning is issued if the approximation of the hypergeometric function
seems to fail (which should not
happen, since numerical integration should be carried out for critical
parameter constellations).
The quantile function (qpearsonIV
) is obtained via Newton's method.
The Newton iteration begins in the (single) mode of the distribution,
which is easily calculated (see [2], section 3). Since the mode of the
distribution is the only inflection point of the cumulative distribution
function, convergence is guaranteed.
The Newton iteration stops when the target q
-error is reached
(or after a maximum of 30 iterations).
dpearsonIV
gives the density, ppearsonIV
gives the distribution
function, qpearsonIV
gives the quantile function, and rpearsonIV
generates random deviates.
If at all possible, package gsl
should be installed.
Otherwise, calculations for distributions with (more or less) extreme
parameters may slow down by factors of more than 1000 and/or may become
unstable.
Many calculations are done in logarithms to avoid IEEE 754 underflow/overflow issues.
The description of quad-double arithmetics in [3] contains minor errors:
in algorithm 9 (p. 6), lines 9 and 10 should be interchanged;
in algorithm 14 (p. 10), should be replaced with
(line 10)
and
should be replaced with
(line 11).
Martin Becker [email protected], Stefan Klößner [email protected] and Joel Heinrich
[1] Abramowitz, M. and I. A. Stegun (1972) Handbook of mathematical functions, National Bureau of Standards, Applied Mathematics Series - 55, Tenth Printing, Washington D.C.
[2] Heinrich, J. (2004) A Guide to the Pearson Type IV Distribution, Univ. Pennsylvania, Philadelphia, Tech. Rep. CDF/Memo/Statistics/Public/6820 http://www-cdf.fnal.gov/physics/statistics/notes/cdf6820_pearson4.pdf
[3] Hida, Y., X. S. Li and D. H. Bailey (2000) Algorithms for quad-double precision floating point arithmetic, Lawrence Berkeley National Laboratory. Paper LBNL-48597.
[4] Willink, R. (2008) A Closed-form Expression for the Pearson Type IV Distribution Function, Aust. N. Z. J. Stat. 50 (2), pp. 199-205
## define Pearson type IV parameter set with m=5.1, nu=3, location=0.5, scale=2 pIVpars <- list(m=5.1, nu=3, location=0.5, scale=2) ## calculate probability density function dpearsonIV(-2:2,params=pIVpars) ## calculate cumulative distribution function ppearsonIV(-2:2,params=pIVpars) ## calculate quantile function qpearsonIV(seq(0.1,0.9,by=0.2),params=pIVpars) ## generate random numbers rpearsonIV(5,params=pIVpars)
## define Pearson type IV parameter set with m=5.1, nu=3, location=0.5, scale=2 pIVpars <- list(m=5.1, nu=3, location=0.5, scale=2) ## calculate probability density function dpearsonIV(-2:2,params=pIVpars) ## calculate cumulative distribution function ppearsonIV(-2:2,params=pIVpars) ## calculate quantile function qpearsonIV(seq(0.1,0.9,by=0.2),params=pIVpars) ## generate random numbers rpearsonIV(5,params=pIVpars)
Calculates the first four moments (mean, variance, skewness, kurtosis) of a Pearson distribution.
pearsonMoments(params, moments)
pearsonMoments(params, moments)
params |
vector/list of parameters for Pearson distribution. First entry gives type of distribution (0 for type 0, 1 for type I, ..., 7 for type VII), remaining entries give distribution parameters (depending on distribution type). |
moments |
optional vector/list of mean, variance, skewness, kurtosis
(not excess kurtosis).
Overrides |
Named vector of length 4 containing mean
, variance
,
skewness
and kurtosis
(in this order).
Optional parameter moments
is merely for testing purposes. Of course,
pearsonMoments
should reproduce its input (when neglecting rounding
errors) if moments
is given.
kurtosis
is the kurtosis of the distribution, not the excess kurtosis!
Martin Becker [email protected]
[1] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 1, Wiley Series in Probability and Mathematical Statistics, Wiley
[2] Johnson, N. L., Kotz, S. and Balakrishnan, N. (1994) Continuous Univariate Distributions, Vol. 2, Wiley Series in Probability and Mathematical Statistics, Wiley
PearsonDS-package
,
Pearson0
, PearsonI
, PearsonII
,
PearsonIII
, PearsonIV
, PearsonV
,
PearsonVI
, PearsonVII
,
## Define moments of distribution moments <- c(mean=1,variance=2,skewness=1,kurtosis=5) ## Are the moments reproduced? pearsonMoments(moments=moments)
## Define moments of distribution moments <- c(mean=1,variance=2,skewness=1,kurtosis=5) ## Are the moments reproduced? pearsonMoments(moments=moments)
This function performs (as pearsonFitML
) an ML estimation
for all sub-classes of the Pearson distribution system via numerical
optimization (with nlminb
) for model selection purposes.
Apart from calculating the log-likelihood values as well as the values of
some common model selection criteria (pure ML, AIC, AICc, BIC, HQC) for the
different sub-classes, model selection is done for each of the criteria and
the parameter estimates for each distribution sub-class are returned.
pearsonMSC(x, ...)
pearsonMSC(x, ...)
x |
empirical data (numerical vector) for MLE. |
... |
parameters for |
For the ML estimation, see the details of pearsonFitML
.
The considered Model Selection Criteria (MSCs) are 'pure' Maximum Likelihood
(ML
), Akaike Information Criterion (AIC
), corrected AIC
(AICc
), Bayes Information Criterion (BIC
, also known as Schwarz
Criterion), and Hannan-Quinn-Criterion (HQC
). The definitions used
for the different MSCs are
for ML
:
for AIC
:
for AICc
:
for BIC
:
for HQC
:
where denotes the log-Likelihood,
denotes the number of observations (ie, the length of
x
)
and denotes the number of parameters of the distribution
(sub-class).
The best model minimizes the corresponding MSC function values.
A list containing
MSCs |
a matrix with rows |
logLik |
a vector with the log-likelihood values for the different distribution types. |
FittedDistributions |
a list with vectors of the parameter estimates (preceeded by the distribution type number) for the 8 Pearson distribution sub-classes. |
Best |
a list with components |
The implementation is still preliminary (and slow). No analytical results are used, ie. no analytical solutions for ML estimators and no analytical gradients.
Martin Becker [email protected]
PearsonDS-package
,
Pearson
,
pearsonFitML
## Generate sample DATA <- rpearson(500,moments=c(mean=1,variance=2,skewness=1,kurtosis=5)) ## Call pearsonMSC for model selection MSC <- pearsonMSC(DATA,control=list(iter.max=1e5,eval.max=1e5)) ## log-Likelihood values for all distribution sub-classes print(MSC$logLik) ## Values for all MSCs and distribution sub-classes print(MSC$MSCs) ## Model selection for all MSCs print(MSC$Best)
## Generate sample DATA <- rpearson(500,moments=c(mean=1,variance=2,skewness=1,kurtosis=5)) ## Call pearsonMSC for model selection MSC <- pearsonMSC(DATA,control=list(iter.max=1e5,eval.max=1e5)) ## log-Likelihood values for all distribution sub-classes print(MSC$logLik) ## Values for all MSCs and distribution sub-classes print(MSC$MSCs) ## Model selection for all MSCs print(MSC$Best)
Density, distribution function, quantile function and random generation for the Pearson type V (aka Inverse Gamma) distribution.
dpearsonV(x, shape, location, scale, params, log = FALSE) ppearsonV(q, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonV(p, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonV(n, shape, location, scale, params)
dpearsonV(x, shape, location, scale, params, log = FALSE) ppearsonV(q, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonV(p, shape, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonV(n, shape, location, scale, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
shape |
shape parameter of Pearson type V distribution. |
location |
location parameter of Pearson type V distribution. |
scale |
scale parameter of Pearson type V distribution. |
params |
vector/list of length 3 containing parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
The Pearson type V distributions are essentially Inverse Gamma distributions.
Thus, all functions are implemented via calls to the corresponding functions
for Gamma distributions, ie. dgamma
, pgamma
, qgamma
and rgamma
in package stats
.
Negative scale
parameters
(which reflect the distribution at location
) are
permitted to allow for negative skewness.
The probability density function with parameters shape
,
scale
and
location
is given by
for ,
and
.
dpearsonV
gives the density, ppearsonV
gives the
distribution function, qpearsonV
gives the quantile function,
and rpearsonV
generates random deviates.
Since package version 0.98, the parameter scale
corresponds to the
usual scale parameter of the Inverse Gamma distribution (not the reciprocal
value, which was implemented [incorrectly!] until package version 0.97).
Martin Becker [email protected]
See the references in GammaDist
.
GammaDist
,
PearsonDS-package
,
Pearson
## define Pearson type V parameter set with shape=3, location=1, scale=-2 pVpars <- list(shape=3, location=1, scale=-2) ## calculate probability density function dpearsonV(-4:1,params=pVpars) ## calculate cumulative distribution function ppearsonV(-4:1,params=pVpars) ## calculate quantile function qpearsonV(seq(0.1,0.9,by=0.2),params=pVpars) ## generate random numbers rpearsonV(5,params=pVpars)
## define Pearson type V parameter set with shape=3, location=1, scale=-2 pVpars <- list(shape=3, location=1, scale=-2) ## calculate probability density function dpearsonV(-4:1,params=pVpars) ## calculate cumulative distribution function ppearsonV(-4:1,params=pVpars) ## calculate quantile function qpearsonV(seq(0.1,0.9,by=0.2),params=pVpars) ## generate random numbers rpearsonV(5,params=pVpars)
Density, distribution function, quantile function and random generation for the Pearson type VI (aka Beta prime) distribution.
dpearsonVI(x, a, b, location, scale, params, log = FALSE) ppearsonVI(q, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonVI(p, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonVI(n, a, b, location, scale, params)
dpearsonVI(x, a, b, location, scale, params, log = FALSE) ppearsonVI(q, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonVI(p, a, b, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonVI(n, a, b, location, scale, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
a |
first shape parameter of Pearson type VI distribution. |
b |
second shape parameter of Pearson type VI distribution. |
location |
location parameter of Pearson type VI distribution. |
scale |
scale parameter of Pearson type VI distribution. |
params |
vector/list of length 4 containing parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
Pearson type VI distributions are (location-scale transformations
of) Beta prime distributions, and Beta prime distributions are
scaled F-distributions. The above functions are
thus implemented via calls to df
, pf
,
qf
and rf
(contained in package stats
).
The probability density function with parameters a
, b
,
scale
and
location
is given by
for ,
,
,
.
dpearsonVI
gives the density, ppearsonVI
gives the
distribution function, qpearsonVI
gives the quantile function,
and rpearsonVI
generates random deviates.
Negative values for scale
are permitted to allow for negative skewness.
Martin Becker [email protected]
See the references in FDist
.
FDist
,
PearsonDS-package
,
Pearson
## define Pearson type VI parameter set with a=2, b=3, location=1, scale=2 pVIpars <- list(a=2, b=3, location=1, scale=2) ## calculate probability density function dpearsonVI(seq(1,6,by=1),params=pVIpars) ## calculate cumulative distribution function ppearsonVI(seq(1,6,by=1),params=pVIpars) ## calculate quantile function qpearsonVI(seq(0.1,0.9,by=0.2),params=pVIpars) ## generate random numbers rpearsonVI(5,params=pVIpars)
## define Pearson type VI parameter set with a=2, b=3, location=1, scale=2 pVIpars <- list(a=2, b=3, location=1, scale=2) ## calculate probability density function dpearsonVI(seq(1,6,by=1),params=pVIpars) ## calculate cumulative distribution function ppearsonVI(seq(1,6,by=1),params=pVIpars) ## calculate quantile function qpearsonVI(seq(0.1,0.9,by=0.2),params=pVIpars) ## generate random numbers rpearsonVI(5,params=pVIpars)
Density, distribution function, quantile function and random generation for the Pearson type VII (aka Student's t) distribution.
dpearsonVII(x, df, location, scale, params, log = FALSE) ppearsonVII(q, df, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonVII(p, df, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonVII(n, df, location, scale, params)
dpearsonVII(x, df, location, scale, params, log = FALSE) ppearsonVII(q, df, location, scale, params, lower.tail = TRUE, log.p = FALSE) qpearsonVII(p, df, location, scale, params, lower.tail = TRUE, log.p = FALSE) rpearsonVII(n, df, location, scale, params)
x , q
|
vector of quantiles. |
p |
vector of probabilities. |
n |
number of observations. |
df |
degrees of freedom of Pearson type VII distribution |
location |
location parameter of Pearson type VII distribution. |
scale |
scale parameter of Pearson type VII distribution. |
params |
vector/list of length 3 containing parameters |
log , log.p
|
logical; if |
lower.tail |
logical; if |
The Pearson type VII distribution is a simple (location-scale) transformation
of the well-known Student's t distribution; the probability density function
with parameters df
,
location
and
scale
is given by
for .
The above functions are thus only wrappers for
dt
,
pt
, qt
and rt
contained in package
stats
.
dpearsonVII
gives the density, ppearsonVII
gives the
distribution function, qpearsonVII
gives the quantile function,
and rpearsonVII
generates random deviates.
Martin Becker [email protected]
See the references in TDist
.
TDist
,
PearsonDS-package
,
Pearson
## define Pearson type VII parameter set with df=7, location=1, scale=1 pVIIpars <- list(df=7, location=1, scale=1) ## calculate probability density function dpearsonVII(-2:4,params=pVIIpars) ## calculate cumulative distribution function ppearsonVII(-2:4,params=pVIIpars) ## calculate quantile function qpearsonVII(seq(0.1,0.9,by=0.2),params=pVIIpars) ## generate random numbers rpearsonVII(5,params=pVIIpars)
## define Pearson type VII parameter set with df=7, location=1, scale=1 pVIIpars <- list(df=7, location=1, scale=1) ## calculate probability density function dpearsonVII(-2:4,params=pVIIpars) ## calculate cumulative distribution function ppearsonVII(-2:4,params=pVIIpars) ## calculate quantile function qpearsonVII(seq(0.1,0.9,by=0.2),params=pVIIpars) ## generate random numbers rpearsonVII(5,params=pVIIpars)