Package 'lglasso'

Title: Graphical Lasso for Longitudinal Data
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.
Authors: Jie Zhou [aut, cre, cph], Jiang Gui [aut], Weston Viles [aut], Anne Hoen [aut]
Maintainer: Jie Zhou <[email protected]>
License: GPL (>= 3)
Version: 2.1.0
Built: 2026-10-08 02:12:35 UTC
Source: https://github.com/jiezhou-2/lglasso

Help Index


Cross validation for lglasso

Description

The function computes the cross validation errors in lglasso.

Usage

CVlglasso(
  data,
  K,
  group = NULL,
  random = FALSE,
  lambda = NULL,
  nlam = 10,
  lam.min.ratio = 0.01,
  expFix = 1,
  trace = FALSE
)

Arguments

data

same as in lglasso

K

fold number for the cross validation

group

same as in lglasso

random

same as in lglasso

lambda

tuning parameter. For one-stage model, lambda is a vector. For two-stage model, lambda is a 2-column matrix. The first column is tuning parameter controlling the sparsity, the second column is tuning parameter controlling the similarity of two networks.

nlam

If lambda is NULL, then nlam set the number of tuning parameter

lam.min.ratio

ratio of largest lambda vs smallest lambda

expFix

same as in lglasso

trace

logical variable. Whether show the computation process

Value

list of length 2. The first component is the cross validation errors, the second component is the corresponding tuning parameters


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 τi\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 tit_i during the time interval for subject ii. 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)

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

Description

This function randomly generates precision matrices (networks) and then simulates normal data that follows these network structures.

Usage

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

Arguments

type

which type of data you are generating. There are two options. One is homo which generates subjects with identical temporal correlation parameter. The other is heter which generates subjects with different temporal correlation parameter.

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 one-stage or two-stage model.

Value

a data list. It includes the data generated, true networks underlying the data,true tau. If type is heter, then true parameter alpha is included as well.