
Calculate diagnostic likelihood ratios
Source:R/DiagnosticLikelihoodRatioTable.R
DiagnosticLikelihoodRatioTable.RdCalculates diagnostic likelihood ratios for categorical diagnostic results and binary outcomes. A likelihood ratio is the probability of a result among outcome-positive participants divided by its probability among outcome-negative participants; this is a diagnostic accuracy measure, not a nested-model test.
Usage
DiagnosticLikelihoodRatioTable(
data,
outcome_vars,
predictor_vars,
positive_level = NULL,
predictor_positive_level = NULL,
stratify_by = NULL,
confidence_level = 0.95,
continuity_correction = NULL,
Relabel = TRUE,
Pthresh = 0.05,
PVar = "PValue"
)Arguments
- data
A data frame.
- outcome_vars
Character vector of binary outcome variable names.
- predictor_vars
Character vector of categorical or binary diagnostic predictor names.
- positive_level
Optional outcome-positive level specification:
NULL, one level for all outcomes, or a named vector keyed by outcome variable.- predictor_positive_level
Optional positive-result specification for binary predictors:
NULL, one level for all predictors, or a named vector.- stratify_by
Optional character vector of variables defining strata.
- confidence_level
Confidence level for log-scale LR confidence intervals.
- continuity_correction
Optional positive value added to all four calculation cells only if a zero cell occurs.
NULLpreserves zero and infinite estimates.- Relabel
Logical; use attached variable labels when available.
- Pthresh
Significance threshold, default
0.05. An explicitly supplied value takes precedence over a legacy significance threshold argument.- PVar
P-value column used for significance decisions. Defaults to raw
"PValue"; select"PValueFDR"to use Benjamini-Hochberg adjusted values. Explicit legacy p-column names remain accepted. Existing, explicitly named FDR plots and adjusted-value columns are retained.Explicit
Pthreshtakes precedence overAlpha,FDRAlpha,label_q, oradjusted_significance_threshold. Pairwisestar_p = "adjusted"retains its legacy adjustment method unlessPVaris supplied;PVar = "PValueFDR"always selects BH.star_p = "none"suppresses legacy pairwise stars. Stars retain conventional p-value tiers within the requested cutoff.
Value
A list containing Results, BinarySummary, compact and expanded gt
tables (FormattedTable, LargeTable, BinaryFormattedTable, and
BinaryLargeTable), and Metadata.
Details
Binary predictors produce sensitivity, specificity, LR+, and LR-. Predictors with more than two levels return one likelihood ratio for each result level. Numeric predictors with more than two observed values must be categorized first.
Categorical input safeguards apply to predictor_vars and stratify_by.
Numeric columns are converted locally to factors, with a warning, only when
all observed values are finite whole-number codes and there are at most 10
distinct non-missing values. Other numeric inputs error: explicitly convert
the column to a factor first if categorical treatment is intended (for
example, df_All$cohort <- factor(df_All$cohort)). Few unique values alone
do not establish categorical meaning. Factors, character columns, and logical
columns are accepted; more than 10 observed categories warn and continue.
Entirely missing columns produce unavailable statistical requests; unsupported types error. Caller data are unchanged,
and existing restrictions on the required number of groups still apply.
Statistical results and provenance
See inference-results for the shared Results and Metadata contract.
See also
PlotDiagnosticLRHeatmap() for matrix views and
PlotDiagnosticLRForest() for estimate-and-interval views.
Examples
data(SampleData)
data(SampleVariableTypes)
df_Labelled <- RevalueData(SampleData, SampleVariableTypes)$RevaluedData
df_Labelled$DiagnosisBinary <- factor(df_Labelled$Diagnosis,
levels = c("Control", "Impaired"))
lr <- DiagnosticLikelihoodRatioTable(df_Labelled, "DiagnosisBinary",
c("sex", "Genotype"))
#> DiagnosisBinary: 'Impaired' treated as outcome-positive.
lr$FormattedTable
Diagnostic likelihood ratios
Stratum
Outcome
Diagnostic result
N
Case %
Control %
Likelihood ratio (95% CI)
PlotDiagnosticLRHeatmap(lr)
#> $DiagnosticLR
#>
#> $DiagnosticMatrices
#>
#> $DiagnosticLRData
#> # A tibble: 8 × 43
#> Outcome OutcomeLabel OutcomePositiveLevel Predictor PredictorLabel
#> <chr> <chr> <chr> <chr> <chr>
#> 1 DiagnosisBinary DiagnosisBinary Impaired sex Sex
#> 2 DiagnosisBinary DiagnosisBinary Impaired sex Sex
#> 3 DiagnosisBinary DiagnosisBinary Impaired Genotype Genotype
#> 4 DiagnosisBinary DiagnosisBinary Impaired Genotype Genotype
#> 5 DiagnosisBinary DiagnosisBinary Impaired Genotype Genotype
#> 6 DiagnosisBinary DiagnosisBinary Impaired Genotype Genotype
#> 7 DiagnosisBinary DiagnosisBinary Impaired Genotype Genotype
#> 8 DiagnosisBinary DiagnosisBinary Impaired Genotype Genotype
#> # ℹ 38 more variables: PredictorLevels <int>, ResultLevel <chr>, Stratum <chr>,
#> # N <int>, NCase <int>, NControl <int>, CaseWithResult <int>,
#> # ControlWithResult <int>, CaseWithoutResult <int>,
#> # ControlWithoutResult <int>, CaseProbability <dbl>,
#> # ControlProbability <dbl>, LikelihoodRatio <dbl>, LRLowerCI <dbl>,
#> # LRUpperCI <dbl>, Log2LR <dbl>, ZeroCell <lgl>, Corrected <lgl>,
#> # Group <chr>, Term <chr>, Estimate <dbl>, ConfLow <dbl>, ConfHigh <dbl>, …
#>
#> $DiagnosticMatrixData
#> # A tibble: 16 × 14
#> Stratum Predictor PredictorLabel Outcome OutcomeLabel ResultLevel
#> <chr> <chr> <chr> <chr> <chr> <chr>
#> 1 All participants sex Sex Diagnosis… DiagnosisBi… Female
#> 2 All participants sex Sex Diagnosis… DiagnosisBi… Male
#> 3 All participants Genotype Genotype Diagnosis… DiagnosisBi… E2E2
#> 4 All participants Genotype Genotype Diagnosis… DiagnosisBi… E2E3
#> 5 All participants Genotype Genotype Diagnosis… DiagnosisBi… E2E4
#> 6 All participants Genotype Genotype Diagnosis… DiagnosisBi… E3E3
#> 7 All participants Genotype Genotype Diagnosis… DiagnosisBi… E3E4
#> 8 All participants Genotype Genotype Diagnosis… DiagnosisBi… E4E4
#> 9 All participants sex Sex Diagnosis… DiagnosisBi… Female
#> 10 All participants sex Sex Diagnosis… DiagnosisBi… Male
#> 11 All participants Genotype Genotype Diagnosis… DiagnosisBi… E2E2
#> 12 All participants Genotype Genotype Diagnosis… DiagnosisBi… E2E3
#> 13 All participants Genotype Genotype Diagnosis… DiagnosisBi… E2E4
#> 14 All participants Genotype Genotype Diagnosis… DiagnosisBi… E3E3
#> 15 All participants Genotype Genotype Diagnosis… DiagnosisBi… E3E4
#> 16 All participants Genotype Genotype Diagnosis… DiagnosisBi… E4E4
#> # ℹ 8 more variables: OutcomeCondition <chr>, Count <int>, Denominator <int>,
#> # Probability <dbl>, CellLabel <chr>, MatrixRow <chr>, MatrixRowLabel <chr>,
#> # HoverText <chr>
#>