weighted_variance_multivariate: Calculate the variance of vectors (multivariate)

View source: R/RcppExports.R

weighted_variance_multivariateR Documentation

Calculate the variance of vectors (multivariate)

Description

Calculation of the weighted variance of vectors

Usage

weighted_variance_multivariate(x, x_mean, inv_precondition_matrices)

Arguments

x

an (m x n) matrix where the ith row is the ith sample

x_mean

a vector of length n (the weighted mean of x samples)

inv_precondition_matrices

list of length m of inverse preconditioning matrices

Value

the weighted variance of vectors

Examples

# set covariance matrices
Sig1 <- diag(2)
Sig2 <- matrix(c(2, 0.5, 0.5, 2), nrow = 2, ncol = 2)
Sig3 <- matrix(c(4, -3.2, -3.2, 4), nrow = 2, ncol = 2)
# sample some x values and store in the rows
x <- matrix(nrow = 3, ncol = 2)
x[1,] <- mvrnormArma(N = 1, mu = c(0, 0), Sigma = Sig1)
x[2,] <- mvrnormArma(N = 1, mu = c(0, 0), Sigma = Sig2)
x[3,] <- mvrnormArma(N = 1, mu = c(0, 0), Sigma = Sig3)
# calculate precondition matrices and their inverses
precondition_matrices <- list(Sig1, Sig2, Sig3)
inv_precondition_matrices <- lapply(precondition_matrices, solve)
inverse_sum_weights <- inverse_sum_matrices(precondition_matrices)
# calculate the weighted mean where weights are the inverse precondition matrices
x_mean <- weighted_mean_multivariate(matrix = x,
                                     weights = precondition_matrices,
                                     inverse_sum_weights = inverse_sum_weights)
weighted_variance_multivariate(x = x,
                               x_mean = x_mean,
                               inv_precondition_matrices = inv_precondition_matrices)

rchan26/hierarchicalFusion documentation built on Sept. 11, 2022, 10:30 p.m.