network.confusion: Confusion Matrix Metrics for Edge Comparison and Recovery

View source: R/network.confusion.R

network.confusionR Documentation

Confusion Matrix Metrics for Edge Comparison and Recovery

Description

Computes many commonly used confusion matrix metrics

Usage

network.confusion(
  base,
  comparison,
  metric = c("all", "sen", "spec", "ppv", "npv", "fdr", "fom", "ba", "f1", "csi", "mcc"),
  full.names = FALSE
)

Arguments

base

Matrix or data frame. Network that will be treated as the "ground truth" such that a false positive represents an edge that is present in comparison but not in this network

comparison

Matrix or data frame. Network that will be treated as the estimator such that a false positive represents an edge that is present in this network but not in base

metric

Character vector. Defaults to "all" metrics. Available options:

  • "all" — All available metrics (default)

  • "sen" — Sensitivity (True Positive Rate):

    \frac{TP}{TP + FN}

  • "spec" — Specificity (True Negative Rate):

    \frac{TN}{TN + FP}

  • "ppv" — Positive Predictive Value (Precision):

    \frac{TP}{TP + FP}

  • "npv" — Negative Predictive Value:

    \frac{TN}{TN + FN}

  • "fdr" — False Discovery Rate:

    1 - PPV = \frac{FP}{TP + FP}

  • "fom" — False Omission Rate:

    1 - NPV = \frac{FN}{TN + FN}

  • "ba" — Balanced Accuracy:

    \frac{Sensitivity + Specificity}{2}

  • "f1" — F1 Score (harmonic mean of PPV and Sensitivity):

    \frac{2TP}{2TP + FP + FN}

  • "csi" — Critical Success Index (Jaccard / Threat Score):

    \frac{TP}{TP + FP + FN}

  • "mcc" — Matthews Correlation Coefficient:

    \frac{TP \times TN - FP \times FN}{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}

full.names

Boolean (length = 1). Whether full or abbreviated names should be used. Defaults to FALSE. Set to TRUE for full names

Value

Returns a named vector of confusion matrix metrics

Author(s)

Hudson Golino <hfg9s at virginia.edu> and Alexander P. Christensen <alexpaulchristensen@gmail.com>

Examples

# Load data
wmt <- wmt2[,7:24]

# Set split
split <- sample(1:nrow(wmt), round(nrow(wmt) / 2))

# Estimate networks
split1 <- network.estimation(wmt[split,])
split2 <- network.estimation(wmt[-split,])

# Estimate metrics
network.confusion(split1, split2)


EGAnet documentation built on April 13, 2026, 5:07 p.m.