Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics, http://friendly.github.io/matlib/
Version 1.0.1
These functions were originally designed for tutorial purposes in teaching & learning matrix algebra ideas using R. In some cases, functions are provided for concepts or computations available elsewhere in R, but where the name is not obvious, e.g., R()
for the rank of a matrix, or tr()
for matrix trace.
In other cases, we provide cover functions to show or demonstrate an algorithm in more detail, sometimes providing a verbose =
argument to print the details of computations, e.g., Det()
for a matrix determinant, Inverse()
for a matrix inverse, using gaussianElimination()
to show the steps.
In addition, a collection of functions are provided for drawing vector diagrams in 2D and 3D, illustrating various concepts of linear algebra more concretely than has been available before. For example,
showEqn(A, b)
shows the matrix equations $\mathbf{A x} = \mathbf{b}$ in text or LaTeX form, while plotEqn(A, b)
and plotEqn3d(A, b)
plots those equations in 2D or 3D space.
matrix2latex()
, latexMatrix()
, Eqn()
and friends facilitate writing matrix equations in LaTeX.
vectors()
, vectors3d()
plot geometric vector diagrams in 2D or 3D, with other functions to draw angles and arcs.
regvec3d()
calculates and plot vectors representing a bivariate regression model, lm(y ~ x1 + x2)
Get the released version from CRAN:
install.packages("matlib")
Or the development version from my R-universe:
install.packages('matlib', repos = c('https://friendly.r-universe.dev', 'https://cloud.r-project.org'))
The development version can also be installed to your R library directly from this repo via:
if (!require(remotes)) install.packages("remotes")
remotes::install_github("friendly/matlib", build_vignettes = TRUE)
The functions that draw 3D graphs use the rgl package. On macOS, rgl requires that XQuartz be installed. After installing XQuartz, it's necessary either to log out of and back into your macOS account or to reboot your Mac.
The functions in this package are grouped under the following topics
tr()
- trace of a matrixR()
- rank of a matrixJ()
- constant vector, matrix or arraylen()
- Euclidean length of a vector or columns of a matrixvec()
- vectorize a matrixProj(y, X)
- projection of vector y on columns of matrix Xmpower(A, p)
- matrix powers for a square symmetric matrixxprod(...)
- vector cross-productminor()
- Minor of A[i,j]cofactor()
- Cofactor of A[i,j]rowMinors()
- Row minors of A[i,]rowCofactors()
- Row cofactors of A[i,]Det()
- Determinants by elimination or eigenvaluesrowadd()
- 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 equations, as text or in LaTeXplotEqn(A, b)
, plotEqn3d(A, b)
- plot matrices (A, b) as linear equationsverbose=TRUE
argument to show the intermediate steps and a fractions=TRUE
argument to show results using MASS::fractions()
.gaussianElimination(A, B)
- reduces $(A, B)$ to $(I, A^{-1} B)$Inverse(X)
, inv()
- uses gaussianElimination
to find the inverse of X, $\mathbf{X}^{-1}$echelon(X)
- uses gaussianElimination
to find the reduced echelon form of XGinv(X)
- uses gaussianElimination
to find the generalized inverse of XLU(X)
- LU decomposition of a matrix Xcholesky(X)
- calculates a Cholesky square root of a matrixswp()
- matrix sweep operatorEigen()
- eigenvalues and eigenvectorsSVD()
- singular value decomposition, $mathbf{X = U D V}$powerMethod()
- find the dominant eigenvector using the power methodshowEig()
- draw eigenvectors on a 2D scatterplot with a dataEllipseMoorePenrose()
- illustrates how the Moore-Penrose inverse can be calculated using SVD()
arrows3d()
- draw nice 3D arrowscorner()
, arc()
- draw a corner or arc showing the angle between two vectors in 2D/3DpointOnLine()
- position of a point along a linevectors()
, vectors3d()
- plot geometric vector diagrams in 2D/3Dregvec3d()
- calculate and plot vectors representing a bivariate regression model, lm(y ~ x1 + x2)
in mean-deviation form.matrix2latex()
: Convert matrix to LaTeX equationlatexMatrix()
: Create and manipulate LaTeX representations of matriceslatexMatrixOperations
: Matrix operators (e.g., %*%
, %O%
) and functions (matmult()
, kronecker()
) for matrix arithmetic, but rendered in LaTeXEqn()
: A wrapper for equations composed from latexMatrix()
expressions and LaTeX text, with ability to preview the results in a Viewer pane.A small collection of vignettes is now available. Use browseVignettes("matlib")
to explore them.
See also:
Ivan Savov, Linear algebra explained in four pages
Michael Rodriguez & Andrew Zieffler Matrix Algebra for Educational Scientists. An online book describing matrix operations and their statistical applications, with R code for many examples.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4