Log-Likelihood Value of a Multivariate Normal Distribution
Log-Likelihood Value of a Multivariate Normal Distribution
Computes log-likelihood value of a multivariate normal distribution given the empirical mean vector and the empirical covariance matrix as sufficient statistics.
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 Σ should be used
eps: Threshold for determinant value of Σ
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 Σ is regularized if λ (lambda) is chosen larger than zero. Let ΔΣ denote a diagonal matrix containing the diagonal entries of Σ. Then, a regularized matrix Σ∗ is defined as Σ∗=wΣ+(1−w)ΔΣ
with w=n/(n+λ).
Returns
Log-likelihood value
Examples
############################################################################## EXAMPLE 1: Multivariate normal distribution#############################################################################library(MASS)#--- simulate dataSigma <- c(1,.55,.5,.55,1,.5,.5,.5,1)Sigma <- matrix( Sigma, nrow=3, ncol=3)mu <- c(0,1,1.2)N <-400set.seed(9875)dat <- MASS::mvrnorm( N, mu, Sigma )colnames(dat)<- paste0("Y",1:3)S <- stats::cov(dat)M <- colMeans(dat)#--- evaulate likelihoodres1 <- LAM::loglike_mvnorm( M=M, S=S, mu=mu, Sigma=Sigma, n=N, lambda=0)# compare log likelihood with somewhat regularized covariance matrixres2 <- LAM::loglike_mvnorm( M=M, S=S, mu=mu, Sigma=Sigma, n=N, lambda=1)print(res1)print(res2)## Not run:############################################################################## 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 statisticssuff_stat <- LAM::suff_stat_NA_pattern(dat1)#-- define some population mean and covariancemu <- colMeans(dat1, na.rm=TRUE)Sigma <- stats::cov(dat1, use="pairwise.complete.obs")#-- compute log-likelihoodLAM::loglike_mvnorm_NA_pattern( suff_stat=suff_stat, mu=mu, Sigma=Sigma)## End(Not run)