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

loglike_mvnorm(M, S, mu, Sigma, n, log=TRUE, lambda=0, ginv=FALSE, eps=1e-30,
       use_rcpp=FALSE )

loglike_mvnorm_NA_pattern( suff_stat, mu, Sigma, log=TRUE, lambda=0, ginv=FALSE,
       eps=1e-30, use_rcpp=FALSE )

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

ginv

Logical indicating whether generalized inverse matrix of \(\bold{\Sigma}\) should be used

eps

Threshold for determinant value of \(\bold{\Sigma}\)

use_rcpp

Logical indicating whether Rcpp function should be used

suff_stat

List with sufficient statistics as generated by suff_stat_NA_pattern.

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)\).

Value

Log-likelihood value

Examples

#############################################################################
# EXAMPLE 1: Multivariate normal distribution
#############################################################################

library(MASS)

#--- 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 <- stats::cov(dat)
M <- colMeans(dat)

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

if (FALSE) {

#############################################################################
# EXAMPLE 2: Multivariate normal distribution with missing data patterns
#############################################################################

library(STARTS)
data(data.starts01b, package="STARTS")
dat <- data.starts01b
dat1 <- dat[, paste0("E",1:3)]

#-- compute sufficient statistics
suff_stat <- LAM::suff_stat_NA_pattern(dat1)
#-- define some population mean and covariance
mu <- colMeans(dat1, na.rm=TRUE)
Sigma <- stats::cov(dat1, use="pairwise.complete.obs")

#-- compute log-likelihood
LAM::loglike_mvnorm_NA_pattern( suff_stat=suff_stat, mu=mu, Sigma=Sigma)
}