| Maintainer: | Steven E. Pav <shabbychef@gmail.com> |
| Version: | 0.2.5 |
| Date: | 2023-08-20 |
| License: | LGPL-3 |
| Title: | Some Additional Distributions |
| BugReports: | https://github.com/shabbychef/sadists/issues |
| 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. |
| Depends: | R (≥ 3.0.2) |
| Imports: | PDQutils (≥ 0.1.1), hypergeo, orthopolynom |
| Suggests: | SharpeR, shiny, testthat, ggplot2, xtable, formatR, knitr |
| URL: | https://github.com/shabbychef/sadists |
| VignetteBuilder: | knitr |
| Collate: | 'cumulants.r' 'dnbeta.r' 'dneta.r' 'dnf.r' 'dnt.r' 'kprime.r''lambdap.r' 'moments.r' 'prodchisqpow.r' 'proddnf.r''prodnormal.r' 'runExample.r' 'sadists.r' 'sumchisqpow.r''sumlogchisq.r' 'upsilon.r' 'utils.r' |
| RoxygenNote: | 7.1.1 |
| NeedsCompilation: | no |
| Packaged: | 2023-08-21 16:02:29 UTC; spav |
| Author: | Steven E. Pav |
| Repository: | CRAN |
| Date/Publication: | 2023-08-21 18:30:02 UTC |
Some Additional Distributions
Description
Some Additional Distributions.
Details
A collection of distributions which can be approximated viaEdgeworth and Cornish-Fisher expansions
Sum of (non-central) chi-square to powers
LetX_i \sim \chi^2\left(\delta_i, \nu_i\right)be independently distributed non-central chi-squares, where\nu_iare the degrees of freedom, and\delta_i are thenon-centrality parameters. Letw_i andp_i be given constants. Suppose
Y = \sum_i w_i X_i^{p_i}.
ThenY follows a weighted sum of chi-squares to power distribution. The special case where all thep_i are one is a 'sum ofchi-squares' distribution; The special case where all thep_i are one half is a 'sum ofchis' distribution;
Lambda Prime
Introduced by Lecoutre, the lambda prime distributionfinds use in inference on the Sharpe ratio under normalreturns.Supposey \sim \chi^2\left(\nu\right), andZ is a standard normal.
T = Z + t \sqrt{y/\nu}
takes a lambda prime distribution with parameters\nu, t.A lambda prime random variable can be viewed as a confidencevariable on a non-central t because
t = \frac{Z' + T}{\sqrt{y/\nu}}
Upsilon
The upsilon distribution generalizes the lambda prime to thecase of the sum of multiple chi variables. That is,supposey_i \sim \chi^2\left(\nu_i\right)independently and independently ofZ, a standard normal. Then
T = Z + \sum_i t_i \sqrt{y_i/\nu_i}
takes an upsilon distribution with parameter vectors[\nu_1, \nu_2, \ldots, \nu_k]', [t_1, t_2, ..., t_k]'.
The upsilon distribution is used in certain tests ofthe Sharpe ratio for independent observations.
K Prime
Introduced by Lecoutre, the K prime family of distributions generalizethe (singly) non-central t, and lambda prime distributions. Supposey \sim \chi^2\left(\nu_1\right), andx \sim t \left(\nu_2, a\sqrt{y/\nu_1}/b\right).Then the random variable
T = b x
takes a K prime distribution with parameters\nu_1, \nu_2, a, b. In Lecoutre's terminology,T \sim K'_{\nu_1, \nu_2}\left(a, b\right)
Equivalently, we can think of
T = \frac{b Z + a \sqrt{\chi^2_{\nu_1} / \nu_1}}{\sqrt{\chi^2_{\nu_2} / \nu_2}}
whereZ is a standard normal, and the normal and the (central) chi-squares areindependent of each other. Whena=0 we recovera central t distribution; when\nu_1=\infty we recover a rescaled non-central t distribution;whenb=0, we get a rescaled square root of a central Fdistribution; when\nu_2=\infty, we recover a Lambda prime distribution.
Doubly Noncentral t
The doubly noncentral t distribution generalizes the (singly)noncentral t distribution to the case where the numerator isthe square root of a scaled noncentral chi-square distribution.That is, ifX \sim \mathcal{N}\left(\mu,1\right) independentlyofY \sim \chi^2\left(k,\theta\right), thenthe random variable
T = \frac{X}{\sqrt{Y/k}}
takes a doubly non-central t distribution with parametersk, \mu, \theta.
Doubly Noncentral F
The doubly noncentral F distribution generalizes the (singly)noncentral F distribution to the case where the numerator isa scaled noncentral chi-square distribution.That is, ifX \sim \chi^2\left(n_1,\theta_1\right) independently ofY \sim \chi^2\left(n_2,\theta_2\right), thenthe random variable
T = \frac{X / n_1}{Y / n_2}
takes a doubly non-central F distribution with parametersn_1, n_2, \theta_1, \theta_2.
Parameter recycling
It should be noted that the functions provided by sadists donotrecycle their distribution parameters against thex, p, q orn parameters. This is in contrast to the common R idiom, and may cause some confusion. This is mostly for reasonsof performance, but also because some of the distributions have vector-valuedparameters; recycling over these would require the user to providelistsof parameters, which would be unpleasant.
Legal Mumbo Jumbo
sadists is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See theGNU Lesser General Public License for more details.
Note
This package is maintained as a hobby.
Author(s)
Steven E. Pavshabbychef@gmail.com
Maintainer: Steven E. Pavshabbychef@gmail.com (ORCID)
References
Lecoutre, Bruno. "Two Useful distributions for Bayesian predictiveprocedures under normal models." Journal of Statistical Planning andInference 79, no. 1 (1999): 93-105.
Poitevineau, Jacques, and Lecoutre, Bruno. "Implementing Bayesian predictiveprocedures: The K-prime and K-square distributions." Computational Statistics and Data Analysis 54, no. 3 (2010): 724-731.https://arxiv.org/abs/1003.4890v1
Walck, C. "Handbook on Statistical Distributions for experimentalists."1996.https://www.stat.rice.edu/~dobelman/textfiles/DistributionsHandbook.pdf
See Also
Useful links:
The doubly non-central Beta distribution.
Description
Density, distribution function, quantile function and randomgeneration for the doubly non-central Beta distribution.
Usage
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)Arguments
x,q | vector of quantiles. |
df1,df2 | the degrees of freedom for the numerator and denominator.We donot recycle these versus the |
ncp1,ncp2 | the non-centrality parameters for the numerator and denominator.We donot 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 |
Details
Supposex_i \sim \chi^2\left(\delta_i,\nu_i\right)be independent non-central chi-squares fori=1,2.Then
Y = \frac{x_1}{x_1 + x_2}
takes a doubly non-central Beta distribution with degrees of freedom\nu_1, \nu_2 and non-centrality parameters\delta_1,\delta_2.
Value
ddnbeta gives the density,pdnbeta gives the distribution function,qdnbeta gives the quantile function, andrdnbeta generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
See Also
(doubly non-central) F distribution functions,ddnf,pdnf,qdnf,rdnf.
Examples
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)The doubly non-central Eta distribution.
Description
Density, distribution function, quantile function and randomgeneration for the doubly non-central Eta distribution.
Usage
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)Arguments
x,q | vector of quantiles. |
df | the degrees of freedom for the denominator chi square.We donot recycle this versus the |
ncp1,ncp2 | the non-centrality parameters for the numerator and denominator.We donot 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 |
Details
SupposeZ is a normal with mean\delta_1,and standard deviation 1, independent ofX \sim \chi^2\left(\delta_2,\nu_2\right),a non-central chi-square with\nu_2 degrees of freedomand non-centrality parameter\delta_2. Then
Y = \frac{Z}{\sqrt{Z^2 + X}}
takes a doubly non-central Eta distribution with\nu_2 degrees of freedom and non-centrality parameters\delta_1,\delta_2. Thesquare ofa doubly non-central Eta is a doubly non-central Beta variate.
Value
ddneta gives the density,pdneta gives the distribution function,qdneta gives the quantile function, andrdneta generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
See Also
(doubly non-central) t distribution functions,ddnt,pdnt,qdnt,rdnt.
(doubly non-central) Beta distribution functions,ddnbeta,pdnbeta,qdnbeta,rdnbeta.
Examples
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)The doubly non-central F distribution.
Description
Density, distribution function, quantile function and randomgeneration for the doubly non-central F distribution.
Usage
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)Arguments
x,q | vector of quantiles. |
df1,df2 | the degrees of freedom for the numerator and denominator.We donot recycle these versus the |
ncp1,ncp2 | the non-centrality parameters for the numerator and denominator.We donot 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 |
Details
Supposex_i \sim \chi^2\left(\delta_i,\nu_i\right)be independent non-central chi-squares fori=1,2.Then
Y = \frac{x_1/\nu_1}{x_2/\nu_2}
takes a doubly non-central F distribution with degrees of freedom\nu_1, \nu_2 and non-centrality parameters\delta_1,\delta_2.
Value
ddnf gives the density,pdnf gives the distribution function,qdnf gives the quantile function, andrdnf generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
See Also
(singly non-central) F distribution functions,df,pf,qf,rf.
Examples
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)The doubly non-central t distribution.
Description
Density, distribution function, quantile function and randomgeneration for the doubly non-central t distribution.
Usage
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)Arguments
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 |
Details
LetZ \sim \mathcal{N}\left(\mu,1\right) independentlyofX \sim \chi^2\left(\theta,\nu\right). The random variable
T = \frac{Z}{\sqrt{X/\nu}}
takes adoubly non-central t distribution with parameters\nu, \mu, \theta.
Value
ddnt gives the density,pdnt gives the distribution function,qdnt gives the quantile function, andrdnt generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
Krishnan, Marakatha. "Series Representations of the Doubly Noncentralt-Distribution." Journal of the American Statistical Association 63, no. 323 (1968): 1004-1012.
See Also
t distribution functions,dt,pt,qt,rt
Examples
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-centraldv1 <- 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)The K prime distribution.
Description
Density, distribution function, quantile function and randomgeneration for the K prime distribution.
Usage
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)Arguments
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 |
Details
Supposey \sim \chi^2\left(\nu_1\right), andx \sim t \left(\nu_2, a\sqrt{y/\nu_1}/b\right).Then the random variable
T = b x
takes a K prime distribution with parameters\nu_1, \nu_2, a, b. In Lecoutre's terminology,T \sim K'_{\nu_1, \nu_2}\left(a, b\right)
Equivalently, we can think of
T = \frac{b Z + a \sqrt{\chi^2_{\nu_1} / \nu_1}}{\sqrt{\chi^2_{\nu_2} / \nu_2}}
whereZ is a standard normal, and the normal and the (central) chi-squares areindependent of each other. Whena=0 we recovera central t distribution; when\nu_1=\infty we recover a rescaled non-central t distribution;whenb=0, we get a rescaled square root of a central Fdistribution; when\nu_2=\infty, we recover a Lambda prime distribution.
Value
dkprime gives the density,pkprime gives the distribution function,qkprime gives the quantile function, andrkprime generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
Lecoutre, Bruno. "Two Useful distributions for Bayesian predictiveprocedures under normal models." Journal of Statistical Planning andInference 79, no. 1 (1999): 93-105.
Poitevineau, Jacques, and Lecoutre, Bruno. "Implementing Bayesian predictiveprocedures: The K-prime and K-square distributions." Computational Statistics and Data Analysis 54, no. 3 (2010): 724-731.https://arxiv.org/abs/1003.4890v1
See Also
t distribution functions,dt,pt,qt,rt,lambda prime distribution functions,dlambdap,plambdap,qlambdap,rlambdap.
Examples
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)The lambda prime distribution.
Description
Density, distribution function, quantile function and randomgeneration for the lambda prime distribution.
Usage
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)Arguments
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 |
Details
Supposey \sim \chi^2\left(\nu\right), andZ is a standard normal.
T = Z + t \sqrt{y/\nu}
takes a lambda prime distribution with parameters\nu, t.A lambda prime random variable can be viewed as a confidencelevel on a non-central t because
t = \frac{Z' + T}{\sqrt{y/\nu}}
Value
dlambdap gives the density,plambdap gives the distribution function,qlambdap gives the quantile function, andrlambdap generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
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.
See Also
t distribution functions,dt,pt,qt,rt,K prime distribution functions,dkprime,pkprime,qkprime,rkprime,upsilon distribution functions,dupsilon,pupsilon,qupsilon,rupsilon,
Examples
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)The product of (non-central) chi-squares raised to powers distribution.
Description
Density, distribution function, quantile function and randomgeneration for the distribution of the product of non-centralchi-squares taken to powers.
Usage
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)Arguments
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 |
Details
LetX_i \sim \chi^2\left(\delta_i, \nu_i\right)be independently distributed non-central chi-squares, where\nu_iare the degrees of freedom, and\delta_i are thenon-centrality parameters. Letp_i be given constants. Suppose
Y = \prod_i X_i^{p_i}.
ThenY follows a product of chi-squares to power distribution.
Value
dprodchisqpow gives the density,pprodchisqpow gives the distribution function,qprodchisqpow gives the quantile function, andrprodchisqpow generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
The PDQ functions are computed by translation of the sum of log chi-squares distribution functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
Pav, Steven. Moments of the log non-central chi-square distribution.https://arxiv.org/abs/1503.06266
See Also
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.
Examples
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)The product of multiple doubly non-central F's distribution.
Description
Density, distribution function, quantile function and randomgeneration for the product of multiple independent doubly non-central F variates.
Usage
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)Arguments
x,q | vector of quantiles. |
df1,df2 | the vectors of the degrees of freedom for the numerator and denominator.We donot recycle these versus the |
ncp1,ncp2 | the vectors of the non-centrality parameters for the numerator and denominator.We donot 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 |
Details
Let
x_j \sim F\left(\delta_{1,j},\delta_{2,j},\nu_{1,j},\nu_{2,j}\right)
be independent doubly non-central F variates with non-centrality parameters\delta_{i,j} and degrees of freedom\nu_{i,j} fori=1,2,\ldots,I andj=1,2.Then
Y = \prod_j x_j
takes a product of doubly non-central F's distribution. We take theparameters of this distribution as the fourI length vectorsof the two degrees of freedom and the two non-centrality parameters.
Value
dproddnf gives the density,pproddnf gives the distribution function,qproddnf gives the quantile function, andrproddnf generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
The PDQ functions are computed by translation of the sum of log chi-squares distribution functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
Pav, Steven. Moments of the log non-central chi-square distribution.https://arxiv.org/abs/1503.06266
See Also
The sum of log of chi-squares distribution,dsumlogchisq,psumlogchisq,qsumlogchisq,rsumlogchisq.(doubly non-central) F distribution functions,ddnf,pdnf,qdnf,rdnf.
Examples
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)The product of normal random variates.
Description
Density, distribution function, quantile function and randomgeneration for the distribution of the product of indepdendentnormal random variables.
Usage
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)Arguments
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 |
Details
LetZ_i \sim \mathcal{N}\left(\mu_i, \sigma_i^2\right)be independently distributed normal variates, with means\mu_iand variances\sigma_i^2.Suppose
Y = \prod_i Z_i.
ThenY follows a product of normals distribution.
Value
dprodnormal gives the density,pprodnormal gives the distribution function,qprodnormal gives the quantile function, andrprodnormal generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
Examples
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)Run Shiny Application
Description
Runs a shiny application which draws from the given distributions, thenillustrates the fidelity of the density, CDF, and quantile functions.
Usage
runExample(port=NULL,launch.browser=TRUE, host=getOption('shiny.host','127.0.0.1'),display.mode='auto')Arguments
port | The TCP port that the application should listen on. If the |
launch.browser | If true, the system's default web browser will belaunched automatically after the app is started. Defaults to true ininteractive sessions only. This value of this parameter can also be afunction to call with the application's URL. |
host | The IPv4 address that the application should listen on. Defaultsto the |
display.mode | The mode in which to display the application. If set tothe value |
Details
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 plotsare available.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
Attali, D. "Supplementing your R package with a shiny app."https://deanattali.com/2015/04/21/r-package-shiny-app/
Examples
## Not run: runExample(launch.browser=TRUE)## End(Not run)News for package 'sadists'
Description
History of the 'sadists' package.
Version 0.2.5 (2023-08-20)
CRAN emergency release.
Version 0.2.4 (2020-06-23)
CRAN emergency release.
Version 0.2.3 (2017-03-19)
add product of normals distribution.
move github figures to location CRAN understands.
Version 0.2.2 (2016-03-03)
work around bad
rchisqwhendf=0=ncp(?)incompatibilities in vignette with ggplot2 release.
Version 0.2.1 (2015-06-12)
shiny app (h/t Dean Attali).
Version 0.2.0 (2015-04-01)
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.
Initial Version 0.1.0 (2015-03-07)
first CRAN release.
The sum of (non-central) chi-squares raised to powers distribution.
Description
Density, distribution function, quantile function and randomgeneration for the distribution of the weighted sum of non-centralchi-squares taken to powers.
Usage
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)Arguments
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 |
Details
LetX_i \sim \chi^2\left(\delta_i, \nu_i\right)be independently distributed non-central chi-squares, where\nu_iare the degrees of freedom, and\delta_i are thenon-centrality parameters. Letw_i andp_i be given constants. Suppose
Y = \sum_i w_i X_i^{p_i}.
ThenY follows a weighted sum of chi-squares to power distribution.
Value
dsumchisqpow gives the density,psumchisqpow gives the distribution function,qsumchisqpow gives the quantile function, andrsumchisqpow generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
The 'sum of chisquare power' distribution doesnot generalizethe 'chi-bar-square' distribution, whosedensity is the sum ofchi-square densities.
Author(s)
Steven E. Pavshabbychef@gmail.com
See Also
The upsilon distribution,dupsilon,pupsilon,qupsilon,rupsilon.
Examples
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)The sum of the logs of (non-central) chi-squares distribution.
Description
Density, distribution function, quantile function and randomgeneration for the distribution of the weighted sum of logs ofnon-central chi-squares.
Usage
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)Arguments
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 |
Details
LetX_i \sim \chi^2\left(\delta_i, \nu_i\right)be independently distributed non-central chi-squares, where\nu_iare the degrees of freedom, and\delta_i are thenon-centrality parameters. Letw_i be given constants. Suppose
Y = \sum_i w_i \log X_i.
ThenY follows a weighted sum of log of chi-squares distribution.
Value
dsumlogchisq gives the density,psumlogchisq gives the distribution function,qsumlogchisq gives the quantile function, andrsumlogchisq generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
Pav, Steven. Moments of the log non-central chi-square distribution.https://arxiv.org/abs/1503.06266
See Also
The product of chi-squares to a power,dprodchisqpow,pprodchisqpow,qprodchisqpow,rprodchisqpow.
Examples
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)The upsilon distribution.
Description
Density, distribution function, quantile function and randomgeneration for the upsilon distribution.
Usage
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)Arguments
x,q | vector of quantiles. |
df | the degrees of freedom in the chi square. a vector. we donot vectorize over this variable. |
t | the scaling parameter on the chi. a vector. should be the samelength 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 |
Details
Supposex_i \sim \chi^2\left(\nu_i\right)independently and independently ofZ, a standard normal. Then
\Upsilon = Z + \sum_i t_i \sqrt{x_i/\nu_i}
takes an upsilon distribution with parameter vectors[\nu_1, \nu_2, \ldots, \nu_k]', [t_1, t_2, ..., t_k]'.
The upsilon distribution is used in certain tests ofthe Sharpe ratio for independent observations, and generalizesthe lambda prime distribution, which can be written asZ + t \sqrt{x/\nu}.
Value
dupsilon gives the density,pupsilon gives the distribution function,qupsilon gives the quantile function, andrupsilon generates random deviates.
Invalid arguments will result in return valueNaN with a warning.
Note
the PDF and CDF are approximated by an Edgeworth expansion; thequantile function is approximated by a Cornish-Fisher expansion.
The PDF, CDF, and quantile function are approximated, viathe Edgeworth or Cornish Fisher approximations, which maynot be terribly accurate in the tails of the distribution.You are warned.
The distribution parameters arenot recycledwith respect to thex, p, q orn parameters,for, respectively, the density, distribution, quantileand generation functions. This is for simplicity ofimplementation and performance. It is, however, in contrastto the usual R idiom for dpqr functions.
Author(s)
Steven E. Pavshabbychef@gmail.com
References
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).https://arxiv.org/abs/1505.00829
See Also
lambda-prime distribution functions,dlambdap,plambdap,qlambdap,rlambdap.Sum of chi-squares to power distribution functions,dsumchisqpow,psumchisqpow,qsumchisqpow,rsumchisqpow.
Examples
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)) }