View source: R/loglike_mvnorm.R
loglike_mvnorm | R Documentation |
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 )
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{Σ} should be used |
eps |
Threshold for determinant value of \bold{Σ} |
use_rcpp |
Logical indicating whether Rcpp function should be used |
suff_stat |
List with sufficient statistics as generated by
|
The population covariance matrix \bold{Σ} is regularized if
λ (lambda
) is chosen larger than zero.
Let \bold{Δ _Σ} denote a diagonal matrix containing
the diagonal entries of \bold{Σ}. Then, a regularized matrix
\bold{Σ}^\ast is defined as
\bold{Σ}^\ast=w \bold{Σ} + (1-w)\bold{Δ _Σ }
with w=n/(n+λ).
Log-likelihood value
############################################################################# # 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.