% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/edge_confusion.R
\name{edge_confusion}
\alias{edge_confusion}
\title{Confusion Matrix Metrics for Edge Comparison and Recovery}
\usage{
edge_confusion(
  base,
  comparison,
  metric = c("all", "sen", "spec", "ppv", "npv", "fdr", "fom", "ba", "f1", "csi", "mcc"),
  full.names = FALSE
)
}
\arguments{
\item{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 \code{comparison}
but not in this network}

\item{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 \code{base}}

\item{metric}{Character vector.
Defaults to \code{"all"} metrics.
Available options:

\itemize{

\item \code{"all"} --- All available metrics (default)

\item \code{"sen"} --- Sensitivity (True Positive Rate):
\deqn{\frac{TP}{TP + FN}}

\item \code{"spec"} --- Specificity (True Negative Rate):
\deqn{\frac{TN}{TN + FP}}

\item \code{"ppv"} --- Positive Predictive Value (Precision):
\deqn{\frac{TP}{TP + FP}}

\item \code{"npv"} --- Negative Predictive Value:
\deqn{\frac{TN}{TN + FN}}

\item \code{"fdr"} --- False Discovery Rate:
\deqn{1 - PPV = \frac{FP}{TP + FP}}

\item \code{"fom"} --- False Omission Rate:
\deqn{1 - NPV = \frac{FN}{TN + FN}}

\item \code{"ba"} --- Balanced Accuracy:
\deqn{\frac{Sensitivity + Specificity}{2}}

\item \code{"f1"} --- F1 Score (harmonic mean of PPV and Sensitivity):
\deqn{\frac{2TP}{2TP + FP + FN}}

\item \code{"csi"} --- Critical Success Index (Jaccard / Threat Score):
\deqn{\frac{TP}{TP + FP + FN}}

\item \code{"mcc"} --- Matthews Correlation Coefficient:
\deqn{\frac{TP \times TN - FP \times FN}{\sqrt{(TP+FP)(TP+FN)(TN+FP)(TN+FN)}}}

}}

\item{full.names}{Boolean (length = 1).
Whether full or abbreviated names should be used.
Defaults to \code{FALSE}.
Set to \code{TRUE} for full names}
}
\value{
A named numeric vector of the requested confusion matrix metrics.
Values are generally in \eqn{[0, 1]}, with the exception of \code{"mcc"}
(Matthews Correlation Coefficient), which ranges from \eqn{-1} to \eqn{1}
where 1 indicates perfect agreement, 0 indicates chance-level performance,
and -1 indicates perfect disagreement. The vector contains only the elements
specified by \code{metric} (all ten metrics when \code{metric = "all"},
which is the default). Names are abbreviated (e.g., \code{"sen"}) when
\code{full.names = FALSE} (default), or expanded
(e.g., \code{"Sensitivity"}) when \code{full.names = TRUE}. Any metric
whose denominator is zero (e.g., sensitivity when no edges exist in
\code{base}) is returned as \code{NA}.
}
\description{
Computes many commonly used confusion matrix metrics
}
\examples{
# 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)

}
\author{
Alexander P. Christensen <alexpaulchristensen@gmail.com>
}
