Choleski Decomposition in R
Last Updated :
24 Apr, 2025
Cholesky Decomposition is a popular numerical method used in linear algebra for decomposing a Hermitian positive-definite matrix into the product of a lower triangular matrix and its transpose. In this article, we'll learn how to perform Cholesky Decomposition in R programming language.
Before diving into the implementation, let's first understand some key concepts that are important to know:
- A symmetric matrix is a square matrix that is equal to its transpose.
- A Hermitian matrix is a square matrix of complex numbers, which is equal to its own conjugate transpose.Â
- A positive-definite matrix is a symmetric matrix with positive eigenvalues.
- The lower triangular matrix is a square matrix that has all the entries above the main diagonal set to zero.
Cholesky Decomposition Algorithm:
Suppose A is a Hermitian positive-definitive matrix, then it can be decomposed by Cholesky decomposition as the product of lower triangular matrix L and the conjugate transpose of this lower triangular matrix L as A = LL^*
If A is a symmetric positive-definitive matrix (or having real values), then it can be decomposed by Cholesky decomposition as the product of lower triangular matrix L and the transpose of this lower triangular matrix L as :
A = LM \\ \text{where}, \\\;\;\;\;\;\;\; L_{j,j}=\sqrt {A_{j,j}-\sum_{k=0}^{j-1}(L_{j,k})^{2}} \\\;\;\;\;\;\;\; M = L^T \text{ Â Transpose of \;L}
Let \begin{bmatrix} A_{00} & A_{01} & A_{02}\\ A_{10} & A_{11} & A_{12}\\ A_{20} & A_{21} & A_{22} \end{bmatrix}    then it can be decomposed as :
\left[\begin{array}{lll} A_{00} & A_{01} & A_{02} \\ A_{10} & A_{11} & A_{12} \\ A_{20} & A_{21} & A_{22} \end{array}\right]=\left[\begin{array}{lll} L_{00} & 0 & 0 \\ L_{10} & L_{11} & 0 \\ L_{20} & L_{21} & L_{22} \end{array}\right]\left[\begin{array}{ccc} L_{00} & L_{10} & L_{20} \\ 0 & L_{11} & L_{21} \\ 0 & 0 & L_{22} \end{array}\right]Â Â Â \\ \text{where}, \\\;\;\;\;\;\;\; L_{j,j}=\sqrt {A_{j,j}-\sum_{k=0}^{j-1}(L_{j,k})^{2}}Â
Example 1: With a symmetric positive-definitive matrix
Step 1: Load Required Libraries
The first step is to load the required libraries in R. In this case, we'll be using the Matrix library, which provides functions for linear algebraic operations.
library(Matrix)
Step 2: Define the Matrix
Next, we'll define the symmetric, positive-definite matrix that we want to decompose. In this example, we'll use the following matrix:
R
A <- matrix(c(25, 15, -5, 15, 18, 0, -5, 0, 11), nrow = 3)
A
Output:
A matrix: 3 Ã 3 of type dbl
25 15 -5
15 18 0
-5 0 11
Step 3: Perform Cholesky Decomposition
Now, we'll perform the Cholesky Decomposition on the defined matrix using the chol() function. The function returns the lower triangular matrix L such that A = t(L) %*% L.
R
Output:
A matrix: 3 Ã 3 of type dbl
5 3 -1
0 3 1
0 0 3
Step 4: Find the transpose of the lower triangular matrix L
R
Output:
A matrix: 3 Ã 3 of type dbl
5 0 0
3 3 0
-1 1 3
Step 5: Verify the Decomposition
To verify the decomposition, we can multiply the lower triangular matrix L with its transpose t(L) and compare the result with the original matrix A.
R
Output:
A matrix: 3 Ã 3 of type dbl
25 15 -5
15 18 0
-5 0 11
R
Output:
TRUE
The output of the all.equal() function is TRUE, indicating that the decomposition is correct.
Note: Currently, Hermitian positive-definite matrices (or complex matrices) are not permitted to present with chol() function.
Use Cholesky Decomposition for Solving Linear Equations
One of the primary applications of Cholesky Decomposition is solving linear equations. Given a system of linear equations Ax = b, we can solve for x using the following steps:
- Decompose the matrix A using Cholesky Decomposition to get L and t(L).
- Solve the lower triangular system Lx = b for x using forward substitution.
- Solve the upper triangular system t(L)x = y for x using backward substitution.
Conclusion
The Cholesky decomposition is efficient and has many useful properties, such as being a stable and exact factorization for positive-definite matrices, and having the triangular factor being easy to invert. The decomposition can also be computed in a distributed computing environment, making it useful for large-scale problems.
Similar Reads
Cholesky Decomposition
Cholesky Decomposition is one of the types of many decompositions in linear algebra which is a branch of mathematics that deals with linear equations and vectors. Decomposition is the term related to the factorization of matrices in linear algebra, and Cholesky is one of the ways to factorize or dec
9 min read
Decomposition In DBMS
Decomposition refers to the division of tables into multiple tables to produce consistency in the data. In this article, we will learn about the Database concept. This article is related to the concept of Decomposition in DBMS. It explains the definition of Decomposition, types of Decomposition in D
4 min read
Eigen Decomposition of a Matrix
Eigen decomposition is a method used in linear algebra to break down a square matrix into simpler components called eigenvalues and eigenvectors. This process helps us understand how a matrix behaves and how it transforms data.For Example - Eigen decomposition is particularly useful in fields like P
4 min read
Singular Value Decomposition
Prerequisites: Matrix Diagonalization, Eigenvector Computation and Low-Rank Approximations Before getting in depth into the SVD, let us first briefly understand what Matrix Diagonalization technique is and when it fails to perform efficiently. Matrix Diagonalization Matrix diagonalization is the pro
8 min read
Collapse Function In R
In the world of working with data, R is an important tool for people who study statistics, work with data, or do research. One of the important things R can do is called the "collapse" function. It helps to make big piles of data smaller and easier to work with. This makes it quicker to analyze and
5 min read
Singular Value Decomposition (SVD)
SVD (Singular Value Decomposition) is a method used in linear algebra to decompose a matrix into three simpler matrices, making it easier to analyze and manipulate.Understanding SVD with ExampleImagine you have a table of data, like a set of ratings where rows are people, and columns are products. T
8 min read
QR Decomposition in Machine learning
QR decomposition is a way of expressing a matrix as the product of two matrices: Q (an orthogonal matrix) and R (an upper triangular matrix). In this article, I will explain decomposition in Linear Algebra, particularly QR decomposition among many decompositions. What is QR Decomposition?Decompositi
9 min read
Cbind Function In R
In this article, we will discuss what is cbind function and how it works in the R Programming Language. What is Cbind Function In RIn R, the cbind() function is used to combine multiple vectors, matrices, or data frames by columns. The name "cbind" stands for "column bind," indicating that it binds
3 min read
dcast() Function in R
Reshaping data in R Programming Language is the process of transforming the structure of a dataset from one format to another. This transformation is done by the dcast function in R. dcast function in RThe dcast() function in R is a part of the reshape2 package and is used for reshaping data from 'l
5 min read
How to Fix Error in colMeans in R
R Programming Language is widely used for statistical computing and data analysis. Like any other programming language, R users often encounter errors while working with functions. One common function that users may encounter errors with is colMeans, which is used to calculate column-wise means in m
5 min read