require(mvtnorm)
require(graph)
nVar <- 50 ## number of variables
maxCon <- 5 ## maximum connectivity per variable
nObs <- 30 ## number of observations to simulate
set.seed(123)
A <- qpRndGraph(p=nVar, d=maxCon)
Sigma <- qpG2Sigma(A, rho=0.5)
X <- rmvnorm(nObs, sigma=as.matrix(Sigma))
## estimate Pearson correlations
pcc.estimates <- qpPCC(X)
## the higher the threshold
g <- qpAnyGraph(abs(pcc.estimates$R), threshold=0.9,
remove="below")
## the sparser the qp-graph
numEdges(g) / choose(numNodes(g), 2)
## the lower the threshold
g <- qpAnyGraph(abs(pcc.estimates$R), threshold=0.5,
remove="below")
# the denser the graph
numEdges(g) / choose(numNodes(g), 2)
Run the code above in your browser using DataLab