Package: qfratio 1.1.1.9000

qfratio: Moments and Distributions of Ratios of Quadratic Forms Using Recursion

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.

Authors:Junya Watanabe [aut, cre, cph], Patrick Alken [cph], Brian Gough [cph], Pavel Holoborodko [cph], Gerard Jungman [cph], Reid Priedhorsky [cph], Free Software Foundation, Inc. [cph]

qfratio_1.1.1.9000.tar.gz
qfratio_1.1.1.9000.zip(r-4.7)qfratio_1.1.1.9000.zip(r-4.6)qfratio_1.1.1.9000.zip(r-4.5)
qfratio_1.1.1.9000.tgz(r-4.6-x86_64)qfratio_1.1.1.9000.tgz(r-4.6-arm64)qfratio_1.1.1.9000.tgz(r-4.5-x86_64)qfratio_1.1.1.9000.tgz(r-4.5-arm64)
qfratio_1.1.1.9000.tar.gz(r-4.7-arm64)qfratio_1.1.1.9000.tar.gz(r-4.7-x86_64)qfratio_1.1.1.9000.tar.gz(r-4.6-arm64)qfratio_1.1.1.9000.tar.gz(r-4.6-x86_64)
qfratio_1.1.1.9000.tgz(r-4.6-emscripten)
manual.pdf |manual.html
DESCRIPTION |NEWS
card.svg |card.png
qfratio/json (API)

# Install 'qfratio' in R:
install.packages('qfratio', repos = c('https://watanabe-j.r-universe.dev', 'https://cloud.r-project.org'))

Bug tracker:https://github.com/watanabe-j/qfratio/issues

Uses libs:
  • c++– GNU Standard C++ Library v3
  • openmp– GCC OpenMP (GOMP) support library

On CRAN:

Conda:

quadratic-formsrcpprcppeigenzonal-polynomialscppopenmp

4.90 score 2 stars 8 scripts 251 downloads 20 exports 3 dependencies

Last updated from:4c906aadb6. Checks:13 OK. Indexed: yes.

TargetResultTimeFilesSyslog
linux-devel-arm64OK328
linux-devel-x86_64OK294
source / vignettesOK402
linux-release-arm64OK307
linux-release-x86_64OK292
macos-release-arm64OK291
macos-release-x86_64OK678
macos-oldrel-arm64OK261
macos-oldrel-x86_64OK503
windows-develOK355
windows-releaseOK373
windows-oldrelOK341
wasm-releaseOK181

Exports:dqfrpqfrqfm_Ap_intqfmrmqfmrm_ApBDqr_intqfmrm_ApBDqr_npiqfmrm_ApBIqr_intqfmrm_ApBIqr_npiqfmrm_IpBDqr_genqfpm_ABDpqr_intqfpm_ABpq_intqfrmqfrm_ApBq_intqfrm_ApBq_npiqfrm_ApIq_intqfrm_ApIq_npiqqfrrqfmrrqfprqfr

Dependencies:MASSRcppRcppEigen

qfratio: Moments of Ratios of Quadratic Forms
Symbols used | Target | First examples | Mathematical details | Moment existence conditions | Expressions for moments | In these expressions, $\beta_{\cdot}$ are arbitrary scaling constants thatsatisfy $0 < \beta < 2 / \qfrlmax$, with $\qfrlmax$ beingthe largest eigenvalue of the argument matrix.In addition, $h_{k_1, \dots k_s}$ and $\tilde{h}_{k_1; k_2 \dots k_s}$ arethe coefficients of $t_1^{k_1} \dots t_s^{k_s}$ in the following power seriesexpansions:\begin{multline}\det{ \mathbf{I}_n - t_1 \mathbf{A}_1 - \dots - t_s \mathbf{A}_s }^{-\frac{1}{2}}\\cdot\exp \left( \frac{(1 - t_1 - \dots - t_s) \boldsymbol{\mu}^T\left( \mathbf{I}_n - t_1 \mathbf{A}_1 - \dots - t_s \mathbf{A}_s \right)^{-1}\boldsymbol{\mu}- \boldsymbol{\mu}^T \boldsymbol{\mu}}{2} \right)\ | \sum_{k_1 = 0}^{\infty} \dots \sum_{k_s = 0}^{\infty} \qfrhijk[k_1, \dots, k_s]{ \mathbf{A}_1 }{\dots}{ \mathbf{A}_s } t_1^{k_1} \dots t_s^{k_s}, \label{gfun_hij} \\end{multline}\begin{multline}\det{ \mathbf{I}_n - t_1 \mathbf{A}_1 - \dots - t_s \mathbf{A}_s }^{-\frac{1}{2}}\ \cdot\exp \left( \frac{(1 - t_2 - \dots - t_s) \boldsymbol{\mu}^T\left( \mathbf{I}_n - t_1 \mathbf{A}_1 - \dots - t_s \mathbf{A}_s \right)^{-1}\boldsymbol{\mu}- \boldsymbol{\mu}^T \boldsymbol{\mu}}{2} \right)\ | A common special case is when $\boldsymbol | Special cases | A notable special case for moments of simple ratios is when $p$ is a positiveinteger and $\mathbf{B} = \mathbf{I}_n$.In this case, (2) simplifies into [@HillierEtAl2014, theorem 4]\begin{equation}\qfrE \left( \frac{(\mathbf{x}^T \mathbf{A} \mathbf{x})^p}{(\mathbf{x}^T \mathbf{x})^q} \right) | 2^{p - q} p!\sum_{k=0}^{p}\frac{ \qfrGmf{ \frac{n}{2} + p - q + k } }{ 2^k k! \qfrGmf{ \frac{n}{2} + p + k } }{}1 F_1 \left( q ; \frac{n}{2} + p + k ; - \frac{\boldsymbol{\mu}^T \boldsymbol{\mu}}{2} \right) a{p, k} \left( \mathbf{A}, \boldsymbol{\mu} \right),\tag{5}\end{equation}where ${}1 F_1 \left( \cdot ; \cdot ; \cdot \right)$ is the confluenthypergeometric function, and $a{p, k}$ are the coefficients of $t^p$ in\begin{align}&\det{ \mathbf{I}_n - t \mathbf{A} }^{-\frac{1}{2}}\left(\boldsymbol{\mu}^T \left( \mathbf{I}_n - t \mathbf{A} \right)^{-1} \boldsymbol{\mu}- \boldsymbol{\mu}^T \boldsymbol{\mu}\right) ^ k | Numerical evaluation | Truncation error | A great advantage in the above expressions is that an error bound is availablefor a partial (truncated) sum for the simple ratio, provided that $p$ is apositive integer and $\mathbf{B}$ is positive definite.By denoting the expression (2) as $M \left( \mathbf{A}, \mathbf{B}, p, q \right)$and the partial sum of the same up to $j = m$ as$\hat{M}m \left( \mathbf{A}, \mathbf{B}, p, q \right)$, the error bound is[@HillierEtAl2014, theorem 7]\begin{multline}\lvert M \left( \mathbf{A}, \mathbf{B}, p, q \right) - \hat{M}m \left( \mathbf{A}, \mathbf{B}, p, q \right) \rvert \\leq\frac{ 2^{p - q} \beta{\mathbf{B}}^{q} p! \qfrGmf{ \frac{n}{2} + p - q } \qfrrf[m+1]{q} }{ \qfrGmf{ \frac{n}{2} + p + m + 1 } }\left[\frac{\exp \left( \frac{ \bar{\boldsymbol{\mu}}^T \bar{\boldsymbol{\mu}} - \boldsymbol{\mu}^T \boldsymbol{\mu} }{2} \right)\qfrdtk[p]{ \bar{A} }{ \bar{\boldsymbol{\mu}} }}{\det{\beta{\mathbf{B}} \mathbf{B}}^{\frac{1}{2}}}- \sum_{j=0}^{m}\qfrhhij[p;j]{ \mathbf{A}^+ }{ \mathbf{I}n - \beta{\mathbf{B}} \mathbf{B} }\right],\end{multline}where $\mathbf{A}^+$ is a symmetric matrix constructed from the eigenvectors and"positivized" eigenvalues of $\mathbf{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 $\tilde{d}$ and $\hat{h}$ are coefficients in the following generating functions:\begin{equation}\det{ \mathbf{I}_n - t \mathbf{A} }^{-\frac{1}{2}}\exp \left( \frac{\boldsymbol{\mu}^T \left( \mathbf{I}_n - t \mathbf{A} \right)^{-1} \boldsymbol{\mu}- \boldsymbol{\mu}^T \boldsymbol{\mu}}{2} \right) | \sum_{k = 0}^{\infty} \qfrdtk[k]{ \mathbf{A} }{ \boldsymbol{\mu} } t^{k},\end{equation}\begin{multline}\det{ \mathbf{I}_n - t_1 \mathbf{A}_1 - \dots - t_s \mathbf{A}_s }^{-\frac{1}{2}}\\quad \cdot\exp \left( \frac{(1 + t_2 + \dots + t_s) \boldsymbol{\mu}^T\left( \mathbf{I}_n - t_1 \mathbf{A}_1 - \dots - t_s \mathbf{A}_s \right)^{-1}\boldsymbol{\mu}- \boldsymbol{\mu}^T \boldsymbol{\mu}}{2} \right) \ | Recursions | Functions | qfrm(): quadratic form ratio moment | Usage | Inside the function | qfmrm(): quadratic form multiple ratio moment | qfm_Ap_int(), qfpm_ABpq_int(), qfpm_ABDpqr_int(): quadratic form (product) moment | rqfr(), rqfmr(), rqfp(): random number generation | d1_i(), d2_*j_*(), d3_*jk_*(), etc.: recursion algorithms | Using the functionality | Recommended workflow | Checking for numerical convergence | Computational cost | References

Last update: 2025-12-04
Started: 2023-02-16

Probability Distribution Functions in Package qfratio
Symbols used | Theory | Preliminaries | Series expression | Distribution function | Density function | Numerical inversion | Saddlepoint approximation | Let $M_{X_q}(s)$ be the moment generating function of $X_q$,\begin{equation}M_{X_q}(s) | A first-order saddlepoint approximation formula for the distribution function$F_Q$ is [@ButlerPaolella2007; @ButlerPaolella2008]:\begin{equation}\widehat{\Pr{}}_1 (Q < q) | A more accurate second-order approximation is [@ButlerPaolella2007]\begin{equation}\widehat{\Pr{}}_2 (Q < q) | A first-order saddlepoint approximation for the density function $f_Q$ is[@ButlerPaolella2007; @ButlerPaolella2008]\begin{equation}\hat{f_1}(q) | A second-order approximation is [@ButlerPaolella2007]\begin{equation}\hat{f_2}(q) | \hat{f_1}(q) (1 + O) ,\end{equation}where\begin{equation}O | Implementation details | Exported functions | Choosing a method | Use with ks.test() | Series expressions | Specifying integration error | autoscale_args | trim_values | Options | Error bound | pqfr() and dqfr() | qqfr() | Distribution of powers | When $\mathbf{A}$ is nonnegative definite or $p$ is an odd integer | When $\mathbf{A}$ is indefinite and $p$ is an even integer | When $\mathbf{A}$ is indefinite and $p$ is non-integer | Graphical examples | References

Last update: 2023-10-20
Started: 2023-07-12

Readme and manuals

Help Manual

Help pageTopics
Recursion for a_{p,k}a1_pk
Coefficients in polynomial expansion of generating function-single matrixd1_i dtil1_i dtil1_i_m dtil1_i_v
Coefficients in polynomial expansion of generating function-for ratios with two matricesd2_1j d2_1j_m d2_1j_v d2_ij d2_ij_m d2_ij_v d2_pj d2_pj_m d2_pj_v h2_ij h2_ij_m h2_ij_v hhat2_1j hhat2_1j_m hhat2_1j_v hhat2_pj hhat2_pj_m hhat2_pj_v htil2_1j htil2_1j_m htil2_1j_v htil2_pj htil2_pj_m htil2_pj_v
Coefficients in polynomial expansion of generating function-for ratios with three matricesd3_ijk d3_ijk_m d3_ijk_v d3_pjk d3_pjk_m d3_pjk_v h3_ijk h3_ijk_m h3_ijk_v hhat3_pjk hhat3_pjk_m hhat3_pjk_v htil3_pjk htil3_pjk_m htil3_pjk_v
Probability distribution of ratio of quadratic formsdqfr dqfr_A1I1 dqfr_broda dqfr_butler pqfr pqfr_A1B1 pqfr_butler pqfr_davies pqfr_imhof qqfr
Coefficients in polynomial expansion of generating function-for productsdtil2_1q_m dtil2_1q_v dtil2_pq dtil2_pq_m dtil2_pq_v dtil3_pqr dtil3_pqr_m dtil3_pqr_v
Calculate hypergeometric serieshgs hgs_1d hgs_2d hgs_3d
Internal C++ wrappers for GSLgsl_wrap hyperg_1F1_vec_b hyperg_2F1_mat_a_vec_c
Is this matrix diagonal?is_diagonal
Are these vectors equal?iseq
Matrix square root and generalized inverseKiK
Construct qfrm objectnew_qfpm new_qfrm
Internal C++ functionsABDpqr_int_E ABpq_int_E ApBDqr_int_Ec ApBDqr_int_Ed ApBDqr_int_El ApBDqr_npi_Ec ApBDqr_npi_Ed ApBDqr_npi_El ApBIqr_int_cEd ApBIqr_int_nEc ApBIqr_int_nEd ApBIqr_int_nEl ApBIqr_npi_Ec ApBIqr_npi_Ed ApBIqr_npi_El ApBq_int_E ApBq_npi_Ec ApBq_npi_Ed ApBq_npi_El ApIq_int_cE ApIq_int_nE ApIq_npi_cE ApIq_npi_nEc ApIq_npi_nEd ApIq_npi_nEl Ap_int_E d_A1I1_Ed d_broda_Ed d_butler_Ed IpBDqr_gen_Ec IpBDqr_gen_Ed IpBDqr_gen_El p_A1B1_Ec p_A1B1_Ed p_A1B1_El p_butler_Ed p_imhof_Ed qfrm_cpp rqfpE
Methods for qfrm and qfpm objectsmethods.qfrm plot.qfrm print.qfpm print.qfrm
Moment of multiple ratio of quadratic forms in normal variablesqfmrm qfmrm_ApBDqr_int qfmrm_ApBDqr_npi qfmrm_ApBIqr_int qfmrm_ApBIqr_npi qfmrm_IpBDqr_gen
Moment of (product of) quadratic forms in normal variablesqfm_Ap_int qfpm qfpm_ABDpqr_int qfpm_ABpq_int
Moment of ratio of quadratic forms in normal variablesqfrm qfrm_ApBq_int qfrm_ApBq_npi qfrm_ApIq_int qfrm_ApIq_npi
Get range of ratio of quadratic formsgen_eig range_qfr
Monte Carlo sampling of ratio/product of quadratic formsrqfmr rqfp rqfr
Make covariance matrix from eigenstructureS_fromUL
Summing up counter-diagonal elementssum_counterdiag sum_counterdiag3D
Matrix trace functiontr