# NOT RUN {
# }
# NOT RUN {
# Load packages
# Compare six methods on simulated data:
# MRPC,
# pc in pcalg (Kalisch et al., 2012),
# and pc.stable, mmpc mmhc and hc in bnlearn (Scutari, 2010)
library(MRPC) # MRPC
library(pcalg) # pc
library(bnlearn) # pc.stable, mmpc, mmhc and hc
####################################-->
# Load simulated data
# Model 1 (mediation)
Truth <- MRPCtruth$M1 # Truth for model 1
# The 1st column of the data matrix is a genetic variant
# and the remaining columns are gene expression nodes.
data <- simu_data_M1 # load data for model 1
n <- nrow (data) # Number of rows
V <- colnames(data) # Column names
# Calculate Pearson correlation
suffStat_C <- list(C = cor(data),
n = n)
# Infer the graph by MRPC
# using the LOND method for FDR control
MRPC.fit <- MRPC(data,
suffStat = suffStat_C,
GV = 1,
FDR = 0.05,
indepTest = 'gaussCItest',
labels = V,
FDRcontrol = 'LOND',
verbose = FALSE)
# Infer the graph by pc
pc.fit <- pc(suffStat = suffStat_C,
indepTest = gaussCItest,
alpha = 0.05,
labels = V,
verbose = FALSE)
# arcs (from gene expression to genotype) to be excluded
# in pc.stable and mmpc
bl <- data.frame (from = colnames (data)[-1],
to = 'V1')
# Infer the graph by pc.stable
pc.stable.fit <- pc.stable(data.frame(data),
blacklist = bl,
undirected = FALSE)
# Infer the graph by mmpc
mmpc.fit <- mmpc(data.frame(data),
blacklist = bl,
undirected = FALSE,
debug = FALSE)
# Infer the graph by mmhc
mmhc.fit <- mmhc(data.frame(data),
blacklist = bl,
debug = FALSE)
# Infer the graph by hc
hc.fit <- hc (data.frame (data),
blacklist = bl,
debug = FALSE)
# Plot the inferred graphs
par(mfrow = c(1, 7))
plot(Truth,
main = "(A) Truth")
plot(MRPC.fit,
main = "(B) MRPC")
plot(pc.fit,
main ="(C) pc")
graphviz.plot(pc.stable.fit,
main = "(D) pc.stable")
graphviz.plot(mmpc.fit,
main = "(E) mmpc")
graphviz.plot(mmhc.fit,
main = "(F) mmhc")
graphviz.plot(hc.fit,
main = "(G) hc")
####################################<--
####################################-->
# Use alpha, instead of FDR control
# in MRPC
# Model 1
Truth <- MRPCtruth$M1 # Truth for model 1
data <- simu_data_M1 # load data for model 1
n <- nrow (data) # Number of rows
V <- colnames(data) # Column names
# Calculate Pearson correlation
suffStat_C <- list(C = cor(data),
n = n)
# Infer the graph by MRPC
# using the LOND method for FDR control
MRPC.fit <- MRPC(data,
suffStat = suffStat_C,
GV = 1,
alpha = 0.01,
indepTest = 'gaussCItest',
labels = V,
FDRcontrol = 'NONE',
verbose = FALSE)
# The inferred adjacency matrix
as(MRPC.fit@graph, "matrix")
####################################<--
####################################-->
# Run MRPC on the complex data set with ADDIS as the FDR control method.
data <- data_examples$complex$cont$withGV$data
n <- nrow (data) # Number of rows
V <- colnames(data) # Column names
# Calculate Pearson correlation
suffStat_C <- list(C = cor(data),
n = n)
# Infer the graph by MRPC
MRPC.addis <- MRPC(data,
suffStat = suffStat_C,
GV = 14,
FDR = 0.05,
indepTest = 'gaussCItest',
labels = V,
FDRcontrol = 'ADDIS',
tau = 0.5,
lambda = 0.25,
verbose = FALSE)
# Plot the true and inferred graphs.
par(mfrow = c(1, 2))
plot(data_examples$complex$cont$withGV$graph,
main = 'True graph')
plot(MRPC.addis,
main = 'Inferred graph')
# Other graph visualizations
# Adjacency matrix from directed graph
Adj_directed <- as(MRPC.addis@graph,
"matrix")
# Plot of dendrogram with modules of different colors
PlotDendrogramObj <- PlotDendrogram(Adj_directed,
minModuleSize = 5)
# Visualization of inferred graph with module colors
PlotGraphWithModulesObj <- PlotGraphWithModules(Adj_directed,
PlotDendrogramObj,
GV = 14,
node.size = 8,
arrow.size = 5,
label.size = 3,
alpha = 1)
plot(PlotGraphWithModulesObj)
####################################<--
####################################-->
# Other models are available and may be called as follows:
# Model 0
# Truth <- MRPCtruth$M0
# data <- simu_data_M0
# Model 2
# Truth <- MRPCtruth$M2
# data <- simu_data_M2
# Model 3
# Truth <- MRPCtruth$M3
# data <- simu_data_M3
# Model 4
# Truth <- MRPCtruth$M4
# data <- simu_data_M4
# Model Multiparent
# Truth <- MRPCtruth$Multiparent
# data <- simu_data_multiparent
# Model Star
# Truth <- MRPCtruth$Star
# data <- simu_data_starshaped
# Model Layered
# Truth <- MRPCtruth$Layered
# data <- simu_data_layered
####################################<--
####################################-->
# Discrete data with genetic variants
data <- data_examples$simple$disc$withGV$data
n <- nrow (data) # Sample size
V <- colnames (data) # Node labels
# need different suffStat for discrete data
suffStat <- list (dm = data, adaptDF = FALSE, n.min = 1000)
# Infer the graph by MRPC
data.mrpc.disc.withGV <- MRPC (data,
suffStat = suffStat,
GV = 1,
FDR = 0.05,
indepTest = 'disCItest',
labels = V,
FDRcontrol = 'LOND',
verbose = FALSE)
# Discrete data without genetic variants
data <- data_examples$simple$disc$withoutGV$data
n <- nrow (data) # Sample size
V <- colnames (data) # Node labels
suffStat <- list (dm = data, adaptDF = FALSE)
# Infer the graph by MRPC
data.mrpc.disc.withoutGV <- MRPC (data,
suffStat = suffStat,
GV = 0,
FDR = 0.05,
indepTest = 'disCItest',
labels = V,
FDRcontrol = 'LOND',
verbose = FALSE)
# Plots of true and inferred graphs on discrete data
par (mfrow = c (2,2))
plot (data_examples$simple$disc$withGV$graph, main = "truth")
plot (data.mrpc.disc.withGV, main = "inferred")
plot (data_examples$simple$disc$withoutGV$graph, main = "truth")
plot (data.mrpc.disc.withoutGV, main = "inferred")
####################################<--
# }
# NOT RUN {
# }
Run the code above in your browser using DataLab