loglik_normal | R Documentation |
Calculates the log-likelihood of a multivariate normal distribution.
loglik_normal(u, sigma)
u |
a |
sigma |
a |
The log-likelihood is calculated for each vector in period t
as
-\frac{K}{2} \ln 2\pi - \frac{1}{2} \ln |\Sigma_t| -\frac{1}{2} u_t^\prime \Sigma_t^{-1} u_t
,
where u_t = y_t - \mu_t
.
# Load data
data("e1")
e1 <- diff(log(e1))
# Generate VAR model
data <- gen_var(e1, p = 2, deterministic = "const")
y <- t(data$data$Y)
x <- t(data$data$Z)
# LS estimate
ols <- tcrossprod(y, x) %*% solve(tcrossprod(x))
# Residuals
u <- y - ols %*% x # Residuals
# Covariance matrix
sigma <- tcrossprod(u) / ncol(u)
# Log-likelihood
loglik_normal(u = u, sigma = sigma)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.