oldpar <- par(no.readonly = TRUE)
par(mar = rep(7, 4))
# Simulation of random graph with 50 nodes
set.seed(1)
simul <- SimulateGraphical(n = 100, pk = 50, topology = "random", nu_within = 0.05)
print(simul)
plot(simul)
# Simulation of scale-free graph with 20 nodes
set.seed(1)
simul <- SimulateGraphical(n = 100, pk = 20, topology = "scale-free")
plot(simul)
# Extracting true precision/correlation matrices
set.seed(1)
simul <- SimulateGraphical(
n = 100, pk = 20,
topology = "scale-free", output_matrices = TRUE
)
str(simul)
# Simulation of multi-block data
set.seed(1)
pk <- c(20, 30)
simul <- SimulateGraphical(
n = 100, pk = pk,
pd_strategy = "min_eigenvalue"
)
mycor <- cor(simul$data)
Heatmap(mycor,
col = c("darkblue", "white", "firebrick3"),
legend_range = c(-1, 1), legend_length = 50,
legend = FALSE, axes = FALSE
)
for (i in 1:2) {
axis(side = i, at = c(0.5, pk[1] - 0.5), labels = NA)
axis(
side = i, at = mean(c(0.5, pk[1] - 0.5)),
labels = ifelse(i == 1, yes = "Group 1", no = "Group 2"),
tick = FALSE, cex.axis = 1.5
)
axis(side = i, at = c(pk[1] + 0.5, sum(pk) - 0.5), labels = NA)
axis(
side = i, at = mean(c(pk[1] + 0.5, sum(pk) - 0.5)),
labels = ifelse(i == 1, yes = "Group 2", no = "Group 1"),
tick = FALSE, cex.axis = 1.5
)
}
# User-defined function for graph simulation
CentralNode <- function(pk, hub = 1) {
theta <- matrix(0, nrow = sum(pk), ncol = sum(pk))
theta[hub, ] <- 1
theta[, hub] <- 1
diag(theta) <- 0
return(theta)
}
simul <- SimulateGraphical(n = 100, pk = 10, implementation = CentralNode)
plot(simul) # star
simul <- SimulateGraphical(n = 100, pk = 10, implementation = CentralNode, hub = 2)
plot(simul) # variable 2 is the central node
# User-defined adjacency matrix
mytheta <- matrix(c(
0, 1, 1, 0,
1, 0, 0, 0,
1, 0, 0, 1,
0, 0, 1, 0
), ncol = 4, byrow = TRUE)
simul <- SimulateGraphical(n = 100, theta = mytheta)
plot(simul)
# User-defined adjacency and block structure
simul <- SimulateGraphical(n = 100, theta = mytheta, pk = c(2, 2))
mycor <- cor(simul$data)
Heatmap(mycor,
col = c("darkblue", "white", "firebrick3"),
legend_range = c(-1, 1), legend_length = 50, legend = FALSE
)
par(oldpar)
Run the code above in your browser using DataLab