Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics
Version 0.5.2
These functions are mainly for tutorial purposes in learning matrix algebra ideas using R. In some cases, functions are provided for concepts available elsewhere in R, but where the function call or name is not obvious. In other cases, functions are provided to show or demonstrate an algorithm.
Get the released version from CRAN:
install.packages("matlib")
The development version can be installed to your R library directly from this repo via:
if (!require(devtools)) install.packages("devtools")
library(devtools)
install_github("friendly/matlib")
This installs the package from the source, so you will need to have R Tools installed on your system. R Tools for Windows takes you to the download page for Windows. R Tools for Mac OS X has the required programs for Mac OS X.
Alternatively, a Windows binary (not always current) is available at http://www.psych.yorku.ca/lab/psy6140/R/matlib.zip and can be installed via
install.packages("http://www.psych.yorku.ca/lab/psy6140/R/matlib.zip", repos=NULL)
This will usually be more current than the CRAN version, but less current than the GitHub version.
tr()
- trace of a matrixR()
- rank of a matrixlen()
- Euclidean length of a vector or columns of a matrixProj(y, X)
- projection of vector y on colunms of Xmpower(A, p)
- matrix powers for a square symmetric matrixvectors()
- plot geometric vectorsminor()
- Minor of A[i,j]cofactor()
- Cofactor of A[i,j]row_minors()
- Row minors of A[i,]row_cofactors()
- Row cofactors of A[i,]rowadd()
- Add multiples of rows to other rowsrowmult()
- Multiply rows by constantsrowswap()
- Interchange two rows of a matrixshowEqn(A, b)
- show matrices (A, b) as linear equationsplotEqn(A, b)
, plotEqn3d(A, b)
- plot matrices (A, b) as linear equationsverbose=TRUE
argument to show the intermediate steps.gaussianElimination(A, B)
- reduces (A, B) to (I, A^{-1} B)Inverse(X)
, inv()
- uses gaussianElimination
to find the inverse of Xechelon(X)
- uses gaussianElimination
to find the reduced echelon form of XGinv(X)
- uses gaussianElimination
to find the generalized inverse of Xcholesky()
- calculates a Cholesky square root of a matrixswp()
- matrix sweep operatoreig()
- eigenvalues and eigenvectorsSVD()
- singular value decompositionA small collection of vignettes is now available. Use browseVignettes("matlib")
to see them.