Introduction to gglasso

Install the package

# on CRAN
install.packages("gglasso")

# dev version on GitHub
pacman::p_load_gh('emeryyi/gglasso')

Least squares regression

library(gglasso)

# load bardet data set
data(bardet)

group1 <- rep(1:20, each = 5)

fit_ls <- gglasso(x = bardet$x, y = bardet$y, group = group1, loss = "ls")

plot(fit_ls)

coef(fit_ls)[1:5,90:100]

Cross-Validation

cvfit_ls <- cv.gglasso(x = bardet$x, y = bardet$y, group = group1, loss = "ls")

plot(cvfit_ls)
coef(cvfit_ls, s = "lambda.min")

Weight Least squares regression

We can also perform weighted least-squares regression by specifying loss='wls', and providing a $n \times n$ weight matrix in the weights argument, where $n$ is the number of observations. Note that cross-validation is NOT IMPLEMENTED for loss='wls'.

# generate weight matrix
times <- seq_along(bardet$y)
rho <- 0.5
sigma <- 1
H <- abs(outer(times, times, "-"))
V <- sigma * rho^H
p <- nrow(V)
V[cbind(1:p, 1:p)] <- V[cbind(1:p, 1:p)] * sigma

# reduce eps to speed up convergence for vignette build
fit_wls <- gglasso(x = bardet$x, y = bardet$y, group = group1, loss = "wls", 
                   weight = V, eps = 1e-4)

plot(fit_wls)

coef(fit_wls)[1:5,90:100]


Try the gglasso package in your browser

Any scripts or data that you put into this service are public.

gglasso documentation built on March 18, 2020, 9:07 a.m.