Learn R Programming

cglasso (version 1.1.2)

loglik: Extract Log-Likelihood or Q-Function

Description

loglik’ function extracts the values of the log-liklihood function from an object with class ‘glasso’ or ‘ggm’, otherwise the values of the Q-function are returned.

Usage

loglik(object)

Arguments

object

a fitted model object.

Value

loglik’ returns an object with S3 class “loglik”, i.e. a list containing the following components:

value

the values of the log-likelihood or Q-function.

df

the number of the estimated non-zero parameters, i.e. the number of non-zero partial correlations plus \(2p\).

n

the sample size.

p

the number of variables.

rho

the values of the tuning parameter used to fit the model.

model

the name of the fitted model.

fun

the name of the used function, i.e. the log-likelihood or the Q-function.

Details

If ‘object’ has class ‘glasso’ or ‘ggm’, the function ‘loglik()’ returns the value of the log-likelihood function: $$\frac{n}{2}\left\{\log det\Theta - tr(S\Theta) - p\log(2\pi)\right\},$$ where \(\Theta\) is estimated using the function glasso or mle.glasso.

For the other models, ‘loglik()’ returns the value of the Q-function, i.e. the function maximaxed in the M-step of the EM-like algorithm. The Q-function is defined as follows: $$\frac{n}{2}\left\{\log det\Theta - tr(S'\Theta) - p\log(2\pi)\right\},$$ where \(S'\) is computed in the E-step.

The method function ‘print.loglik’ is used the improve the readability of the results.

See Also

cglasso, mglasso, glasso, mle and the method functions, plot, aic, bic and ebic.

Examples

Run this code
# NOT RUN {
library("cglasso")
set.seed(123)

#################
# cglasso model #
#################
p <- 5L
n <- 100L
mu <- rep(0L, p)
Tht <- diag(p)
diag(Tht[-1L, -p]) <- diag(Tht[-p, -1L]) <- 0.3
Sgm <- solve(Tht)
X <- rdatacggm(n = n, mu = mu, Sigma = Sgm, probr = 0.05)
out <- cglasso(X = X)
out_loglik <- loglik(out)
out_loglik

##############
# cggm model #
##############
out_mle <- mle(out)
out_loglik <- loglik(out_mle)
out_loglik

#################
# mglasso model #
#################
library(MASS)
X <- mvrnorm(n = n, mu = mu, Sigma = Sgm)
id.na <- sample.int(n = n * p, size = n * p * 0.05)
X[id.na] <- NA
out <- mglasso(X = X)
out_loglik <- loglik(out)
out_loglik

##############
# mggm model #
##############
out_mle <- mle(out)
out_loglik <- loglik(out_mle)
out_loglik

################
# glasso model #
#################
X <- mvrnorm(n = n, mu = mu, Sigma = Sgm)
out <- glasso(X)
out_loglik <- loglik(out)
out_loglik

#############
# ggm model #
#############
out_mle <- mle(out)
out_loglik <- loglik(out_mle)
out_loglik
# }

Run the code above in your browser using DataLab