Skip to content

Commit

Permalink
Add variance(<matrix>) method that gives diag(cov(<matrix>))
Browse files Browse the repository at this point in the history
  • Loading branch information
mitchelloharawild committed Jan 4, 2022
1 parent 96b706e commit 8a7aa72
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,7 @@ S3method(support,distribution)
S3method(variance,default)
S3method(variance,dist_default)
S3method(variance,distribution)
S3method(variance,matrix)
S3method(variance,numeric)
S3method(vec_arith,distribution)
S3method(vec_arith,hilo)
Expand Down
5 changes: 5 additions & 0 deletions R/distribution.R
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,11 @@ variance.default <- function(x, ...){
variance.numeric <- function(x, ...){
stats::var(as.vector(x), ...)
}
#' @rdname variance
#' @export
variance.matrix <- function(x, ...){
diag(stats::cov(x, ...))
}

#' Variance of a probability distribution
#'
Expand Down
3 changes: 3 additions & 0 deletions man/variance.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 8a7aa72

Please sign in to comment.