Learn R Programming

cglasso (version 1.1.2)

coef: Extract Model Coefficients

Description

coef’ extracts model coefficients from a fitted model.

Usage

# S3 method for glasso
coef(object, …, nrho = 1L, type = c("theta", "sigma"),
     print.info = FALSE, digits = 3L)
# S3 method for mglasso
coef(object, …, nrho = 1L, type = c("theta", "sigma", "mu"),
     print.info = FALSE, digits = 3L)

Arguments

object

an object with class ‘glasso’, ‘ggm’, ‘mglasso’ or ‘mggm’ ‘cglasso’ or ‘cggm’.

nrho

integer used to specify the model from which to extract the coefficients. Default is nrho = 1.

type

a string specifying the returned parameters. If ‘object’ has class ‘glasso’ or ‘ggm’, the user can choice between the precision matrix (‘type = "theta"’) and the covariance matrix (‘type = "sigma"’). In the other fitted models,the user can also extract the estimates of the expected values (‘type = "mu"’). Default is "theta"

print.info

flag specifying if information about the model is printed out. Default is FALSE.

digits

the minimum number of significant digits to be used. Default is 3L.

additional argument added for backward compatibility with the generic function coef.

Value

Coefficients extracted from ‘object’ are returned.

Details

By default, the method functions ‘coef.glasso’ and ‘coef.mglasso’ return the parameters specified by the argument ‘type’.

If ‘print.info = TRUE’ then the estimated parameters are silently returned and information about the chosen model is printed out, i.e. the value of the tuning parameter, the value of the pseudo R-squared, the number of connected components and the number of vertices per connected component. Furthermore, to improve the readability of the results the estimates are printed out taken into account the connected components (see the examples below).

See Also

glasso, mglasso, cglasso and mle.

Examples

Run this code
# NOT RUN {
library("cglasso")

#################
# cglasso model #
#################
set.seed(123)
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)

coef(out, nrho = 3L, type = "theta", print.info = TRUE)
Tht_hat <- coef(out, nrho = 3L, type = "theta")
Tht_hat

coef(out, nrho = 3L, type = "sigma", print.info  = TRUE)
Sgm_hat <- coef(out, nrho = 3L, type = "sigma")
Sgm_hat

coef(out, nrho = 3L, type = "mu", print.info = TRUE)
mu_hat <- coef(out, nrho = 3L, type = "mu")
mu_hat

#################
# mglasso model #
#################
R <- event(X)
X <- as.matrix(X)
X[R == 1L] <- NA
out <- mglasso(X = X)

coef(out, nrho = 3L, type = "theta", print.info = TRUE)
Tht_hat <- coef(out, nrho = 3L, type = "theta")
Tht_hat

coef(out, nrho = 3L, type = "sigma", print.info  = TRUE)
Sgm_hat <- coef(out, nrho = 3L, type = "sigma")
Sgm_hat

coef(out, nrho = 3L, type = "mu", print.info = TRUE)
mu_hat <- coef(out, nrho = 3L, type = "mu")
mu_hat

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

coef(out, nrho = 3L, type = "theta", print.info = TRUE)
Tht_hat <- coef(out, nrho = 3L, type = "theta")
Tht_hat

coef(out, nrho = 3L, type = "sigma", print.info  = TRUE)
Sgm_hat <- coef(out, nrho = 3L, type = "sigma")
Sgm_hat
# }

Run the code above in your browser using DataLab