Created
April 11, 2022 13:37
-
-
Save hannesdatta/74bcd0d833a73d13a735a9fee423dca7 to your computer and use it in GitHub Desktop.
From a variance-covariance matrix to a cholesky decomposition (and back)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # From a variance-covariance matrix to a cholesky decomposition (and back) | |
| ## Let's first define our var-covar matrix | |
| varcovar = diag(3) | |
| varcovar[1,2] <- .5 | |
| varcovar[2,1] <- .5 | |
| ## Let's get our (upper) cholesky decomposition | |
| decomp = chol(varcovar) | |
| # See - we can go back to the real var-covar by taking the crossproduct | |
| crossprod(decomp) | |
| ## From an upper cholesky to the var-covar matrix | |
| uchol = diag(3) | |
| uchol[upper.tri(uchol, diag=T)] <- c(1, .5, .866, 0, 0, 1) | |
| crossprod(uchol) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment