Learn R Programming

L0ggm (version 0.1.2)

edge_confusion: Confusion Matrix Metrics for Edge Comparison and Recovery

Description

Computes many commonly used confusion matrix metrics

Usage

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

Value

A named numeric vector of the requested confusion matrix metrics. Values are generally in \([0, 1]\), with the exception of "mcc"

(Matthews Correlation Coefficient), which ranges from \(-1\) to \(1\)

where 1 indicates perfect agreement, 0 indicates chance-level performance, and -1 indicates perfect disagreement. The vector contains only the elements specified by metric (all ten metrics when metric = "all", which is the default). Names are abbreviated (e.g., "sen") when full.names = FALSE (default), or expanded (e.g., "Sensitivity") when full.names = TRUE. Any metric whose denominator is zero (e.g., sensitivity when no edges exist in base) is returned as NA.

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

Author

Alexander P. Christensen <alexpaulchristensen@gmail.com>

Examples

Run this code
# Set split
split <- sample(
  1:nrow(basic_smallworld),
  round(nrow(basic_smallworld) / 2)
)

# Estimate networks
split1 <- network_estimation(basic_smallworld[split,])
split2 <- network_estimation(basic_smallworld[-split,])

# Estimate metrics
edge_confusion(split1, split2)

Run the code above in your browser using DataLab