qfratio-package {qfratio}R Documentation

qfratio: Moments and Distributions of Ratios of Quadratic Forms

Description

This package is for evaluating moments of ratios (and products) of quadratic forms in normal variables, specifically using recursive algorithms developed by Bao et al. (2013) and Hillier et al. (2014) (see also Smith, 1989, 1993; Hillier et al., 2009). It also provides some functions to evaluate distribution, quantile, and probability density functions of simple ratios of quadratic forms in normal variables using several algorithms. It was originally developed as a supplement to Watanabe (2023) for evaluating average evolvability measures in evolutionary quantitative genetics, but can be used for a broader class of statistics.

Details

The primary front-end functions of this package are qfrm() and qfmrm() for evaluating moments of ratios of quadratic forms. These pass arguments to one of the several “internal” (though exported) functions which do actual calculations, depending on the argument matrices and exponents. In addition, there are a few functions to calculate moments of products of quadratic forms (integer exponents only; qfpm).

There are many internal functions for calculating coefficients in power-series expansion of generating functions for these moments (d1_i, d2_ij, d3_ijk, dtil2_pq) using “super-short” recursions (Bao and Kan, 2013; Hillier et al. 2014). Some of these coefficients are related to the top-order zonal and invariant polynomials of matrix arguments.

The package also has some functions to evaluate distribution, quantile, and density functions of simple ratios of quadratic forms: pqfr(), qqfr(), and dqfr().

See package vignettes (vignette("qfratio") and vignette("qfratio_distr")) for more details.

The DESCRIPTION file:

Package: qfratio
Type: Package
Title: Moments and Distributions of Ratios of Quadratic Forms Using Recursion
Version: 1.1.1
Date: 2024-02-08
Authors@R: c(person("Junya", "Watanabe", email = "Junya.Watanabe@uab.cat", role = c("aut", "cre", "cph"), comment = c(ORCID = "0000-0002-9810-5286")), person("Patrick", "Alken", role = "cph", comment = "Author of bundled C codes from GSL"), person("Brian", "Gough", role = "cph", comment = "Author of bundled C codes from GSL"), person("Pavel", "Holoborodko", role = "cph", comment = "Author of bundled C codes from GSL"), person("Gerard", "Jungman", role = "cph", comment = "Author of bundled C codes from GSL"), person("Reid", "Priedhorsky", role = "cph", comment = "Author of bundled C codes from GSL"), person("Free Software Foundation, Inc.", role = "cph", comment = "Copyright holder of some bundled scripts"))
Description: Evaluates moments of ratios (and products) of quadratic forms in normal variables, specifically using recursive algorithms developed by Bao and Kan (2013) <doi:10.1016/j.jmva.2013.03.002> and Hillier et al. (2014) <doi:10.1017/S0266466613000364>. Also provides distribution, quantile, and probability density functions of simple ratios of quadratic forms in normal variables with several algorithms. Originally developed as a supplement to Watanabe (2023) <doi:10.1007/s00285-023-01930-8> for evaluating average evolvability measures in evolutionary quantitative genetics, but can be used for a broader class of statistics. Generating functions for these moments are also closely related to the top-order zonal and invariant polynomials of matrix arguments.
License: GPL (>= 3)
URL: https://github.com/watanabe-j/qfratio
BugReports: https://github.com/watanabe-j/qfratio/issues
Imports: Rcpp, MASS, stats
LinkingTo: Rcpp, RcppEigen
Suggests: mvtnorm, CompQuadForm, graphics, testthat (>= 3.0.0), knitr, rmarkdown
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3
Config/testthat/edition: 3
VignetteBuilder: knitr, rmarkdown
Author: Junya Watanabe [aut, cre, cph] (<https://orcid.org/0000-0002-9810-5286>), Patrick Alken [cph] (Author of bundled C codes from GSL), Brian Gough [cph] (Author of bundled C codes from GSL), Pavel Holoborodko [cph] (Author of bundled C codes from GSL), Gerard Jungman [cph] (Author of bundled C codes from GSL), Reid Priedhorsky [cph] (Author of bundled C codes from GSL), Free Software Foundation, Inc. [cph] (Copyright holder of some bundled scripts)
Maintainer: Junya Watanabe <Junya.Watanabe@uab.cat>

Index of help topics:

KiK                     Matrix square root and generalized inverse
S_fromUL                Make covariance matrix from eigenstructure
a1_pk                   Recursion for a_{p,k}
d1_i                    Coefficients in polynomial expansion of
                        generating function-single matrix
d2_ij                   Coefficients in polynomial expansion of
                        generating function-for ratios with two
                        matrices
d3_ijk                  Coefficients in polynomial expansion of
                        generating function-for ratios with three
                        matrices
dqfr                    Probability distribution of ratio of quadratic
                        forms
dtil2_pq                Coefficients in polynomial expansion of
                        generating function-for products
hgs                     Calculate hypergeometric series
hyperg_1F1_vec_b        Internal C++ wrappers for GSL
is_diagonal             Is this matrix diagonal?
iseq                    Are these vectors equal?
new_qfrm                Construct qfrm object
p_A1B1_Ed               Internal C++ functions
print.qfrm              Methods for qfrm and qfpm objects
qfmrm                   Moment of multiple ratio of quadratic forms in
                        normal variables
qfpm                    Moment of (product of) quadratic forms in
                        normal variables
qfratio-package         qfratio: Moments and Distributions of Ratios of
                        Quadratic Forms
qfrm                    Moment of ratio of quadratic forms in normal
                        variables
range_qfr               Get range of ratio of quadratic forms
rqfr                    Monte Carlo sampling of ratio/product of
                        quadratic forms
sum_counterdiag         Summing up counter-diagonal elements
tr                      Matrix trace function

Author/Maintainer

Junya Watanabe Junya.Watanabe@uab.cat

References

Bao, Y. and Kan, R. (2013) On the moments of ratios of quadratic forms in normal random variables. Journal of Multivariate Analysis, 117, 229–245. doi:10.1016/j.jmva.2013.03.002.

Hillier, G., Kan, R. and Wang, X. (2009) Computationally efficient recursions for top-order invariant polynomials with applications. Econometric Theory, 25, 211–242. doi:10.1017/S0266466608090075.

Hillier, G., Kan, R. and Wang, X. (2014) Generating functions and short recursions, with applications to the moments of quadratic forms in noncentral normal vectors. Econometric Theory, 30, 436–473. doi:10.1017/S0266466613000364.

Smith, M. D. (1989) On the expectation of a ratio of quadratic forms in normal variables. Journal of Multivariate Analysis, 31, 244–257. doi:10.1016/0047-259X(89)90065-1.

Smith, M. D. (1993) Expectations of ratios of quadratic forms in normal variables: evaluating some top-order invariant polynomials. Australian Journal of Statistics, 35, 271–282. doi:10.1111/j.1467-842X.1993.tb01335.x.

Watanabe, J. (2023) Exact expressions and numerical evaluation of average evolvability measures for characterizing and comparing G matrices. Journal of Mathematical Biology, 86, 95. doi:10.1007/s00285-023-01930-8.

See Also

qfrm: Moment of simple ratio of quadratic forms

qfmrm: Moment of multiple ratio of quadratic forms

qfpm: Moment of product of quadratic forms

rqfr: Monte Carlo sampling of ratio/product of quadratic forms

dqfr: Probability distribution of simple ratio of quadratic forms

Examples

## Symmetric matrices
nv <- 4
A <- diag(nv:1)
B <- diag(sqrt(1:nv))
D <- diag((1:nv)^2 / nv)
mu <- nv:1 / nv
Sigma <- matrix(0.5, nv, nv)
diag(Sigma) <- 1

## Expectation of (x^T A x)^2 / (x^T x)^2 where x ~ N(0, I)
qfrm(A, p = 2)
## And a Monte Carlo mean of the same
mean(rqfr(1000, A = A, p = 2))

## Expectation of (x^T A x)^1/2 / (x^T x)^1/2 where x ~ N(0, I)
(res1 <- qfrm(A, p = 1/2))
plot(res1)
## A Monte Carlo mean
mean(rqfr(1000, A = A, p = 1/2))

## (x^T A x)^2 / (x^T B x)^3 where x ~ N(mu, Sigma)
(res2 <- qfrm(A, B, p = 2, q = 3, mu = mu, Sigma = Sigma))
plot(res2)
## A Monte Carlo mean
mean(rqfr(1000, A = A, B = B, p = 2, q = 3, mu = mu, Sigma = Sigma))

## Expectation of (x^T A x)^2 / (x^T B x) (x^T x) where x ~ N(0, I)
(res3 <- qfmrm(A, B, p = 2, q = 1, r = 1))
plot(res3)
## A Monte Carlo mean
mean(rqfmr(1000, A = A, B = B, p = 2, q = 1, r = 1))

## Expectation of (x^T A x)^2 where x ~ N(0, I)
qfm_Ap_int(A, 2)
## A Monte Carlo mean
mean(rqfp(1000, A = A, p = 2, q = 0, r = 0))

## Expectation of (x^T A x) (x^T B x) (x^T D x) where x ~ N(mu, I)
qfpm_ABDpqr_int(A, B, D, 1, 1, 1, mu = mu)
## A Monte Carlo mean
mean(rqfp(1000, A = A, B = B, D = D, p = 1, q = 1, r = 1, mu = mu))

## Distribution and quantile functions,
## and density of (x^T A x) / (x^T B x)
quantiles <- 0:nv + 0.5
(probs <- pqfr(quantiles, A, B))
qqfr(probs, A, B)     # p = 1 yields maximum of ratio
dqfr(quantiles, A, B)


[Package qfratio version 1.1.1 Index]