Learn R Programming

sirt (version 1.14-0)

loglike_mvnorm: Log-Likelihood Value of a Multivariate Normal Distribution

Description

Computes log-likelihood value of a multivariate normal distribution given the empirical mean vector and the empirical covariance matrix as sufficient statistics.

Usage

loglike_mvnorm(M, S, mu, Sigma, n, log = TRUE, lambda = 0)

Arguments

M
Empirical mean vector
S
Empirical covariance matrix
mu
Population mean vector
Sigma
Population covariance matrix
n
Sample size
log
Optional logical indicating whether the logarithm of the likelihood should be calculated.
lambda
Regularization parameter of the covariance matrix (see Details).

Value

Log-likelihood value

Details

The population covariance matrix $\bold{\Sigma}$ is regularized if $\lambda$ (lambda) is chosen larger than zero. Let $\bold{\Delta _\Sigma}$ denote a diagonal matrix containing the diagonal entries of $\bold{\Sigma}$. Then, a regularized matrix $\bold{\Sigma}^\ast$ is defined as $\bold{\Sigma}^\ast = w \bold{\Sigma} + (1-w)\bold{\Delta _\Sigma }$ with $w=n/(n+\lambda)$.

Examples

Run this code
#############################################################################
# EXAMPLE 1: Multivariate normal distribution
#############################################################################   

#--- simulate data
Sigma <- c( 1 , .55 , .5 , .55 , 1 , .5 ,.5 , .5 , 1 )
Sigma <- matrix( Sigma , nrow=3 , ncol=3 )
mu <- c(0,1,1.2)
N <- 400
set.seed(9875)
dat <- MASS::mvrnorm( N , mu , Sigma )
colnames(dat) <- paste0("Y",1:3)
S <- cov(dat)
M <- colMeans(dat)

#--- evaulate likelihood
res1 <- loglike_mvnorm( M=M , S=S , mu=mu , Sigma=Sigma , n = N , lambda = 0 )
# compare log likelihood with slightly regularized covariance matrix
res2 <- loglike_mvnorm( M=M , S=S , mu=mu , Sigma=Sigma , n = N , lambda = 1 )
res1
res2	

Run the code above in your browser using DataLab