qfratio: Moments of Ratios of Quadratic Forms

This document is to provide an overview of the moment-related functionalities of the R package qfratio (CRAN; GitHub). Distribution-related functionalities are documented in a separate vignette: vignette("qfratio_distr").

Symbols used

  • n: number of variables
  • m: order of evaluation at which infinite series is truncated
  • p, q, r: exponents of quadratic forms (positive real numbers)
  • t1, …, ts: parameters in generating functions; s here denotes the number of arguments (typically s = 2 or 3)
  • a, d, , h, , : coefficients in generating functions defined in text
  • C: (top-order) zonal and invariant polynomials of matrix arguments (Chikuse, 1980, 1987; Davis, 1980; Muirhead, 1982)
  • x: n-variate random vector (in most cases normal)
  • $\qfrmvnorm{\boldsymbol{\mu}}{\boldsymbol{\Sigma}}$: n-variate normal distribution with mean vector μ and covariance matrix Σ
  • A, B, D: n × n argument matrices
  • In: n-dimensional identity matrix
  • 0n: n-variate vector of 0’s
  • 0n × n: n × n matrix of 0’s
  • $\qfrE \left( \cdot \right)$: expectation/mean
  • $\qfrGmf{\cdot}$: gamma function
  • (x)a: Pochhammer symbol, that is, (x)a = x(x + 1)…(x + a − 1) (with the convention (x)0 = 1)
  • AT: matrix transposition
  • A−1: matrix inverse
  • $\mathbf{A}^{-\frac{1}{2}}$: (symmetric) matrix satisfying $\mathbf{A}^{-\frac{1}{2}} \mathbf{A} \mathbf{A}^{-\frac{1}{2}} = \mathbf{I}_n$, assuming positive definite A
  • det A: matrix determinant
  • $\qfrtr{\mathbf{A}}$: matrix trace
  • λi: ith eigenvalue of the matrix concerned
  • $\qfrlmax$: largest eigenvalue of the matrix concerned
  • hi: eigenvector corresponding to λi
  • βA: scaling constant that satisfies $0 < \beta < 2 / \qfrlmax$ for A
  • A+: matrix with “positivized” eigenvalues, i.e., $\mathbf{A}^+ = \sum_{i=1}^n \lvert \lambda_i \rvert \mathbf{h}_i \mathbf{h}_i^T$

The use of n for the number of variables and p, q, … for exponents is to conform with Bao and Kan (2013).

Target

The package primarily concerns moments of ratios of quadratic forms of the following forms: In this package, these are called a simple and multiple ratio, respectively, following Smith (1989) (to be precise, the latter is a very specific case of the multiple ratios treated therein).

Quantities of the above forms frequently occur in the statistical and econometric literature (Mathai and Provost, 1992; Hillier et al., 2009, 2014). In evolutionary biology, the quantities known as evolvability measures have the same general form, and evaluation of their expectation (average or mean evolvability measures) can be of practical interest (Hansen and Houle, 2008; Melo et al., 2016; Watanabe, 2023).

The package is mainly for evaluating the moments of the above quantity assuming the multivariate normality of x, that is, where $\mathbf{x} \sim \qfrmvnorm{\boldsymbol{\mu}}{\boldsymbol{\Sigma}}$.

First examples

Here are simple example use cases:

## Simple matrices
nv <- 4
A <- diag(1:nv)
B <- diag(sqrt(nv:1))
D <- diag((nv:1) ^ 2)

## Expectation of (x^T A x)^2 / (x^T x)^1 where x ~ N(0, I)
qfrm(A, p = 2, q = 1) # By default, B = I
#> 
#>  Moment of ratio of quadratic forms
#> 
#> Moment = 26.66667
#> This value is exact

## Expectation of (x^T A x)^2 / (x^T B x)^2 where x ~ N(0, I)
qfrm(A, B, p = 2) # By default, q = p
#> 
#>  Moment of ratio of quadratic forms
#> 
#> Moment = 3.467871, Error = 0 (one-sided)
#> Possible range:
#>  3.46787143 3.46787143

## Expectation of (x^T A x)^1/2 / (x^T B x)^1 where x ~ N(0, I)
qfrm(A, B, p = 1/2, q = 1)
#> 
#>  Moment of ratio of quadratic forms
#> 
#> Moment = 0.6652398
#> Error bound unavailable; recommended to inspect plot() of this object

## Expectation of (x^T A x)^2 / ((x^T B x)^1 (x^T D x)^1) where x ~ N(0, I)
qfmrm(A, B, D, p = 2, q = 1, r = 1)
#> 
#>  Moment of ratio of quadratic forms
#> 
#> Moment = 1.135126
#> Error bound unavailable; recommended to inspect plot() of this object

## Expectation of (x^T A x)^1 / (x^T B x)^1 where x ~ N(mu, Sigma)
## with arbitrary mu and Sigma
mu <- 1:nv / nv
Sigma <- diag(runif(nv) * 3)
qfrm(A, B, p = 1, q = 1, mu = mu, Sigma = Sigma, m = 300)
#> 
#>  Moment of ratio of quadratic forms
#> 
#> Moment = 2.210412, Error = 0 (two-sided)
#> Possible range:
#>  2.21041201 2.21041201

In each of the above examples, the function qfrm() (quadratic form ratio moment) or qfmrm() (quadratic form multiple ratio moment) is called to calculate the moment. The function calls are followed by outputs from the print method for the results, which show the values of the moments.

You might have wondered what it means by results being “exact” or having “error”, or about the unexplained argument m = 300 in the last example. Seeing this requires some excursion into the math involved.

Mathematical details

Moment existence conditions

For the above quantities to be well-defined and have finite moments:

  • B (and D) must be nonnegative definite (i.e., has no negative eigenvalues)
  • when p is non-positive-integer, A must be nonnegative definite as well

For the simple ratio, the necessary and sufficient conditions for the moment to exist is stated in Bao and Kan (2013, proposition 1):

  1. When B is positive definite, the moment exists if and only if $\frac{n}{2} + p > q$.
  2. When B is positive semidefinite with rank l, consider a matrix of its eigenvectors P = (P1, P2), with P1 and P2 being n × l and n × (n − l) submatrices corresponding to the nonzero and zero eigenvalues, respectively, and let $\tilde{\mathbf{A}}_{12} = \mathbf{P}_1^T \mathbf{A} \mathbf{P}_2$ and $\tilde{\mathbf{A}}_{22} = \mathbf{P}_2^T \mathbf{A} \mathbf{P}_2$. Then,
    • when $\tilde{\mathbf{A}}_{12} = \mathbf{0}_{l \times (n - l)}$ and $\tilde{\mathbf{A}}_{22} = \mathbf{0}_{(n - l) \times (n - l)}$, the moment exists if and only if $\frac{l}{2} + p > q$;
    • when $\tilde{\mathbf{A}}_{12} \neq \mathbf{0}_{l \times (n - l)}$ and $\tilde{\mathbf{A}}_{22} = \mathbf{0}_{(n - l) \times (n - l)}$, the moment exists if and only if $\frac{l + p}{2} > q$; and
    • when $\tilde{\mathbf{A}}_{22} \neq \mathbf{0}_{(n - l) \times (n - l)}$, the moment exists if and only if $\frac{l}{2} > q$.

For the multiple ratio, the existence conditions are more difficult to define. When the null space of B is a subspace of that of D (or vice versa), the existence problem reduces to that of the simple ratio, and the above conditions apply by inserting the rank of B and q + r into l and q above (Watanabe, 2023). However, when both B and D are singular and neither of their ranges is a subspace of each other, no general existence conditions seem to be known in the literature. See the documentations for qfrm and qfmrm for the behaviors when the existence conditions are not satisfied.

Expressions for moments

There are several equivalent expressions for moments of ratios of quadratic forms in normal variables, only some of which are amenable to straightforward numerical evaluation. The package uses one class of such expressions, based on a series expansion and term-by-term integration of a ratio (Smith, 1989, 1993; Hillier, 2001; Hillier et al., 2009, 2014; Bao and Kan, 2013).

The following expressions assume $\mathbf{x} \sim \qfrmvnorm{\boldsymbol{\mu}}{\mathbf{I}_n}$. For arbitrary but nonsingular Σ, it is always possible to transform the variables and argument matrices by using xnew = K−1x, Anew = KTAK, etc., where K is an n × n matrix that satisfies KKT = Σ (Mathai and Provost, 1992, chap. 3). When Σ is singular, certain conditions need to be met by the argument matrices, Σ, and μ for this transformation, and hence the following expressions, to be valid (Watanabe, 2023, appendix C).

For the simple ratio with an arbitrary (positive real) p, when the moment exists, the expression is (Bao and Kan, 2013, eq. (12)) and for a positive-integral p, this can be simplified into (Bao and Kan, 2013, eq. (13), correcting a typo):

For the multiple ratio, the expression for an arbitrary p is (after Smith, 1989, eq. (5.2)) and for a positive-integral p (Watanabe, 2023, eq. (B28)),

In these expressions, β are arbitrary scaling constants that satisfy $0 < \beta < 2 / \qfrlmax$, with $\qfrlmax$ being the largest eigenvalue of the argument matrix. In addition, hk1, …ks and k1; k2ks are the coefficients of t1k1tsks in the following power series expansions: (These notations follow Bao and Kan (2013); Hillier et al. (2014) used the symbol h for here.)

A common special case is when μ = 0n, in which case the coefficients d in the following expansion is used:

Actually, the above expressions (1)–(4) can be written in terms of d with an additional argument (Hillier et al., 2009; Bao and Kan, 2013), but those alternative expressions are not utilized in the package.

A theoretically important result is that this d is related to the top-order zonal and invariant polynomials of matrix arguments, C (Chikuse, 1987; Hillier et al., 2009): where $\qfrbrc{k_i}$ and the like denote the top-order partitions of ki, in the notation of Smith (1989).

Note that the order of the argument matrices is arbitrary in d or h, but not in where A1 is not interchangeable with the other arguments.

Special cases

A notable special case for moments of simple ratios is when p is a positive integer and B = In. In this case, (2) simplifies into (Hillier et al., 2014, theorem 4) where 1F1(⋅; ⋅; ⋅) is the confluent hypergeometric function, and ap, k are the coefficients of tp in As the lowest-order term in this last expansion is that of tk, ap, k = 0 for k > p, so that the series in (5) truncates at k = p. This truncation enables quasi-exact evaluation of the moment, given accurate evaluation of the hypergeometric function.

When μ = 0n in addition, (5) further simplifies as ap, k = 0 for k > 0, so that the series essentially vanishes leaving only the term for k = 0. Similar simplification happens in (1), (3), and (4) as well when any of the argument matrices is In and μ = 0n, although they will still involve a single or double infinite series.

Numerical evaluation

The above expressions (1)–(4) are exact, but their exact values cannot generally be evaluated as they involve infinite series, except when the conditions for (5) apply. Fortunately, the series are absolutely convergent, so that their partial sums up to certain orders typically yield a sufficiently accurate result. This is what is done by the qfrm() and qfmrm() functions. The order of evaluation is determined by the argument m; the functions calculate the terms from i = j = k = 0 to i + j + k ≤ m (as i, j, k appear in the above summations) and then return an m + 1 vector that contains sums of the same-order terms, along with other things.

The default is m = 100, which sufficed for most of the above examples, but for large problems, the user would want to use a larger value (which can be hundreds of thousands for very large problems; see below).

The coefficients d, h, are evaluated by recursive algorithms described below. At the core of this package are internal functions to implement these recursive algorithms, which can be computationally intensive as the problem becomes larger.

Truncation error

A great advantage in the above expressions is that an error bound is available for a partial (truncated) sum for the simple ratio, provided that p is a positive integer and B is positive definite. By denoting the expression (2) as M(A, B, p, q) and the partial sum of the same up to j = m as m(A, B, p, q), the error bound is (Hillier et al., 2014, theorem 7) where A+ is a symmetric matrix constructed from the eigenvectors and “positivized” eigenvalues of A (above), $\bar{\boldsymbol{\mu}} = \sqrt{2}\left( \beta_\mathbf{B} \mathbf{B} \right)^{-\frac{1}{2}} \boldsymbol{\mu}$, $\bar{\mathbf{A}} = \beta_{\mathbf{B}}^{-1} \mathbf{B}^{-\frac{1}{2}} \mathbf{A}^+ \mathbf{B}^{-\frac{1}{2}}$, and and are coefficients in the following generating functions:

For the multiple ratio, a similar error bound is available when D = In, in addition to p being a positive integer. By denoting the expression (4) as M(A, B, D, p, q, r), and the partial sum of (4) up to j + k = m as m(A, B, D, p, q, r), the error bound is where $\tilde{\boldsymbol{\mu}} = \sqrt{3}\left( \beta_\mathbf{B} \mathbf{B} \right)^{-\frac{1}{2}} \boldsymbol{\mu}$ and other notations are as above.

Recursions

The coefficients h, , and in the above series expressions are evaluated by the “super-short” recursive algorithm developed by Hillier and colleagues (Bao and Kan, 2013; Hillier et al., 2014). That is, where with the initial conditions h0, 0, 0 = 0, 0, 0 = 0, 0, 0 = 1 (as per Hillier et al. (2014), but not 0, as incorrectly printed in Bao and Kan (2013)), $\mathbf{G}_{0,0,0} = \tilde{\mathbf{G}}_{0,0,0} = \hat{\mathbf{G}}_{0,0,0} = \mathbf{0}_{n \times n}$, and $\mathbf{g}_{0,0,0} = \tilde{\mathbf{g}}_{0,0,0} = \hat{\mathbf{g}}_{0,0,0} = \mathbf{0}_n$. If any of the indices is negative, the term is treated as 0.

The recursion for d can be obtained by just inserting μ = 0n (and hence omitting g altogether) in that for h, and those for the two-argument versions are by omitting any terms with A3 or k − 1 as an index in the corresponding three-argument versions.

The recursion for $\qfrdtk{\mathbf{A}}{\boldsymbol{\mu}}$ is (Bao and Kan, 2013; Hillier et al., 2014): where with λi being the ith eigenvalue of A, δi = (hiTμ)2, hi being the eigenvector of A corresponding to λi, and the initial conditions are 0 = 1 and u0, i = v0, i = 0 for all i.

The recursion for ap, k(A, μ) is (Hillier et al., 2014, eqs. (31), (32), noting that w should be indexed by k as well): where with $a_{p,0} = \qfrdk[p]{\mathbf{A}}$ and w0, k, i = 0 for any k, i.

The recursion for $\qfrdk{\mathbf{A}}$ can be obtained either as that for $\qfrdtk{\mathbf{A}}{\mathbf{0}_n}$ (where all v’s are 0) or by dropping any terms with A2 or j − 1 as an index from that for the two-argument version of d above.

Functions

The package is designed for evaluation of moments of ratios of quadratic forms using the recursive algorithms described above. The primary front-end functions are qfrm() and qfmrm(), which return a qfrm object containing terms in the truncated series and error bound when available. Simple print and plot methods are defined for the qfrm class, for quick inspection of evaluation results.

qfrm(): quadratic form ratio moment

This function is for evaluating moments of the simple ratios of quadratic forms, $\qfrE \left( \frac{\left( \mathbf{x}^T \mathbf{A} \mathbf{x} \right)^p} {\left( \mathbf{x}^T \mathbf{B} \mathbf{x} \right)^q} \right)$, where $\mathbf{x} \sim \qfrmvnorm{\boldsymbol{\mu}}{\boldsymbol{\Sigma}}$.

Usage

qfrm(A, B, p = 1, q = p, m = 100L,
     mu = rep.int(0, n), Sigma = diag(n),
     tol_zero = .Machine$double.eps * 100,
     tol_sing = tol_zero, ...)

A and B are the argument matrices; when one is missing, In is inserted.

m determines the order of evaluation, so will be one of the most important arguments specified by the user.

mu and Sigma specify the mean and covariance of x, so by default $\mathbf{x} \sim \qfrmvnorm{\mathbf{0}_n}{\mathbf{I}_n}$.

tol_zero and tol_sing just determine the numerical tolerance for assessing identity and singularity, respectively, so usually need not be changed except when handling edgy cases.

Inside the function

When Sigma is provided and not In, this function calls itself recursively with A, B, and mu transformed as described above (and dropping Sigma).

As the evaluation is based on different series expressions depending on whether B = In or not and whether p is an integer or not, the actual calculation is done by one of the following four “internal” functions, for which qfrm() acts as a switcher:

Function Argument matrices p Expression Error bound Number of recursions
qfrm_ApIq_int() B = In integer (5) Exact*  ∼ p
qfrm_ApIq_npi() B = In non-positive-integer (1) (simplified when μ = 0n) Available only when μ = 0n  ∼ m when μ = 0n;  ∼ m2/2 otherwise
qfrm_ApBq_int() B arbitrary integer (2) Available  ∼ (p + 1)m
qfrm_ApBq_npi() B arbitrary non-positive-integer (1) Unavailable  ∼ m2/2

*: assuming accurate evaluation of the confluent hypergeometric function when μ ≠ 0n

These functions are exported into the package namespace so can be directly used if necessary.

They do the following operations:

  1. Check structures of arguments (e.g., A, B being square, p, q being scalar)
  2. Symmetrize the argument matrices (A <- (A + t(A)) / 2; same for B)
  3. Rotate A, B, and mu with the eigenvectors of B, to
    • check for the moment existence conditions (above)
    • see whether A is co-diagonalized, in which case computation can be simplified
  4. Calculate d, h, or up to the order m with an internal function
  5. Multiply the result with the appropriate coefficients in (1), (2) or (5) with an internal function
  6. In qfrm_ApBq_npi(), the same-order terms in the double series are summed up
  7. Conduct a rough check of numerical convergence
  8. Calculate the sequence of error bound as in the steps 4–6 when applicable
  9. Return a structured object including the series and error bound

By default, the steps 4–8 are handled by internal C++ functions. The steps 7 and 8 can be suppressed if desired (by using check_convergence = "none" or FALSE and error_bound = FALSE, respectively).

qfmrm(): quadratic form multiple ratio moment

This function is for evaluating moments of the multiple ratios of quadratic forms, $\qfrE \left( \frac{\left( \mathbf{x}^T \mathbf{A} \mathbf{x} \right)^p} {\left( \mathbf{x}^T \mathbf{B} \mathbf{x} \right)^q\left( \mathbf{x}^T \mathbf{D} \mathbf{x} \right)^r} \right)$, where $\mathbf{x} \sim \qfrmvnorm{\boldsymbol{\mu}}{\boldsymbol{\Sigma}}$.

It works in a way very similar to qfrm(), just with the additional arguments D and r. The corresponding “internal” functions are:

Function Argument matrices p Expression Error bound Number of recursions
qfmrm_ApBIqr_int() D = In integer (4) (simplified when μ = 0n) Available  ∼ (p + 1)m when μ = 0n;  ∼ (p + 1)m2/2 otherwise
qfmrm_ApBIqr_npi() D = In non-positive-integer (3) (simplified when μ = 0n) Unavailable  ∼ m2/2 when μ = 0n;  ∼ m3/6 otherwise
qfmrm_IpBDqr_gen() A = In general (4) simplified (when μ = 0n) or (3) (otherwise) Unavailable  ∼ m2/2 when μ = 0n;  ∼ m3/6 otherwise
qfmrm_ApBDqr_int() Arbitrary integer (4) Unavailable  ∼ (p + 1)m2/2
qfmrm_ApBDqr_npi() Arbitrary non-positive-integer (3) Unavailable  ∼ m3/6

Usage

qfmrm(A, B, D, p = 1, q = p/2, r = q, m = 100L,
      mu = rep.int(0, n), Sigma = diag(n),
      tol_zero = .Machine$double.eps * 100,
      tol_sing = tol_zero, ...)

Essentially the same as qfrm().

qfm_Ap_int(), qfpm_ABpq_int(), qfpm_ABDpqr_int(): quadratic form (product) moment

These functions are for evaluating moments of (products of) quadratic forms, $\qfrE \left( \left( \mathbf{x}^T \mathbf{A} \mathbf{x} \right)^p \right)$, $\qfrE \left( \left( \mathbf{x}^T \mathbf{A} \mathbf{x} \right)^p \left( \mathbf{x}^T \mathbf{B} \mathbf{x} \right)^q \right)$, and $\qfrE \left( \left( \mathbf{x}^T \mathbf{A} \mathbf{x} \right)^p \left( \mathbf{x}^T \mathbf{B} \mathbf{x} \right)^q \left( \mathbf{x}^T \mathbf{D} \mathbf{x} \right)^r \right)$, where $\mathbf{x} \sim \qfrmvnorm{\boldsymbol{\mu}}{\boldsymbol{\Sigma}}$, using the algorithm described in Hillier et al. (2014, secs. 3–4). The exponents must be positive integers.

In principle, the same algorithm can be applied to a product of more than three quadratic forms, but this package has not implemented functions for them.

As these expressions only involve finite series, all the results are exact. The functions return a qfpm object, for which a simple print method is defined.

Usage

qfpm_ABDpqr_int(A, B, D, p = 1, q = 1, r = 1,
                mu = rep.int(0, n), Sigma = diag(n),
                use_cpp = TRUE, cpp_method = "double",
                tol_zero = .Machine$double.eps * 100,
                tol_sing = tol_zero)

The other two functions have the same arguments, just dropping the inapplicable argument matrices and exponents.

cpp_method is a dummy argument and ignored in these functions.

rqfr(), rqfmr(), rqfp(): random number generation

These functions generate a random sample of the simple ratio $\frac{\left( \mathbf{x}^T \mathbf{A} \mathbf{x} \right)^p} {\left( \mathbf{x}^T \mathbf{B} \mathbf{x} \right)^q}$, multiple ratio $\frac{\left( \mathbf{x}^T \mathbf{A} \mathbf{x} \right)^p} {\left( \mathbf{x}^T \mathbf{B} \mathbf{x} \right)^q\left( \mathbf{x}^T \mathbf{D} \mathbf{x} \right)^r}$, and product (xTAx)p(xTBx)q(xTDx)r, respectively, of quadratic forms in normal variables $\mathbf{x} \sim \qfrmvnorm{\boldsymbol{\mu}}{\boldsymbol{\Sigma}}$.

They can be used for verifying results from the above functions, or as a Monte Carlo surrogate when numerical convergence cannot be obtained within reasonable computational memory and time.

Usage

rqfr(nit = 1000L, A, B, p = 1, q = p, mu, Sigma, use_cpp = TRUE)
rqfmr(nit = 1000L, A, B, D, p = 1, q = p/2, r = q, mu, Sigma, use_cpp = TRUE)
rqfp(nit = 1000L, A, B, D, p = 1, q = 1, r = 1, mu, Sigma, use_cpp = TRUE)

Similar to the regular random number generation functions, e.g., stats::rnorm(); the first argument nit is the desired size of the random sample (or number of iteration), followed by other parameters.

d1_i(), d2_*j_*(), d3_*jk_*(), etc.: recursion algorithms

The package has a number of internal functions that implement the recursive algorithms described above. They are usually not accessed by the user, but are documented herein to aid understanding of the package structure. Note also that, by default, the actual calculations are handled by C++ equivalents, which are not exposed to the user.

Arranged in the target variable and the number of argument matrices, these are:

Target One matrix Two matrices Three matrices
d d1_i() d2_ij_*(), d2_pj_*() d3_ijk_*(), d3_pjk_*()
dtil1_i_*() dtil2_pq_*() dtil3_pqr_*()
h h2_ij_*() h3_ijk_*()
htil2_pj_*() htil3_pjk_*()
hhat2_pj_*() htil3_pjk_*()
a a1_pk()

The functions with *_ij_* or *_ijk_* are to calculate terms in double and triple infinite series, with the dimensions of the output determined by the argument m (typically used with non-integer p, (1) or (3) above), whereas *_pj_* and *_pjk_* are for the terms in series truncated along the first argument matrix (used with integral p, (2) or (4)). The one matrix functions assume either of these two cases, and dtil2_pq_*() and dtil3_pqr_*() assume finite series along all argument matrices.

All these functions, excepting d1_i() and a1_pk(), have two versions ending in *_m or *_v, which stand for the matrix and vector “methods”. The latter is for the situations where all the argument matrices are co-diagonalized by the same eigenvectors, in which case the above recursive algorithms reduce from full matrix arithmetic to element-wise operations of the eigenvalues (and the rotated mean vector), which is much less computationally intensive.

Most of these functions automatically scale the result to avoid numerical overflow, and (log of) the scaling factors are appended as an attribute of the return value, so that the front-end functions can appropriately scale the results back to the original one (see below).

Using the functionality

Checking for numerical convergence

In the last example above, the argument tol_conv was used to adjust the tolerance in assessing numerical convergence; by default (check_convergence = "relative"), a warning is thrown when the ratio of the last term in the series to the partial sum is larger than this tolerance, whose default is .Machine$double.eps ^ (1/4) (= ~1.2e-4). Using a smaller value for this argument as done above can safeguard against non-convergence, although it is up to the user’s discretion at which point the result is deemed satisfactory.

Other options:

  • check_convergence = "strict_relative" or TRUE: sets tol_conv = .Machine$double.eps (unless a smaller tol_conv is specified by the user), which is rather strict
  • check_convergence = "absolute": check is done in terms of absolute value rather than relative magnitude
  • check_convergence = "none" or FALSE: skips convergence check

Computational cost

The computational cost for the recursive algorithms increases drastically with the order of evaluation m. An approximate number of recursions required in each function is listed in the tables for qfrm and qfmrm functions above; the computational memory and time increase at least proportionally to this value. Of course the computational cost is also influenced by the number of variables n.

In extremely large problems, therefore, it may be impossible to obtain a satisfactory numerical convergence within reasonable amount of time and memory. A potential practical alternative is a Monte Carlo approach using rqfr().

## A large problem
nv <- 200
large_A <- diag(c(1000, rep.int(1, nv - 1)))
large_B <- diag(c(rep.int(1, nv - 1), 1000))
large_D <- diag((nv:1) ^ 2)

res <- qfmrm(large_A, large_B, large_D, 1, 1/2, 1/2, m = 500)
#> Warning in qfmrm_ApBDqr_int(A = A, B = B, D = D, p = p, q = q, r = r, m = m, : Last term is >1.2e-04 times as large as the series,
#>   suggesting non-convergence. Consider using larger m
res
#> 
#>  Moment of ratio of quadratic forms
#> 
#> Moment = 0.02519373
#> Error bound unavailable; recommended to inspect plot() of this object

plot(res) # Far to convergence


## This problem needs much larger m (>5000)
## taking computational time + memory
## (though still manageable with a regular machine in this particular case)

## Monte Carlo sample
MCres <- rqfmr(10000, large_A, large_B, large_D, 1, 1/2, 1/2)

## Monte Carlo 95% CI of the moment
mean(MCres) + sd(MCres) / sqrt(10000) * qt(c(0.025, 0.975), 10000 - 1)
#> [1] 0.02958917 0.03117620

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.
Chikuse, Y. (1980) Invariant polynomials with matrix arguments and their applications. In: Gupta, R. P., (ed.), Multivariate Statistical Analysis. Amsterdam: North-Holland. pp. 53–68.
Chikuse, Y. (1987) Methods for constructing top order invariant polynomials. Econometric Theory, 3, 195–207. doi:10.1017/S026646660001029X.
Davis, A. W. (1980) Invariant polynomials with two matrix arguments, extending the zonal polynomials. In: Krishnaiah, P. R., (ed.), Multivariate Analysis—V. Amsterdam: North-Holland. pp. 287–299.
Hansen, T. F. and Houle, D. (2008) Measuring and comparing evolvability and constraint in multivariate characters. Journal of Evolutionary Biology, 21, 1201–1219. doi:10.1111/j.1420-9101.2008.01573.x.
Hillier, G. (2001) The density of a quadratic form in a vector uniformly distributed on the n-sphere. Econometric Theory, 17, 1–28. doi:10.1017/S026646660117101X.
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.
Mathai, A. M. and Provost, S. B. (1992) Quadratic Forms in Random Variables: Theory and Applications. New York, New York: Marcel Dekker.
Melo, D., Garcia, G., Hubbe, A., Assis, A. P. and Marroig, G. (2016) EvolQG—an R package for evolutionary quantitative genetics [version 3; referees: 2 approved, 1 approved with reservations]. F1000Research, 4, 925. doi:10.12688/f1000research.7082.3.
Muirhead, R. J. (1982) Aspects of Multivariate Statistical Theory. Hoboken, New Jersey: John Wiley & Sons. doi:10.1002/9780470316559.
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.