README.md

CRAN_Status_Badge Downloads Dependencies Travis-CI Build Status

matlib

Matrix Functions for Teaching and Learning Linear Algebra and Multivariate Statistics, http://friendly.github.io/matlib/

Version 0.9.7

These functions are mainly 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,

Installation

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(remotes)) install.packages("remotes")
 remotes::install_github("friendly/matlib", build_vignettes = TRUE)

This installs the package from the source and creates the package vignettes, 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.

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.

Topics

The functions in this package are grouped under the following topics

  1. Convenience functions:

  2. tr() - trace of a matrix

  3. R() - rank of a matrix
  4. J() - constant vector, matrix or array
  5. len() - Euclidean length of a vector or columns of a matrix
  6. vec() - vectorize a matrix
  7. Proj(y, X) - projection of vector y on columns of matrix X
  8. mpower(A, p) - matrix powers for a square symmetric matrix
  9. xprod(...) - vector cross-product

  10. Determinants: functions for calculating determinants by cofactor expansion

  11. minor() - Minor of A[i,j]

  12. cofactor() - Cofactor of A[i,j]
  13. rowMinors() - Row minors of A[i,]
  14. rowCofactors() - Row cofactors of A[i,]
  15. Det() - Determinants by elimination or eigenvalues

  16. Elementary row operations: functions for solving linear equations "manually" by the steps used in row echelon form and Gaussian elimination

  17. rowadd() - Add multiples of rows to other rows

  18. rowmult() - Multiply rows by constants
  19. rowswap() - Interchange two rows of a matrix

  20. Linear equations: functions to illustrate linear equations of the form $\mathbf{A x = b}$

  21. showEqn(A, b) - show matrices (A, b) as linear equations

  22. plotEqn(A, b), plotEqn3d(A, b) - plot matrices (A, b) as linear equations

  23. Gaussian elimination: functions for illustrating Gaussian elimination for solving systems of linear equations of the form $\mathbf{A x = b}$. These functions provide a verbose=TRUE argument to show the intermediate steps and a fractions=TRUE argument to show results using MASS::fractions().

  24. gaussianElimination(A, B) - reduces $(A, B)$ to $(I, A^{-1} B)$

  25. Inverse(X), inv() - uses gaussianElimination to find the inverse of X, $\mathbf{X}^{-1}$
  26. echelon(X) - uses gaussianElimination to find the reduced echelon form of X
  27. Ginv(X) - uses gaussianElimination to find the generalized inverse of X
  28. LU(X) - LU decomposition of a matrix X
  29. cholesky(X) - calculates a Cholesky square root of a matrix
  30. swp() - matrix sweep operator

  31. Eigenvalues: functions to illustrate the algorithms for calculating eigenvalues and eigenvectors and related matrix decompositions and generalizations.

  32. Eigen() - eigenvalues and eigenvectors

  33. SVD() - singular value decomposition, \$mathbf{X = U D V}$
  34. powerMethod() - find the dominant eigenvector using the power method
  35. showEig() - draw eigenvectors on a 2D scatterplot with a dataEllipse
  36. MoorePenrose() - illustrates how the Moore-Penrose inverse can be calculated using SVD()

  37. Vector diagrams: functions for drawing vector diagrams in 2D and 3D

  38. arrows3d() - draw nice 3D arrows

  39. corner(), arc() - draw a corner or arc showing the angle between two vectors in 2D/3D
  40. pointOnLine() - position of a point along a line
  41. vectors(), vectors3d() - plot geometric vector diagrams in 2D/3D
  42. regvec3d() - calculate and plot vectors representing a bivariate regression model, lm(y ~ x1 + x2) in mean-deviation form.

Vignettes and presentations

A small collection of vignettes is now available. Use browseVignettes("matlib") to explore them.

| Vignette | Title | |-------------------------------------------------------------------------------------|-----------------------------------------------| | det-ex1 | Properties of determinants | | det-ex2 | Evaluation of determinants | | inv-ex1 | Inverse of a matrix | | inv-ex2 | Matrix inversion by elementary row operations | | ginv | Generalized inverse | | eigen-ex1 | Eigenvalues and Eigenvectors: Properties | | eigen-ex2 | Eigenvalues: Spectral Decomposition | | linear-equations | Solving Linear Equations | | gramreg | Gram-Schmidt Orthogonalization and Regression | | data-beta | Vector Spaces of Least Squares and Linear Equations |

See also:



friendly/matlib documentation built on March 3, 2024, 12:18 p.m.