# Example 1: Gaussian graph with AND-rule.
library(datasets)
head(iris)
X <- as.matrix(subset(iris,iris$Species=="setosa")[, -5])
# Build a sparse gaussian graph using the bootstrap ranking LASSO model.
# The parameters of B and Boots in the following example are set as small values to
# reduce the running time, however the default values are proposed.
SGraph.and <- SGraph(x=X, graphtype=c("gaussian"), B=2, Boots=2, edgerule=c("AND"),
plot=FALSE)
# Give out the adjacency matrix of variables.
SGraph.and$Adjmatrix
# Plot the graph based on the adjacency matrix of variables using the qgraph package.
library(qgraph)
qgraph(SGraph.and$Adjmatrix, directed=FALSE, color="blue", negCol="red",
edge.labels=TRUE, layout="circle")
# Example 2: Gene network estimation using the bootstrap ranking LASSO method.
library(SIS)
data(leukemia.train)
# Genes screened by the LASSO algorithm as candidates for graphical modeling.
set.seed(0123)
x <- as.matrix(leukemia.train[, -7130])
y <- as.factor(leukemia.train[, 7130])
cvfit <- cv.glmnet(x=x, y=y, type.measure="deviance", nfolds=3, family="binomial")
model.final <- cvfit$glmnet.fit
nzero <- as.matrix(coef(model.final, s=cvfit$lambda.min))
var_nz <- names(nzero[nzero[,1]!=0, ])[-1]
sub_data <- leukemia.train[, c(var_nz, "V7130")]
# Gene expression data subset from patients with acute myeloid leukemia.
subset_1 <- subset(sub_data, sub_data$V7130==1)
subset_1 <- as.matrix(subset_1[, -dim(subset_1)[2]])
# The parameters of B and Boots in the following example are set as small values to
# reduce the running time, however the default values are proposed.
SGraph.fit <- SGraph(subset_1, graphtype=c("gaussian"), B=2, Boots=2, edgerule=c("OR"))
Run the code above in your browser using DataLab