Package {lglasso}


Type: Package
Title: Graphical Lasso for Longitudinal Data
Version: 2.0.0
Description: Estimate treatment-specific precision matrices (networks) from longitudinal high-dimensional normal data. The corresponding random effects are also estimated. It is motivated by the analysis of omics data in clinical trials where the longitudinal omics data becomes increasingly common. It includes both one-stage models (without treatment) and two-stage models (with one treatment). For details of the algorithms, please check the materials on its GitHub repo. If you have any questions, feel free to contact the maintainers through the email below.
License: GPL (≥ 3)
Encoding: UTF-8
LazyData: true
URL: https://github.com/jiezhou-2/lglasso
Suggests: knitr, rmarkdown, testthat (≥ 3.0.0)
Depends: R (≥ 3.5)
NeedsCompilation: no
Packaged: 2026-09-24 02:07:36 UTC; f003r0s
Author: Jie Zhou [aut, cre, cph], Jiang Gui [aut], Weston Viles [aut], Anne Hoen [aut]
Maintainer: Jie Zhou <chowstat@gmail.com>
Repository: CRAN
Date/Publication: 2026-09-24 08:50:08 UTC
Imports: CVXR, glasso, MASS, fake, stats
RoxygenNote: 7.3.3
Config/testthat/edition: 3

Simulate longitudinal data from one-stage/two-stage model

Description

This function simulates longitudinal data that follows known network structures and fixed/random temporal correlation. It can be used to evaluate the effectiveness of network identification algorithms.

Usage

Simulate(type = c("homo", "heter"), n, p, m1, m2, tt, tau, alpha, group)

Arguments

type

which type of data the function is to generate. For option homo, data is generated from a homogeneous model. For option heter, data is generated from heterogeneous model.

n

the number of subjects in the data set

p

the dimension of the normal distribution

m1

the number of edges in true networks

m2

the edge difference between two networks

tt

the average time points for each subject

tau

the true dampening rate in homogeneous models

alpha

the true parameter in exponential distribution of tau when type is heter

group

a scalar of 1 or 2, indicating that data is generated from either one-stage or two-stage model.

Value

A data list. It includes the simulated data, true networks and tau. If type is heter, then true alpha is included as well.


Internal data‑list used by the package

Description

The object datalist is automatically generated by tools::add_datalist() and is used only by the package infrastructure. It is not part of the public API.


Longitudinal graphical lasso

Description

This function estimates precision matrices(networks) and random effects from longitudinal high-dimensional data under normality assumption.

Usage

lglasso(
  data,
  lambda,
  group = NULL,
  random = FALSE,
  expFix = 1,
  N = 100,
  maxit = 50,
  tol = 10^(-2),
  lower = c(0.01, 0.01),
  upper = c(10, 10),
  w.init = NULL,
  wi.init = NULL,
  trace = FALSE,
  ...
)

Arguments

data

n by (p+2) data frame in which the first column is subject IDs, the second column is the time points of longitudinal data.

lambda

numerical vector of tuning parameters. For one-stage model, lambda is a scalar controlling the sparsity of the network. For two-stage model, lambda is a vector of length 2, in which the first entry controls the sparsity of both pre-treatment and post-treatment networks, while the second entry controls the overlap of the two networks.

group

factor of length n if supplied. If group is a one-level factor, then a one-stage model is fitted. If group is a two-level factor, then a two-stage model is fitted. Data points that are before (after) the treatment (exposure) share the same level in group. If NULL, then a one-stage model is fitted.

random

a logical variable. If TRUE, then a heterogeneous model is fitted. Otherwise, a homogeneous model is fitted.

expFix

numerical number specifying the exponent in the covariance function of the longitudinal data. Default is 1.

N

a integer specifying the number of sampling for heterogeneous model

maxit

integer specifying the maximum iterations for the algorithms.

tol

a small number determining whether the algorithms converged and should stop.

lower

vector of length 1 or 2 which specifies the lower bounds for temporal correlation tau. It is of length 1 for one-stage model and 2 for two-stage model

upper

vector of length 1 or 2 which specifies the upper bounds for temporal correlation tau It is of length 1 for one-stage model and 2 for two-stage model

w.init

initial value for covariance matrix. Default is identity matrix.

wi.init

initial value for precision matrix. Default is identity matrix.

trace

whether or not show the progress of the computation

...

other inputs

Details

lglasso is developed to estimate precision matrices, or networks, and random effects \tau_i from high-dimensional longitudinal data. The one-stage model in lglasso is proposed in Zhou et al (2024). Currently, it contains two network identification models, i.e., one-stage and two-stage model. One-stage model assume a common network underlying the longitudinal data for all the subjects. Consequently, the function outputs a single network as the estimate in this case. In two-stage models, a treatment is applied at time t_i during the time interval for subject i. Therefore, there are two networks, i.e., pre- and post-treatment networks, that need to be estimated simultaneously. For details, please check the reference paper and the online resources.

Value

A list which includes:

w: the list of the estimates for covariance matrices

wi: the list of the estimates for precision matrices

tau: the estimate of dampening rate tau. For heterogeneous models, the output is a vector called random effects. For homogeneous model, the output is a scalar.

alpha: a scalar representing the estimate of the parameter in exponential distribution of tau for heterogeneous models. The output is NULL for homogeneous model

ll: the likelihood. ll is used to compute extended QIC for tuning parameter selection

Examples

## Not run: 
library(lglasso)
# number of nodes
p=15
# number of edge in general network
m1=20
# the difference between the number of edges in individual networks and general network
m2=5
# number of subjects
n=30
set.seed(1)
## One-stage model
### Estimate the network based on homogeneous one-stage model
####simulate data
dd=Simulate(type="homo",n=n,p=p,m1=m1,m2=m2,tau=2,tt=10)
ddata=dd$data
dim(ddata)
ddata[1:2,1:5]
#### Estimation
aa=lglasso(data=ddata,lambda = 0.01,trace=TRUE)
estimates=lapply(aa$wi,function(ll){ifelse(abs(ll)>10^(-5),1,0)})
#### estimated network
estimates
#### true network
dd$network
#### correlation parameter
aa$tau
#### likelihood
aa$ll



### Estimate the network based on heterogeneous one-stage model
####simulate data
dd=Simulate(type="heter",n=n,p=p,m1=m1,m2=m2,tt=10,alpha=5,group = 1)
ddata=dd$data$pre
dim(ddata)
ddata[1:2,1:5]
#### Estimation
aa=lglasso(data=ddata,lambda = 0.01,random=TRUE,trace=TRUE)
estimates=lapply(aa$wi,function(ll){ifelse(abs(ll)>10^(-5),1,0)})
#### estimated network
estimates
####  true network
dd$network
#### likelihood
aa$ll



## Two-stage model
### Estimate the networks based on homogeneous two-stage model
####simulate data
dd=Simulate(type="homo",n=n,p=p,m1=m1,m2=m2,tau=c(2,1),tt=10)
ddata=do.call(rbind,dd$data)
group=c(rep(0,nrow(ddata)/2),rep(1,nrow(ddata)/2))
dim(ddata)
ddata[1:2,1:5]
#### Estimation
aa=lglasso(data=ddata,lambda = c(0.01,0.01),group = group,trace=TRUE)
estimates=lapply(aa$wi,function(ll){ifelse(abs(ll)>10^(-5),1,0)})
#### estimated pre-treatment  network
estimates[[1]]
####  true pre-treatment network
dd$network$pre
#### estimated post-treatment  network
estimates[[2]]
####  true post-treatment network
dd$network$post
#### correlation parameters
aa$tau
#### likelihood
aa$ll


### Estimate the networks based on heterogeneous two-stage model
####simulate data
dd=Simulate(type="heter",n=n,p=p,m1=m1,m2=m2,tt=10,alpha=0.5,group=2)
ddata=do.call(rbind,dd$data)
group=c(rep(0,nrow(ddata)/2),rep(1,nrow(ddata)/2))
dim(ddata)
ddata[1:2,1:5]
#### Estimation
aa=lglasso(data=ddata,lambda = c(0.01,0.01),random=TRUE,group = group,trace=TRUE)
estimates=lapply(aa$wi,function(ll){ifelse(abs(ll)>10^(-5),1,0)})
#### estimated pre-treatment network
estimates[[1]]
#### true pre-treatment network
dd$network$pre
#### estimated post-treatment network
estimates[[2]]
####  true post-treatment network
dd$network$post
#### likelihood
aa$ll

## End(Not run)