update_Sigma | R Documentation |
Update error covariance matrix
update_Sigma(n_Sigma_0, V_Sigma_0, N, S)
n_Sigma_0 |
[ |
V_Sigma_0 |
[ |
N |
[ |
S |
[ |
An update for Sigma
.
(Sigma_true <- matrix(c(1, 0.5, 0.2, 0.5, 1, 0.2, 0.2, 0.2, 2), ncol = 3))
beta <- matrix(c(-1, 1), ncol = 1)
N <- 100
X <- replicate(N, matrix(rnorm(6), ncol = 2), simplify = FALSE)
eps <- replicate(
N, oeli::rmvnorm(n = 1, mean = c(0, 0, 0), Sigma = Sigma_true),
simplify = FALSE
)
U <- mapply(function(X, eps) X %*% beta + eps, X, eps, SIMPLIFY = FALSE)
n_Sigma_0 <- 4
V_Sigma_0 <- diag(3)
outer_prod <- function(X, U) (U - X %*% beta) %*% t(U - X %*% beta)
S <- Reduce(`+`, mapply(
function(X, U) (U - X %*% beta) %*% t(U - X %*% beta), X, U,
SIMPLIFY = FALSE
))
Sigma_draws <- replicate(100, update_Sigma(n_Sigma_0, V_Sigma_0, N, S))
apply(Sigma_draws, 1:2, mean)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.