Title: | Some Additional Distributions |
---|---|
Description: | Provides the density, distribution, quantile and generation functions of some obscure probability distributions, including the doubly non-central t, F, Beta, and Eta distributions; the lambda-prime and K-prime; the upsilon distribution; the (weighted) sum of non-central chi-squares to a power; the (weighted) sum of log non-central chi-squares; the product of non-central chi-squares to powers; the product of doubly non-central F variables; the product of independent normals. |
Authors: | Steven E. Pav [aut, cre] |
Maintainer: | Steven E. Pav <[email protected]> |
License: | LGPL-3 |
Version: | 0.2.4 |
Built: | 2024-11-06 02:56:29 UTC |
Source: | https://github.com/shabbychef/sadists |
Density, distribution function, quantile function and random generation for the doubly non-central Beta distribution.
ddnbeta(x, df1, df2, ncp1, ncp2, log = FALSE, order.max=6) pdnbeta(q, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdnbeta(p, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdnbeta(n, df1, df2, ncp1, ncp2)
ddnbeta(x, df1, df2, ncp1, ncp2, log = FALSE, order.max=6) pdnbeta(q, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdnbeta(p, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdnbeta(n, df1, df2, ncp1, ncp2)
x , q
|
vector of quantiles. |
df1 , df2
|
the degrees of freedom for the numerator and denominator.
We do not recycle these versus the |
ncp1 , ncp2
|
the non-centrality parameters for the numerator and denominator.
We do not recycle these versus the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Suppose
be independent non-central chi-squares for
.
Then
takes a doubly non-central Beta distribution with degrees of freedom
and non-centrality parameters
.
ddnbeta
gives the density, pdnbeta
gives the
distribution function, qdnbeta
gives the quantile function,
and rdnbeta
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
(doubly non-central) F distribution functions,
ddnf, pdnf, qdnf, rdnf
.
rv <- rdnbeta(500, df1=100,df2=500,ncp1=1.5,ncp2=12) d1 <- ddnbeta(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) plot(rv,d1) p1 <- ddnbeta(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) # should be nearly uniform: plot(ecdf(p1)) q1 <- qdnbeta(ppoints(length(rv)), df1=100,df2=500,ncp1=1.5,ncp2=12) qqplot(x=rv,y=q1)
rv <- rdnbeta(500, df1=100,df2=500,ncp1=1.5,ncp2=12) d1 <- ddnbeta(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) plot(rv,d1) p1 <- ddnbeta(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) # should be nearly uniform: plot(ecdf(p1)) q1 <- qdnbeta(ppoints(length(rv)), df1=100,df2=500,ncp1=1.5,ncp2=12) qqplot(x=rv,y=q1)
Density, distribution function, quantile function and random generation for the doubly non-central Eta distribution.
ddneta(x, df, ncp1, ncp2, log = FALSE, order.max=6) pdneta(q, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdneta(p, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdneta(n, df, ncp1, ncp2)
ddneta(x, df, ncp1, ncp2, log = FALSE, order.max=6) pdneta(q, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdneta(p, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdneta(n, df, ncp1, ncp2)
x , q
|
vector of quantiles. |
df |
the degrees of freedom for the denominator chi square.
We do not recycle this versus the |
ncp1 , ncp2
|
the non-centrality parameters for the numerator and denominator.
We do not recycle these versus the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Suppose is a normal with mean
,
and standard deviation 1, independent of
,
a non-central chi-square with
degrees of freedom
and non-centrality parameter
. Then
takes a doubly non-central Eta distribution with
degrees of freedom and non-centrality parameters
. The square of
a doubly non-central Eta is a doubly non-central Beta variate.
ddneta
gives the density, pdneta
gives the
distribution function, qdneta
gives the quantile function,
and rdneta
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
(doubly non-central) t distribution functions,
ddnt, pdnt, qdnt, rdnt
.
(doubly non-central) Beta distribution functions,
ddnbeta, pdnbeta, qdnbeta, rdnbeta
.
rv <- rdneta(500, df=100,ncp1=1.5,ncp2=12) d1 <- ddneta(rv, df=100,ncp1=1.5,ncp2=12) plot(rv,d1) p1 <- ddneta(rv, df=100,ncp1=1.5,ncp2=12) # should be nearly uniform: plot(ecdf(p1)) q1 <- qdneta(ppoints(length(rv)), df=100,ncp1=1.5,ncp2=12) qqplot(x=rv,y=q1)
rv <- rdneta(500, df=100,ncp1=1.5,ncp2=12) d1 <- ddneta(rv, df=100,ncp1=1.5,ncp2=12) plot(rv,d1) p1 <- ddneta(rv, df=100,ncp1=1.5,ncp2=12) # should be nearly uniform: plot(ecdf(p1)) q1 <- qdneta(ppoints(length(rv)), df=100,ncp1=1.5,ncp2=12) qqplot(x=rv,y=q1)
Density, distribution function, quantile function and random generation for the doubly non-central F distribution.
ddnf(x, df1, df2, ncp1, ncp2, log = FALSE, order.max=6) pdnf(q, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdnf(p, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdnf(n, df1, df2, ncp1, ncp2)
ddnf(x, df1, df2, ncp1, ncp2, log = FALSE, order.max=6) pdnf(q, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdnf(p, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdnf(n, df1, df2, ncp1, ncp2)
x , q
|
vector of quantiles. |
df1 , df2
|
the degrees of freedom for the numerator and denominator.
We do not recycle these versus the |
ncp1 , ncp2
|
the non-centrality parameters for the numerator and denominator.
We do not recycle these versus the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Suppose
be independent non-central chi-squares for
.
Then
takes a doubly non-central F distribution with degrees of freedom
and non-centrality parameters
.
ddnf
gives the density, pdnf
gives the
distribution function, qdnf
gives the quantile function,
and rdnf
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
(singly non-central) F distribution functions,
df, pf, qf, rf
.
rv <- rdnf(500, df1=100,df2=500,ncp1=1.5,ncp2=12) d1 <- ddnf(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) plot(rv,d1) p1 <- ddnf(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) # should be nearly uniform: plot(ecdf(p1)) q1 <- qdnf(ppoints(length(rv)), df1=100,df2=500,ncp1=1.5,ncp2=12) qqplot(x=rv,y=q1)
rv <- rdnf(500, df1=100,df2=500,ncp1=1.5,ncp2=12) d1 <- ddnf(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) plot(rv,d1) p1 <- ddnf(rv, df1=100,df2=500,ncp1=1.5,ncp2=12) # should be nearly uniform: plot(ecdf(p1)) q1 <- qdnf(ppoints(length(rv)), df1=100,df2=500,ncp1=1.5,ncp2=12) qqplot(x=rv,y=q1)
Density, distribution function, quantile function and random generation for the doubly non-central t distribution.
ddnt(x, df, ncp1, ncp2, log = FALSE, order.max=6) pdnt(q, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdnt(p, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdnt(n, df, ncp1, ncp2)
ddnt(x, df, ncp1, ncp2, log = FALSE, order.max=6) pdnt(q, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) qdnt(p, df, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=6) rdnt(n, df, ncp1, ncp2)
x , q
|
vector of quantiles. |
df |
the degrees of freedom for the denominator, |
ncp1 , ncp2
|
the non-centrality parameters for the numerator and denominator,
respectively, |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Let independently
of
. The
random variable
takes a doubly non-central t distribution with parameters
.
ddnt
gives the density, pdnt
gives the
distribution function, qdnt
gives the quantile function,
and rdnt
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
Krishnan, Marakatha. "Series Representations of the Doubly Noncentral t-Distribution." Journal of the American Statistical Association 63, no. 323 (1968): 1004-1012.
t distribution functions, dt, pt, qt, rt
rvs <- rdnt(128, 20, 1, 1) dvs <- ddnt(rvs, 20, 1, 1) pvs.H0 <- pdnt(rvs, 20, 0, 1) pvs.HA <- pdnt(rvs, 20, 1, 1) plot(ecdf(pvs.H0)) plot(ecdf(pvs.HA)) # compare to singly non-central dv1 <- ddnt(1, df=10, ncp1=5, ncp2=0, log=FALSE) dv2 <- dt(1, df=10, ncp=5, log=FALSE) pv1 <- pdnt(1, df=10, ncp1=5, ncp2=0, log.p=FALSE) pv11 <- pdnt(1, df=10, ncp1=5, ncp2=0.001, log.p=FALSE) v2 <- pt(1, df=10, ncp=5, log.p=FALSE) q1 <- qdnt(pv1, df=10, ncp1=5, ncp2=0, log.p=FALSE)
rvs <- rdnt(128, 20, 1, 1) dvs <- ddnt(rvs, 20, 1, 1) pvs.H0 <- pdnt(rvs, 20, 0, 1) pvs.HA <- pdnt(rvs, 20, 1, 1) plot(ecdf(pvs.H0)) plot(ecdf(pvs.HA)) # compare to singly non-central dv1 <- ddnt(1, df=10, ncp1=5, ncp2=0, log=FALSE) dv2 <- dt(1, df=10, ncp=5, log=FALSE) pv1 <- pdnt(1, df=10, ncp1=5, ncp2=0, log.p=FALSE) pv11 <- pdnt(1, df=10, ncp1=5, ncp2=0.001, log.p=FALSE) v2 <- pt(1, df=10, ncp=5, log.p=FALSE) q1 <- qdnt(pv1, df=10, ncp1=5, ncp2=0, log.p=FALSE)
Density, distribution function, quantile function and random generation for the K prime distribution.
dkprime(x, v1, v2, a, b = 1, order.max=6, log = FALSE) pkprime(q, v1, v2, a, b = 1, order.max=6, lower.tail = TRUE, log.p = FALSE) qkprime(p, v1, v2, a, b = 1, order.max=6, lower.tail = TRUE, log.p = FALSE) rkprime(n, v1, v2, a, b = 1)
dkprime(x, v1, v2, a, b = 1, order.max=6, log = FALSE) pkprime(q, v1, v2, a, b = 1, order.max=6, lower.tail = TRUE, log.p = FALSE) qkprime(p, v1, v2, a, b = 1, order.max=6, lower.tail = TRUE, log.p = FALSE) rkprime(n, v1, v2, a, b = 1)
x , q
|
vector of quantiles. |
v1 |
the degrees of freedom in the numerator chisquare. When
(positive) infinite, we recover a non-central t
distribution with |
v2 |
the degrees of freedom in the denominator chisquare.
When equal to infinity, we recover the Lambda prime distribution.
This is not recycled against the |
a |
the non-centrality scaling parameter. When equal to zero,
we recover the (central) t distribution.
This is not recycled against the |
b |
the scaling parameter.
This is not recycled against the |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
log |
logical; if TRUE, densities |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Suppose , and
.
Then the random variable
takes a K prime distribution with parameters
. In Lecoutre's terminology,
Equivalently, we can think of
where is a standard normal, and the normal and the (central) chi-squares are
independent of each other. When
we recover
a central t distribution;
when
we recover a rescaled non-central t distribution;
when
, we get a rescaled square root of a central F
distribution; when
, we recover a
Lambda prime distribution.
dkprime
gives the density, pkprime
gives the
distribution function, qkprime
gives the quantile function,
and rkprime
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
Lecoutre, Bruno. "Two Useful distributions for Bayesian predictive procedures under normal models." Journal of Statistical Planning and Inference 79, no. 1 (1999): 93-105.
Poitevineau, Jacques, and Lecoutre, Bruno. "Implementing Bayesian predictive procedures: The K-prime and K-square distributions." Computational Statistics and Data Analysis 54, no. 3 (2010): 724-731. http://arxiv.org/abs/1003.4890v1
t distribution functions, dt, pt, qt, rt
,
lambda prime distribution functions, dlambdap, plambdap, qlambdap, rlambdap
.
d1 <- dkprime(1, 50, 20, a=0.01) d2 <- dkprime(1, 50, 20, a=0.0001) d3 <- dkprime(1, 50, 20, a=0) d4 <- dkprime(1, 10000, 20, a=1) d5 <- dkprime(1, Inf, 20, a=1)
d1 <- dkprime(1, 50, 20, a=0.01) d2 <- dkprime(1, 50, 20, a=0.0001) d3 <- dkprime(1, 50, 20, a=0) d4 <- dkprime(1, 10000, 20, a=1) d5 <- dkprime(1, Inf, 20, a=1)
Density, distribution function, quantile function and random generation for the lambda prime distribution.
dlambdap(x, df, t, log = FALSE, order.max=6) plambdap(q, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) qlambdap(p, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) rlambdap(n, df, t)
dlambdap(x, df, t, log = FALSE, order.max=6) plambdap(q, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) qlambdap(p, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) rlambdap(n, df, t)
x , q
|
vector of quantiles. |
df |
the degrees of freedom in the chi square.
This is not recycled against the |
t |
the scaling parameter on the chi.
This is not recycled against the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Suppose , and
is a standard normal.
takes a lambda prime distribution with parameters
.
A lambda prime random variable can be viewed as a confidence
level on a non-central t because
dlambdap
gives the density, plambdap
gives the
distribution function, qlambdap
gives the quantile function,
and rlambdap
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
Lecoutre, Bruno. "Another look at confidence intervals for the noncentral t distribution." Journal of Modern Applied Statistical Methods 6, no. 1 (2007): 107–116. https://digitalcommons.wayne.edu/cgi/viewcontent.cgi?article=1128&context=jmasm
Lecoutre, Bruno. "Two useful distributions for Bayesian predictive procedures under normal models." Journal of Statistical Planning and Inference 79 (1999): 93–105.
t distribution functions, dt, pt, qt, rt
,
K prime distribution functions, dkprime, pkprime, qkprime, rkprime
,
upsilon distribution functions, dupsilon, pupsilon, qupsilon, rupsilon
,
rv <- rlambdap(100, 50, t=0.01) d1 <- dlambdap(1, 50, t=0.01) pv <- plambdap(rv, 50, t=0.01) qv <- qlambdap(ppoints(length(rv)), 50, t=1)
rv <- rlambdap(100, 50, t=0.01) d1 <- dlambdap(1, 50, t=0.01) pv <- plambdap(rv, 50, t=0.01) qv <- qlambdap(ppoints(length(rv)), 50, t=1)
Density, distribution function, quantile function and random generation for the distribution of the product of non-central chi-squares taken to powers.
dprodchisqpow(x, df, ncp=0, pow=1, log = FALSE, order.max=5) pprodchisqpow(q, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=5) qprodchisqpow(p, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=5) rprodchisqpow(n, df, ncp=0, pow=1)
dprodchisqpow(x, df, ncp=0, pow=1, log = FALSE, order.max=5) pprodchisqpow(q, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=5) qprodchisqpow(p, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=5) rprodchisqpow(n, df, ncp=0, pow=1)
x , q
|
vector of quantiles. |
df |
the vector of degrees of freedom.
This is recycled against the |
ncp |
the vector of non-centrality parameters.
This is recycled against the |
pow |
the vector of the power parameters.
This is recycled against the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Let
be independently distributed non-central chi-squares, where
are the degrees of freedom, and
are the
non-centrality parameters.
Let
be given constants. Suppose
Then follows a product of chi-squares to power distribution.
dprodchisqpow
gives the density, pprodchisqpow
gives the
distribution function, qprodchisqpow
gives the quantile function,
and rprodchisqpow
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
The PDQ functions are computed by translation of the sum of log chi-squares distribution functions.
Steven E. Pav [email protected]
Pav, Steven. Moments of the log non-central chi-square distribution. http://arxiv.org/abs/1503.06266
The sum of log of chi-squares distribution,
dsumlogchisq
,
psumlogchisq
,
qsumlogchisq
,
rsumlogchisq
,
The upsilon distribution,
dupsilon
,
pupsilon
,
qupsilon
,
rupsilon
.
The sum of chi-square powers distribution,
dsumchisqpow
,
psumchisqpow
,
qsumchisqpow
,
rsumchisqpow
.
df <- c(100,20,10) ncp <- c(5,3,1) pow <- c(1,0.5,1) rvs <- rprodchisqpow(128, df, ncp, pow) dvs <- dprodchisqpow(rvs, df, ncp, pow) qvs <- pprodchisqpow(rvs, df, ncp, pow) pvs <- qprodchisqpow(ppoints(length(rvs)), df, ncp, pow)
df <- c(100,20,10) ncp <- c(5,3,1) pow <- c(1,0.5,1) rvs <- rprodchisqpow(128, df, ncp, pow) dvs <- dprodchisqpow(rvs, df, ncp, pow) qvs <- pprodchisqpow(rvs, df, ncp, pow) pvs <- qprodchisqpow(ppoints(length(rvs)), df, ncp, pow)
Density, distribution function, quantile function and random generation for the product of multiple independent doubly non-central F variates.
dproddnf(x, df1, df2, ncp1, ncp2, log = FALSE, order.max=4) pproddnf(q, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=4) qproddnf(p, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=4) rproddnf(n, df1, df2, ncp1, ncp2)
dproddnf(x, df1, df2, ncp1, ncp2, log = FALSE, order.max=4) pproddnf(q, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=4) qproddnf(p, df1, df2, ncp1, ncp2, lower.tail = TRUE, log.p = FALSE, order.max=4) rproddnf(n, df1, df2, ncp1, ncp2)
x , q
|
vector of quantiles. |
df1 , df2
|
the vectors of the degrees of freedom for the numerator and denominator.
We do not recycle these versus the |
ncp1 , ncp2
|
the vectors of the non-centrality parameters for the numerator and denominator.
We do not recycle these versus the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Let
be independent doubly non-central F variates with non-centrality parameters
and degrees of freedom
for
and
.
Then
takes a product of doubly non-central F's distribution. We take the
parameters of this distribution as the four length vectors
of the two degrees of freedom and the two non-centrality parameters.
dproddnf
gives the density, pproddnf
gives the
distribution function, qproddnf
gives the quantile function,
and rproddnf
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
The PDQ functions are computed by translation of the sum of log chi-squares distribution functions.
Steven E. Pav [email protected]
Pav, Steven. Moments of the log non-central chi-square distribution. http://arxiv.org/abs/1503.06266
The sum of log of chi-squares distribution,
dsumlogchisq
,
psumlogchisq
,
qsumlogchisq
,
rsumlogchisq
.
(doubly non-central) F distribution functions,
ddnf
,
pdnf
,
qdnf
,
rdnf
.
df1 <- c(10,20,5) df2 <- c(1000,500,150) ncp1 <- c(1,0,2.5) ncp2 <- c(0,1.5,5) rv <- rproddnf(500, df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) d1 <- dproddnf(rv, df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) plot(rv,d1) p1 <- pproddnf(rv, df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) # should be nearly uniform: plot(ecdf(p1)) q1 <- qproddnf(ppoints(length(rv)), df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) qqplot(x=rv,y=q1)
df1 <- c(10,20,5) df2 <- c(1000,500,150) ncp1 <- c(1,0,2.5) ncp2 <- c(0,1.5,5) rv <- rproddnf(500, df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) d1 <- dproddnf(rv, df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) plot(rv,d1) p1 <- pproddnf(rv, df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) # should be nearly uniform: plot(ecdf(p1)) q1 <- qproddnf(ppoints(length(rv)), df1=df1,df2=df2,ncp1=ncp1,ncp2=ncp2) qqplot(x=rv,y=q1)
Density, distribution function, quantile function and random generation for the distribution of the product of indepdendent normal random variables.
dprodnormal(x, mu, sigma, log = FALSE, order.max=5) pprodnormal(q, mu, sigma, lower.tail = TRUE, log.p = FALSE, order.max=5) qprodnormal(p, mu, sigma, lower.tail = TRUE, log.p = FALSE, order.max=5) rprodnormal(n, mu, sigma)
dprodnormal(x, mu, sigma, log = FALSE, order.max=5) pprodnormal(q, mu, sigma, lower.tail = TRUE, log.p = FALSE, order.max=5) qprodnormal(p, mu, sigma, lower.tail = TRUE, log.p = FALSE, order.max=5) rprodnormal(n, mu, sigma)
x , q
|
vector of quantiles. |
mu |
the vector of means.
This is recycled against the |
sigma |
the vector of standard deviations.
This is recycled against the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Let
be independently distributed normal variates, with means
and variances
.
Suppose
Then follows a product of normals distribution.
dprodnormal
gives the density, pprodnormal
gives the
distribution function, qprodnormal
gives the quantile function,
and rprodnormal
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
mu <- c(100,20,10) sigma <- c(10,50,10) rvs <- rprodnormal(128, mu, sigma) dvs <- dprodnormal(rvs, mu, sigma) qvs <- pprodnormal(rvs, mu, sigma) pvs <- qprodnormal(ppoints(length(rvs)), mu, sigma)
mu <- c(100,20,10) sigma <- c(10,50,10) rvs <- rprodnormal(128, mu, sigma) dvs <- dprodnormal(rvs, mu, sigma) qvs <- pprodnormal(rvs, mu, sigma) pvs <- qprodnormal(ppoints(length(rvs)), mu, sigma)
Runs a shiny application which draws from the given distributions, then illustrates the fidelity of the density, CDF, and quantile functions.
runExample(port=NULL,launch.browser=TRUE, host=getOption('shiny.host','127.0.0.1'),display.mode='auto')
runExample(port=NULL,launch.browser=TRUE, host=getOption('shiny.host','127.0.0.1'),display.mode='auto')
port |
The TCP port that the application should listen on. If the
|
launch.browser |
If true, the system's default web browser will be launched automatically after the app is started. Defaults to true in interactive sessions only. This value of this parameter can also be a function to call with the application's URL. |
host |
The IPv4 address that the application should listen on. Defaults
to the |
display.mode |
The mode in which to display the application. If set to
the value |
Launches shiny applications, and optionally, your system's web browser. Draws are taken from the random variable, and d-d, q-q, and p-p plots are available.
Steven E. Pav [email protected]
Attali, D. "Supplementing your R package with a shiny app." http://deanattali.com/2015/04/21/r-package-shiny-app/
## Not run: runExample(launch.browser=TRUE) ## End(Not run)
## Not run: runExample(launch.browser=TRUE) ## End(Not run)
Some Additional Distributions.
A collection of distributions which can be approximated via Edgeworth and Cornish-Fisher expansions
Let
be independently distributed non-central chi-squares, where
are the degrees of freedom, and
are the
non-centrality parameters.
Let
and
be given constants. Suppose
Then follows a weighted sum of chi-squares to power distribution.
The special case where all the
are one is a 'sum of
chi-squares' distribution;
The special case where all the
are one half is a 'sum of
chis' distribution;
Introduced by Lecoutre, the lambda prime distribution
finds use in inference on the Sharpe ratio under normal
returns.
Suppose , and
is a standard normal.
takes a lambda prime distribution with parameters
.
A lambda prime random variable can be viewed as a confidence
variable on a non-central t because
The upsilon distribution generalizes the lambda prime to the
case of the sum of multiple chi variables. That is,
suppose
independently and independently of
, a standard normal.
Then
takes an upsilon distribution with parameter vectors
.
The upsilon distribution is used in certain tests of the Sharpe ratio for independent observations.
Introduced by Lecoutre, the K prime family of distributions generalize
the (singly) non-central t, and lambda prime distributions.
Suppose , and
.
Then the random variable
takes a K prime distribution with parameters
. In Lecoutre's terminology,
Equivalently, we can think of
where is a standard normal, and the normal and the (central) chi-squares are
independent of each other. When
we recover
a central t distribution;
when
we recover a rescaled non-central t distribution;
when
, we get a rescaled square root of a central F
distribution; when
, we recover a
Lambda prime distribution.
The doubly noncentral t distribution generalizes the (singly)
noncentral t distribution to the case where the numerator is
the square root of a scaled noncentral chi-square distribution.
That is, if
independently
of
, then
the random variable
takes a doubly non-central t distribution with parameters
.
The doubly noncentral F distribution generalizes the (singly)
noncentral F distribution to the case where the numerator is
a scaled noncentral chi-square distribution.
That is, if
independently
of
, then
the random variable
takes a doubly non-central F distribution with parameters
.
It should be noted that the functions provided by sadists do not
recycle their distribution parameters against the
x, p, q
or n
parameters. This is in contrast to the
common R idiom, and may cause some confusion. This is mostly for reasons
of performance, but also because some of the distributions have vector-valued
parameters; recycling over these would require the user to provide lists
of parameters, which would be unpleasant.
sadists is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
This package is maintained as a hobby.
Steven E. Pav [email protected]
Paolella, Marc. Intermediate Probability: A Computational Approach. Wiley, 2007. http://www.wiley.com/WileyCDA/WileyTitle/productCd-0470026375.html
Lecoutre, Bruno. "Two Useful distributions for Bayesian predictive procedures under normal models." Journal of Statistical Planning and Inference 79, no. 1 (1999): 93-105.
Poitevineau, Jacques, and Lecoutre, Bruno. "Implementing Bayesian predictive procedures: The K-prime and K-square distributions." Computational Statistics and Data Analysis 54, no. 3 (2010): 724-731. http://arxiv.org/abs/1003.4890v1
Walck, C. "HAndbook on Statistical Distributions for experimentalists." 1996. http://www.stat.rice.edu/~dobelman/textfiles/DistributionsHandbook.pdf
History of the 'sadists' package.
CRAN emergency release.
add product of normals distribution.
move github figures to location CRAN understands.
work around bad rchisq
when (?)
incompatibilities in vignette with ggplot2 release.
shiny app (h/t Dean Attali).
add doubly non-central Beta and Eta distributions.
add (sum of) log chi-square distribution.
have products of chi-square depend on transform of this distribution.
first CRAN release.
Density, distribution function, quantile function and random generation for the distribution of the weighted sum of non-central chi-squares taken to powers.
dsumchisqpow(x, wts, df, ncp=0, pow=1, log = FALSE, order.max=6) psumchisqpow(q, wts, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=6) qsumchisqpow(p, wts, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=6) rsumchisqpow(n, wts, df, ncp=0, pow=1)
dsumchisqpow(x, wts, df, ncp=0, pow=1, log = FALSE, order.max=6) psumchisqpow(q, wts, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=6) qsumchisqpow(p, wts, df, ncp=0, pow=1, lower.tail = TRUE, log.p = FALSE, order.max=6) rsumchisqpow(n, wts, df, ncp=0, pow=1)
x , q
|
vector of quantiles. |
wts |
the vector of weights.
This is recycled against the |
df |
the vector of degrees of freedom.
This is recycled against the |
ncp |
the vector of non-centrality parameters.
This is recycled against the |
pow |
the vector of the power parameters.
This is recycled against the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Let
be independently distributed non-central chi-squares, where
are the degrees of freedom, and
are the
non-centrality parameters.
Let
and
be given constants. Suppose
Then follows a weighted sum of chi-squares to power distribution.
dsumchisqpow
gives the density, psumchisqpow
gives the
distribution function, qsumchisqpow
gives the quantile function,
and rsumchisqpow
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
The 'sum of chisquare power' distribution does not generalize the 'chi-bar-square' distribution, whose density is the sum of chi-square densities.
Steven E. Pav [email protected]
The upsilon distribution,
dupsilon,pupsilon,qupsilon,rupsilon
.
wts <- c(1,-3,4) df <- c(100,20,10) ncp <- c(5,3,1) pow <- c(1,0.5,1) rvs <- rsumchisqpow(128, wts, df, ncp, pow) dvs <- dsumchisqpow(rvs, wts, df, ncp, pow) qvs <- psumchisqpow(rvs, wts, df, ncp, pow) pvs <- qsumchisqpow(ppoints(length(rvs)), wts, df, ncp, pow)
wts <- c(1,-3,4) df <- c(100,20,10) ncp <- c(5,3,1) pow <- c(1,0.5,1) rvs <- rsumchisqpow(128, wts, df, ncp, pow) dvs <- dsumchisqpow(rvs, wts, df, ncp, pow) qvs <- psumchisqpow(rvs, wts, df, ncp, pow) pvs <- qsumchisqpow(ppoints(length(rvs)), wts, df, ncp, pow)
Density, distribution function, quantile function and random generation for the distribution of the weighted sum of logs of non-central chi-squares.
dsumlogchisq(x, wts, df, ncp=0, log = FALSE, order.max=6) psumlogchisq(q, wts, df, ncp=0, lower.tail = TRUE, log.p = FALSE, order.max=6) qsumlogchisq(p, wts, df, ncp=0, lower.tail = TRUE, log.p = FALSE, order.max=6) rsumlogchisq(n, wts, df, ncp=0)
dsumlogchisq(x, wts, df, ncp=0, log = FALSE, order.max=6) psumlogchisq(q, wts, df, ncp=0, lower.tail = TRUE, log.p = FALSE, order.max=6) qsumlogchisq(p, wts, df, ncp=0, lower.tail = TRUE, log.p = FALSE, order.max=6) rsumlogchisq(n, wts, df, ncp=0)
x , q
|
vector of quantiles. |
wts |
the vector of weights.
This is recycled against the |
df |
the vector of degrees of freedom.
This is recycled against the |
ncp |
the vector of non-centrality parameters.
This is recycled against the |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Let
be independently distributed non-central chi-squares, where
are the degrees of freedom, and
are the
non-centrality parameters.
Let
be given constants. Suppose
Then follows a weighted sum of log of chi-squares distribution.
dsumlogchisq
gives the density, psumlogchisq
gives the
distribution function, qsumlogchisq
gives the quantile function,
and rsumlogchisq
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
Pav, Steven. Moments of the log non-central chi-square distribution. http://arxiv.org/abs/1503.06266
The product of chi-squares to a power,
dprodchisqpow
,
pprodchisqpow
,
qprodchisqpow
,
rprodchisqpow
.
wts <- c(1,-3,4) df <- c(100,20,10) ncp <- c(5,3,1) rvs <- rsumlogchisq(128, wts, df, ncp) dvs <- dsumlogchisq(rvs, wts, df, ncp) qvs <- psumlogchisq(rvs, wts, df, ncp) pvs <- qsumlogchisq(ppoints(length(rvs)), wts, df, ncp)
wts <- c(1,-3,4) df <- c(100,20,10) ncp <- c(5,3,1) rvs <- rsumlogchisq(128, wts, df, ncp) dvs <- dsumlogchisq(rvs, wts, df, ncp) qvs <- psumlogchisq(rvs, wts, df, ncp) pvs <- qsumlogchisq(ppoints(length(rvs)), wts, df, ncp)
Density, distribution function, quantile function and random generation for the upsilon distribution.
dupsilon(x, df, t, log = FALSE, order.max=6) pupsilon(q, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) qupsilon(p, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) rupsilon(n, df, t)
dupsilon(x, df, t, log = FALSE, order.max=6) pupsilon(q, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) qupsilon(p, df, t, lower.tail = TRUE, log.p = FALSE, order.max=6) rupsilon(n, df, t)
x , q
|
vector of quantiles. |
df |
the degrees of freedom in the chi square. a vector. we do not vectorize over this variable. |
t |
the scaling parameter on the chi. a vector. should be the same
length as |
log |
logical; if TRUE, densities |
order.max |
the order to use in the approximate density, distribution, and quantile computations, via the Gram-Charlier, Edeworth, or Cornish-Fisher expansion. |
p |
vector of probabilities. |
n |
number of observations. |
log.p |
logical; if TRUE, probabilities p are given
as |
lower.tail |
logical; if TRUE (default), probabilities are
|
Suppose
independently and independently of
, a standard normal.
Then
takes an upsilon distribution with parameter vectors
.
The upsilon distribution is used in certain tests of
the Sharpe ratio for independent observations, and generalizes
the lambda prime distribution, which can be written as
.
dupsilon
gives the density, pupsilon
gives the
distribution function, qupsilon
gives the quantile function,
and rupsilon
generates random deviates.
Invalid arguments will result in return value NaN
with a warning.
the PDF and CDF are approximated by an Edgeworth expansion; the quantile function is approximated by a Cornish-Fisher expansion.
The PDF, CDF, and quantile function are approximated, via the Edgeworth or Cornish Fisher approximations, which may not be terribly accurate in the tails of the distribution. You are warned.
The distribution parameters are not recycled
with respect to the x, p, q
or n
parameters,
for, respectively, the density, distribution, quantile
and generation functions. This is for simplicity of
implementation and performance. It is, however, in contrast
to the usual R idiom for dpqr functions.
Steven E. Pav [email protected]
Lecoutre, Bruno. "Another look at confidence intervals for the noncentral t distribution." Journal of Modern Applied Statistical Methods 6, no. 1 (2007): 107–116. https://digitalcommons.wayne.edu/cgi/viewcontent.cgi?article=1128&context=jmasm
Lecoutre, Bruno. "Two useful distributions for Bayesian predictive procedures under normal models." Journal of Statistical Planning and Inference 79 (1999): 93–105.
Pav, Steven. "Inference on the Sharpe ratio via the upsilon distribution.' Arxiv (2015). http://arxiv.org/abs/1505.00829
lambda-prime distribution functions,
dlambdap, plambdap, qlambdap, rlambdap
.
Sum of chi-squares to power distribution functions,
dsumchisqpow, psumchisqpow, qsumchisqpow, rsumchisqpow
.
mydf <- c(100,30,50) myt <- c(-1,3,5) rv <- rupsilon(500, df=mydf, t=myt) d1 <- dupsilon(rv, df=mydf, t=myt) plot(rv,d1) p1 <- pupsilon(rv, df=mydf, t=myt) # should be nearly uniform: plot(ecdf(p1)) q1 <- qupsilon(ppoints(length(rv)),df=mydf,t=myt) qqplot(x=rv,y=q1) if (require(SharpeR)) { ope <- 252 n.sim <- 500 n.term <- 3 set.seed(234234) pp <- replicate(n.sim,{ # these are population parameters a <- rnorm(n.term) psi <- 6 * rnorm(length(a)) / sqrt(ope) b <- sum(a * psi) df <- 100 + ceiling(200 * runif(length(psi))) comm <- 1 / sqrt(sum(a^2 / df)) cdf <- df - 1 # now independent draws from the SR distribution: x <- rsr(length(df), df, zeta=psi, ope=1) # now compute a p-value under the true null pupsilon(comm * b,df=cdf,t=comm*a*x) }) # ought to be uniform: plot(ecdf(pp)) }
mydf <- c(100,30,50) myt <- c(-1,3,5) rv <- rupsilon(500, df=mydf, t=myt) d1 <- dupsilon(rv, df=mydf, t=myt) plot(rv,d1) p1 <- pupsilon(rv, df=mydf, t=myt) # should be nearly uniform: plot(ecdf(p1)) q1 <- qupsilon(ppoints(length(rv)),df=mydf,t=myt) qqplot(x=rv,y=q1) if (require(SharpeR)) { ope <- 252 n.sim <- 500 n.term <- 3 set.seed(234234) pp <- replicate(n.sim,{ # these are population parameters a <- rnorm(n.term) psi <- 6 * rnorm(length(a)) / sqrt(ope) b <- sum(a * psi) df <- 100 + ceiling(200 * runif(length(psi))) comm <- 1 / sqrt(sum(a^2 / df)) cdf <- df - 1 # now independent draws from the SR distribution: x <- rsr(length(df), df, zeta=psi, ope=1) # now compute a p-value under the true null pupsilon(comm * b,df=cdf,t=comm*a*x) }) # ought to be uniform: plot(ecdf(pp)) }