loglike_mvnorm function

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.

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 Σ=wΣ+(1w)ΔΣ\bold{\Sigma}^\ast=w \bold{\Sigma} + (1-w)\bold{\Delta _\Sigma }

with w=n/(n+λ)w=n/(n+\lambda).

Returns

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) ## 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 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) ## End(Not run)
  • Maintainer: Alexander Robitzsch
  • License: GPL (>= 2)
  • Last published: 2024-07-15