weighted_variance_multivariate | R Documentation |
Calculation of the weighted variance of vectors
weighted_variance_multivariate(x, x_mean, inv_precondition_matrices)
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 |
the weighted variance of vectors
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.