Yet another R package for matrices. It contains a small set of functions designed to speed up the computation of certain matrix operations that are commonly used in statistics and econometrics. It provides efficient implementations for the computation of several structured matrices, matrix decompositions and statistical procedures, many of which have minimal memory overhead. Suggested Extension by fastverse.
Version 0.6-2 of fastmatrix can be found at the CRAN package repository:
- fastmatrix_0.6-2.tar.gz - Package sources
- fastmatrix_0.6.zip - Windows binaries (R-release)
- fastmatrix_0.6.tgz - MacOS binaries (R-release, arm64)
- fastmatrix_0.6.tgz - MacOS binaries (R-release, x86_64)
Next, the main functionalities of fastmatrix (latest release, version 0.6-2, Oct 14, 2025):
- Structured matrices:
- Constructors for AR(1) and compound symmetry correlation matrices.
- Constructors for Frank, Hankel and Helmert matrices.
- Operations envolving the commutation matrix, with minimum requirements of storage.
- Operations envolving the duplication matrix, with minimum requirements of storage.
- Operations envolving the symmetrizer matrix, with minimum requirements of storage.
- Matrix operations and decompositions:
- Array multiplication (see for instance, Appendix A of Wei, 1998).
- C version of the Kronecker product which is slightly faster than the built in R base.
- Column-equilibration for rectangular and symmetric matrices.
- Evaluation of a real general matrix polynomial using Horner's scheme.
- Evaluation of a matrix function where its argument is an upper triangular matrix by applying a Parlett recurrence.
- Fast computation of Hadamard (elementwise) product using unrolled loops.
- Gauss-Seidel, Jacobi and conjugate gradients (CG) iterative methods for solving linear systems.
- Inner products and norms for matrices.
- Computation of the scaled condition number of a rectangular matrix.
- LDL decomposition for symmetric real matrices.
- Computation of the modified Cholesky factorization of a real symmetric but not necessarily positive definite matrix.
- Lp norms for vectors.
- LU factorization for square matrices.
- Matrix square root using the Newton iteration proposed by Denman and Beavers (1976) and the Schur decomposition.
- Modified Cholesky factorization for symmetric but not necessarily positive definite matrices.
- Power method to compute the dominant eigenvalue and its associated eigenvector.
- Rank-1 update to Cholesky factorization.
- Routine to compute a Krylov matrix.
- Schur decomposition for a square matrix.
- Sherman-Morrison formula.
- Sweep operator for symmetric matrices.
- vec and vech operators to handle rectangular and square matrices.
- Statistical procedures:
- Covariance matrix estimation using the Mean Square Successive (MSSD) method.
- Estimation of the weighted mean and covariance matrix using an online algorithm (Clarke, 1971).
- Computation of central moments up to fourth order using an online algorithm (Spicer, 1972).
- Geometric mean using a Fused-Multiply-and-Add (FMA) compensated scheme for accurate computation of floating-point product.
- Mahalanobis distances, checking if the covariance is a positive definite matrix.
- Omnibus test for univariate normality (Jarque-Bera, Doornik-Hansen, Adjusted Lagrange multiplier test (Urzua, 1996) and a robust version proposed by Gel and Gastwirt, 2008).
- Ordinary least-squares (OLS) using several methods: conjugate gradients, Cholesky, QR decomposition, singular value decomposition, and the Sweep operator. This provides an alternative to extend the procedures available in R built-in function 'lm'.
- Ridge estimation for linear regression.
- Routines to compute measures of multivariate skewness and kurtosis proposed by Mardia (1970).
- Routine for the computation of the mediancenter (or geometric median) for multivariate data.
- Test for variance homogeneity of correlated variables (Harris, 1985).
- Whitening transformation.
- Wilson-Hilferty transformation for Gamma random variables.
- Random number generators (RNGs):
- RNG from the multivariate normal (Gaussian) distribution.
- RNG of uniformly distributed deviates within a unitary ball.
- RNG of uniformly distributed deviats located on a spherical surface.
- Miscellaneous:
- Bezier curve based on n+1 control points.
- Floyd-Warshall algorithm to find all shortest paths (if exist) in a directed graph.
- C interfaces:
- The package provides interfaces for code written in C, enabling other R packages (or user-written C code) to access the C routines in the fastmatrix package.
Our plan in the near future is the implementation of functions to handle:
- Some special matrices and operations arising in numerical analysis.
To install fastmatrix (version 0.6-2) from CRAN, start R and enter:
install.packages("fastmatrix")
Or install it from its GitHub repository. First install the devtools package.
install.packages("devtools")
Then install fastmatrix using the install_github
function in devtools
library(devtools)
install_github("faosorios/fastmatrix", subdir = "pkg")
Alternatively, you can download the source as a tarball (.tar.gz file). Unpack this file (thereby creating a directory named, fastmatrix) and install the package source by executing (at the console prompt)
R CMD INSTALL fastmatrix
Next, you can load the package by using the command: library(fastmatrix)
Please report any bugs/suggestions/improvements to Felipe Osorio. If you find these routines useful or not then please let me know. Also, acknowledgement of the use of the routines is appreciated.
citation("fastmatrix")
To cite fastmatrix in publications use:
Osorio, F., Ogueda, A. (2025). Fast computation of some matrices
useful in statistics. R package version 0.6-2. URL:
https://faosorios.github.io/fastmatrix/
A BibTeX entry for LaTeX users is
@Manual{,
title = {Fast computation of some matrices useful in statistics},
author = {F. Osorio and A. Ogueda},
year = {2025},
note = {R package version 0.6-2},
url = {https://faosorios.github.io/fastmatrix/},
}
- Ogueda, A., Osorio, F. (2025). Influence diagnostics for ridge regression using the Kullback-Leibler divergence. Statistical Papers 66, 85.
- Guglielmini, S., Claeskens, G. (2025). Asymptotic post-selection inference for regularized graphical models. Statistics and Computing 35, 36.
- van Buuren, S. (2023). Evaluation and prediction of individual growth trajectories. Annals of Human Biology 50, 247–257.
Felipe Osorio is an applied statistician and creator of several R packages
- Webpage: fosorios.github.io
Alonso Ogueda is a doctorate student of mathematics from the Mathematical Sciences Department, George Mason University, USA.
- Github: github.com/aoguedao