calculate_fs_metrics_cv: Calculate Feature Selection Metrics

View source: R/helper_functions.R

calculate_fs_metrics_cvR Documentation

Calculate Feature Selection Metrics

Description

Computes TP, FP, FN, TN, Sensitivity, Specificity, Precision, and F1-Score.

Usage

calculate_fs_metrics_cv(
  selected_vars,
  true_vars_global,
  total_feature_count_p_val
)

Arguments

selected_vars

A character vector of selected variable names.

true_vars_global

A character vector of the true variable names.

total_feature_count_p_val

The total number of candidate features (p).

Details

The function handles edge cases where the number of true positives, false positives, or false negatives is zero to avoid division-by-zero errors in precision, sensitivity, and F1-score calculations.

Value

A list containing the following numeric elements:

  • TP: True Positives

  • FP: False Positives

  • FN: False Negatives

  • TN: True Negatives

  • Sens: Sensitivity (Recall)

  • Spec: Specificity

  • Prec: Precision

  • F1: F1-Score

  • N_Selected: Total number of selected variables

Note

Inputs are character vectors; no NA imputation is performed. Division by zero is guarded with 0-valued metrics as documented.

Examples

# --- Example for an internal function ---
# Imagine our model selected 3 variables: V1, V2, and V10
selected <- c("V1", "V2", "V10")

# And the "true" important variables were V1, V2, V3, and V4
true_set <- c("V1", "V2", "V3", "V4")

# And the total pool of variables was 50
p <- 50

# Calculate the performance metrics
metrics <- calculate_fs_metrics_cv(
  selected_vars = selected,
  true_vars_global = true_set,
  total_feature_count_p_val = p
)

print(metrics)
#> Expected output:
#> $TP
#> [1] 2
#> $FP
#> [1] 1
#> $FN
#> [1] 2
#> $TN
#> [1] 45
#> $Sens
#> [1] 0.5
#> $Spec
#> [1] 0.9782609
#> $Prec
#> [1] 0.6666667
#> $F1
#> [1] 0.5714286
#> $N_Selected
#> [1] 3

TemporalForest documentation built on Dec. 23, 2025, 1:06 a.m.