Title: | Build Dependency Graphs using Projection |
---|---|
Description: | Implements a general framework for creating dependency graphs using projection as introduced in Fan, Feng and Xia (2019)<arXiv:1501.01617>. Both lasso and sparse additive model projections are implemented. Both Pearson correlation and distance covariance options are available to generate the graph. |
Authors: | Yang Feng [aut, cre], Jianqing Fan [aut], Lucy Xia [aut] |
Maintainer: | Yang Feng <[email protected]> |
License: | GPL-2 |
Version: | 1.6 |
Built: | 2025-01-31 02:53:00 UTC |
Source: | https://github.com/cran/pgraph |
greg
calculate the regularized graphical model estimation using lasso, scad and adaptive lasso penalties. It report the results in the form of roc results for each method.
greg(z, A, eps = 1e-15, rholist = NULL, gamma = 0.5, trace = FALSE)
greg(z, A, eps = 1e-15, rholist = NULL, gamma = 0.5, trace = FALSE)
z |
n * p dimensional matrix |
A |
p * p true graph |
eps |
a tolerence level for thresholding |
rholist |
a sequence of penalty parameters |
gamma |
the adaptive lasso penalty parameter |
trace |
whether to trace to estimation process. |
a list.
roc.lasso |
roc results for lasso |
roc.scad |
roc results for scad |
roc.alasso |
roc results for adaptive lasso |
set.seed(0) p = 20; n = 300; tmp=runif(p-1,1,3) s=c(0,cumsum(tmp)); s1=matrix(s,p,p) cov.mat.true=exp(-abs(s1-t(s1))) prec.mat.true=solve(cov.mat.true); a=matrix(rnorm(p*n),n,p) data.sa=a%*%chol(cov.mat.true); true.graph = outer(1:p,1:p,f<-function(x,y){(abs(x-y)==1)}) greg.fit = greg(data.sa, true.graph) auc.lasso = sum(diff(greg.fit$roc.lasso[,1])*greg.fit$roc.lasso[-1,2]) auc.alasso = sum(diff(greg.fit$roc.alasso[,1])*greg.fit$roc.alasso[-1,2]) auc.scad = sum(diff(greg.fit$roc.scad[,1])*greg.fit$roc.scad[-1,2]) auc.lasso auc.alasso auc.scad
set.seed(0) p = 20; n = 300; tmp=runif(p-1,1,3) s=c(0,cumsum(tmp)); s1=matrix(s,p,p) cov.mat.true=exp(-abs(s1-t(s1))) prec.mat.true=solve(cov.mat.true); a=matrix(rnorm(p*n),n,p) data.sa=a%*%chol(cov.mat.true); true.graph = outer(1:p,1:p,f<-function(x,y){(abs(x-y)==1)}) greg.fit = greg(data.sa, true.graph) auc.lasso = sum(diff(greg.fit$roc.lasso[,1])*greg.fit$roc.lasso[-1,2]) auc.alasso = sum(diff(greg.fit$roc.alasso[,1])*greg.fit$roc.alasso[-1,2]) auc.scad = sum(diff(greg.fit$roc.scad[,1])*greg.fit$roc.scad[-1,2]) auc.lasso auc.alasso auc.scad
pgraph
calculate the conditional dependency graph (with/without external factors) via projection using lasso or sparse additive model.
pgraph( z, f = NULL, method = c("lasso", "sam", "ols"), cond = TRUE, R = 199, randSeed = 0, trace = FALSE )
pgraph( z, f = NULL, method = c("lasso", "sam", "ols"), cond = TRUE, R = 199, randSeed = 0, trace = FALSE )
z |
n * p dimensional matrix |
f |
n * q factor matrix. Default = 'NULL'. |
method |
projection method. Default = 'lasso'. |
cond |
whether to create a conditional graph or unconditional graph. Default = TRUE. If cond = FALSE, f must be provided. |
R |
number of random permutations for the test. |
randSeed |
the random seed for the program. Default = 0. |
trace |
whether to trace to estimation process. |
a list to be used to calculate the ROC curve.
statmat.pearson |
matrix with pearson correlation test |
statmat.dcov |
matrix with distance covariance test |
library(splines) set.seed(0) p = 5; n = 100; tmp=runif(p-1,1,3) s=c(0,cumsum(tmp)); s1=matrix(s,p,p) cov.mat.true=exp(-abs(s1-t(s1))) prec.mat.true=solve(cov.mat.true); a=matrix(rnorm(p*n),n,p) data.sa=a%*%chol(cov.mat.true); true.graph = outer(1:p,1:p,f<-function(x,y){(abs(x-y)==1)}) methodlist = c('lasso','sam') fit = vector(mode='list', length=2) info = vector(mode='list', length=2) auc = NULL for(i in 1:2){ method = methodlist[i] fit[[i]] = pgraph(data.sa, method = method) info[[i]] = roc(fit[[i]]$statmat.pearson, true.graph) auc[i] = sum(-diff(info[[i]][,1])*info[[i]][-1,2]) cat(method, ': auc=', auc[i],'\n') }
library(splines) set.seed(0) p = 5; n = 100; tmp=runif(p-1,1,3) s=c(0,cumsum(tmp)); s1=matrix(s,p,p) cov.mat.true=exp(-abs(s1-t(s1))) prec.mat.true=solve(cov.mat.true); a=matrix(rnorm(p*n),n,p) data.sa=a%*%chol(cov.mat.true); true.graph = outer(1:p,1:p,f<-function(x,y){(abs(x-y)==1)}) methodlist = c('lasso','sam') fit = vector(mode='list', length=2) info = vector(mode='list', length=2) auc = NULL for(i in 1:2){ method = methodlist[i] fit[[i]] = pgraph(data.sa, method = method) info[[i]] = roc(fit[[i]]$statmat.pearson, true.graph) auc[i] = sum(-diff(info[[i]][,1])*info[[i]][-1,2]) cat(method, ': auc=', auc[i],'\n') }
projcore
calculate the projected matrix given
factors.
projcore( x, b, method = c("lasso", "sam", "ols"), one.SE = TRUE, refit = TRUE, randSeed = 0 )
projcore( x, b, method = c("lasso", "sam", "ols"), one.SE = TRUE, refit = TRUE, randSeed = 0 )
x |
first vector |
b |
factor matrix |
method |
projection method. Default = 'lasso'. |
one.SE |
whether to use the 1se rule for glmnet. Default = TRUE. |
refit |
whether to refit the selected model. Default = TRUE. |
randSeed |
the random seed for the program. Default = 0. |
eps |
the residual matrix after projection |
projcov
calculate the projected distance covariance of two vectors given
common factors.
projcov( x, y, b, method = c("lasso", "sam", "ols"), one.SE = TRUE, refit = TRUE, R = 199, randSeed = 0, normalized = FALSE )
projcov( x, y, b, method = c("lasso", "sam", "ols"), one.SE = TRUE, refit = TRUE, R = 199, randSeed = 0, normalized = FALSE )
x |
first vector |
y |
second vector |
b |
factor matrix |
method |
projection method. Default = 'lasso'. |
one.SE |
whether to use the 1se rule for glmnet. Default = TRUE. |
refit |
whether to refit the selected model. Default = TRUE. |
R |
number of random permutations for the test. |
randSeed |
the random seed for the program. Default = 0. |
normalized |
whether to normalized by S2. Default = FALSE. |
a list.
test.pearson |
pearson correlection test statistic |
test.dcov |
distance covariance test statistic |
xeps |
residual of projection of x on b |
yeps |
residual of projection of y on b |
library(splines) set.seed(0) K = 3 n = 100 b = matrix(rnorm(K*n),n,K) bx = 1:3 by = c(1,2,2) x = b%*%bx+rnorm(n) y = b%*%by+rnorm(n) fit1 = projcov(x, y, b, method = 'lasso') fit2 = projcov(x, y, b, method = 'sam')
library(splines) set.seed(0) K = 3 n = 100 b = matrix(rnorm(K*n),n,K) bx = 1:3 by = c(1,2,2) x = b%*%bx+rnorm(n) y = b%*%by+rnorm(n) fit1 = projcov(x, y, b, method = 'lasso') fit2 = projcov(x, y, b, method = 'sam')
roc
calculate the fpr and tpr for the roc curve
roc(a, a0)
roc(a, a0)
a |
p * p estimated graph |
a0 |
p * p true graph |
a list.
tpr |
tpr sequence |
fpr |
fpr sequence |