## example in Figure 1 from (Castelo and Roverato, accepted)
## undirected graph on 9 vertices
edg <- matrix(c(1, 4,
2, 4,
3, 4,
4, 5,
5, 6,
5, 7,
8, 9),
ncol=2, byrow=TRUE)
## create a corresponding synthetic precision matrix with
## partial correlation values set to -0.4 for all present edges
K <- matrix(0, nrow=9, ncol=9, dimnames=list(1:9, 1:9))
K[edg] <- -0.4
K <- K + t(K)
diag(K) <- 1
## calculate the corresponding covariance matrix
S <- solve(K)
## calculate networked partial correlations for all present
## edges
npc <- sapply(1:nrow(edg), function(i) qpPathWeight(S, edg[i, ]))
## note that while all partial correlations are zero for missing
## edges and are equal to -0.4 for present edges, the corresponding
## networked partial ## correlations are also zero for missing edges
## but may be different between them for present edges, depending on
## the connections between the vertices
cbind(edg, npc)
Run the code above in your browser using DataLab