Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

loglik_normal

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π - \frac{1}{2} \ln |Σ_t| -\frac{1}{2} u_t^\prime Σ_t^{-1} u_t

, where u_t = y_t - μ_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

Bayesian Inference of Vector Autoregressive Models

v0.2.0
GPL (>= 2)
Authors
Franz X. Mohr [aut, cre]
Initial release
2021-04-25

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.