loglik_normal: Calculates the log-likelihood of a multivariate normal...

View source: R/RcppExports.R

loglik_normalR Documentation

Calculates the log-likelihood of a multivariate normal distribution.

Description

Calculates the log-likelihood of a multivariate normal distribution.

Usage

loglik_normal(u, sigma)

Arguments

u

a K \times T matrix of residuals.

sigma

a K \times K or KT \times K variance-covariance matrix.

Details

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.

Examples


# 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)


bvartools documentation built on May 29, 2024, 5:32 a.m.