Confusion metrics at a PIP threshold
confusion_at_threshold.RdComputes true/false positive/negative counts and rates by comparing a continuous score matrix (e.g., PIP) against a binary ground truth adjacency matrix at a given threshold. Only the upper triangle is used.
Arguments
- score_mat
Numeric matrix
[p, p]; continuous edge scores (e.g., posterior inclusion probabilities frompip_edges).- truth_mat
Numeric matrix
[p, p]; binary ground truth adjacency (1 = edge present, 0 = absent).- thr
Numeric; threshold for edge selection. An edge is selected if
score_mat[i,j] >= thr.- upper_only
Logical; if
TRUE(default), only the upper triangle is evaluated (appropriate for undirected graphs).
Value
A named numeric vector with components:
TPTrue positives (correctly selected edges).
FPFalse positives (incorrectly selected non-edges).
TNTrue negatives (correctly excluded non-edges).
FNFalse negatives (missed true edges).
TPRTrue positive rate (sensitivity / recall).
FPRFalse positive rate (1 - specificity).
Examples
sim <- simulate_multiggm(K = 2, p = 8, n = 80, seed = 1)
fit <- multiggm_mcmc(data_list = sim$data_list, burnin = 200, nsave = 100)
pip <- pip_edges(fit)
confusion_at_threshold(pip[,,1], sim$adj_list[[1]], thr = 0.5)
#> TP FP TN FN TPR FPR
#> 8.0000000 0.0000000 15.0000000 5.0000000 0.6153846 0.0000000