Skip to contents

Formats the output of summarize_ptsd_changes() into a more readable table with proper labels and formatting of percentages and metrics.

Usage

create_readable_summary(summary_stats, DT = FALSE)

Arguments

summary_stats

A dataframe output from summarize_ptsd_changes() containing raw diagnostic metrics and counts

DT

Logical. If TRUE, return the summary as an interactive datatable widget. If FALSE (default), return a plain data.frame. The DT package must be installed when DT = TRUE.

Value

A formatted data.frame (or a datatable widget when DT = TRUE) with the following columns:

  • Scenario: Name of the diagnostic criterion

  • Total Diagnosed: Count and percentage of diagnosed cases

  • Total Non-Diagnosed: Count and percentage of non-diagnosed cases

  • True Positive: Count of cases diagnosed under both criteria

  • True Negative: Count of cases not diagnosed under either criterion

  • Newly Diagnosed: Count of new positive diagnoses (false positive)

  • Newly Non-Diagnosed: Count of new negative diagnoses (false negative)

  • True Cases: Total correctly classified cases

  • False Cases: Total misclassified cases

  • Sensitivity, Specificity, PPV, NPV, Accuracy, Balanced Accuracy: Diagnostic accuracy metrics (4 decimals)

Details

Reformats the diagnostic metrics into a presentation-ready format:

  • Combines counts with percentages for diagnosed/non-diagnosed cases

  • Rounds diagnostic accuracy metrics to 4 decimal places

  • Provides clear column headers for all metrics

Examples

# Using the output from summarize_ptsd_changes
n_cases <- 100
sample_data <- data.frame(
  PTSD_orig = sample(c(TRUE, FALSE), n_cases, replace = TRUE),
  PTSD_alt1 = sample(c(TRUE, FALSE), n_cases, replace = TRUE)
)

# Generate and format summary
diagnostic_metrics <- summarize_ptsd_changes(sample_data)
readable_summary <- create_readable_summary(diagnostic_metrics)
print(readable_summary)
#>    Scenario Total Diagnosed Total Non-Diagnosed True Positive True Negative
#> 1 PTSD_orig        49 (49%)            51 (51%)            49            51
#> 2 PTSD_alt1        58 (58%)            42 (42%)            29            22
#>   Newly Diagnosed Newly Non-Diagnosed True Cases False Cases Sensitivity
#> 1               0                   0        100           0      1.0000
#> 2              29                  20         51          49      0.5918
#>   Specificity PPV    NPV Accuracy Balanced Accuracy
#> 1      1.0000 1.0 1.0000     1.00            1.0000
#> 2      0.4314 0.5 0.5238     0.51            0.5116