Skip to contents

Computes an F1-score matrix comparing true spatial ecotype (SE) labels and predicted SE labels (e.g., from cross-validation). The function calculates precision and recall per SE within each sample and returns an averaged F1-score matrix across samples.

Usage

ComputeMetrics(
  scmeta,
  SE = "SE",
  Pred = "cvPred",
  CellType = NULL,
  Sample = "Sample",
  metric = c("F1", "F2", "precision", "recall")[1]
)

Arguments

scmeta

A data.frame containing single-cell metadata.

SE

Character. Column name in `scmeta` for true SE labels.

Pred

Character. Column name in `scmeta` for predicted SE labels.

CellType

Character or NULL. Optional column name for cell type. If provided, SE labels will be concatenated with cell type labels.

Sample

Character or NULL. Column name for sample identifiers in `scmeta`. If NULL, all cells are treated as coming from a single sample.

metric

One of 'F1', 'F2', 'precision', or 'recall'.

Value

A matrix of averaged F1 scores with rows and columns corresponding to SE labels.

Details

The function computes the specified metrics (e.g. F1 scores) for all SEs, and then average them across samples.