
Summarize policy performance metrics for a two-stage treatment regime
policy_summary_metrics.RdComputes classification and optional value-based performance metrics for estimated treatment decisions in a two-stage dynamic treatment regime. The function compares estimated stage-1 and stage-2 treatment assignments against observed assignments and returns stage-specific as well as joint treatment-path metrics.
Usage
policy_summary_metrics(
tmpData,
estA1,
estA2,
obs1_var = "A1.var",
obs2_var = "A2.var",
eta2_var = "eta2",
Tc1_var = NULL,
Tt1_var = NULL,
Tc2_var = NULL,
Tt2_var = NULL,
Tc_total_var = NULL,
Tt_total_var = NULL,
stage = c("both", "stage1", "stage2")
)Arguments
- tmpData
A data frame containing observed treatment assignments, stage-2 eligibility indicators, and optionally outcome/value columns.
- estA1
A vector of estimated stage-1 treatment assignments. Must have length equal to
nrow(tmpData). Expected coding is-1and1.- estA2
A vector of estimated stage-2 treatment assignments. Must have length equal to
nrow(tmpData). Expected coding is-1and1.- obs1_var
Character string giving the column name in
tmpDatacontaining observed stage-1 treatment assignments. Default is"A1.var".- obs2_var
Character string giving the column name in
tmpDatacontaining observed stage-2 treatment assignments. Default is"A2.var".- eta2_var
Character string giving the column name in
tmpDataindicating whether an individual proceeds to stage 2. Subjects withtmpData[[eta2_var]] == 1are included in stage-2 and joint-path metrics. Default is"eta2".- Tc1_var
Optional character string giving the column name for the stage-1 value under control or treatment option
-1. Default isNULL.- Tt1_var
Optional character string giving the column name for the stage-1 value under treatment option
1. Default isNULL.- Tc2_var
Optional character string giving the column name for the stage-2 value under control or treatment option
-1. Default isNULL.- Tt2_var
Optional character string giving the column name for the stage-2 value under treatment option
1. Default isNULL.- Tc_total_var
Optional character string giving the column name for the total outcome/value under control or treatment option
-1. Default isNULL.- Tt_total_var
Optional character string giving the column name for the total outcome/value under treatment option
1. Default isNULL.- stage
Character string indicating which stage(s) to summarize. Must be one of
"both","stage1", or"stage2". Default is"both".
Value
A named numeric vector containing some or all of the following components:
Acc1LStage-1 accuracy.
MCC1LStage-1 Matthews correlation coefficient.
Sensitivity1LStage-1 sensitivity.
Specificity1LStage-1 specificity.
PPV1LStage-1 positive predictive value.
NPV1LStage-1 negative predictive value.
F11LStage-1 F1 score.
RMST1LOptional stage-1 value summary.
Acc2LStage-2 accuracy among subjects with
eta2 == 1.MCC2LStage-2 Matthews correlation coefficient.
Sensitivity2LStage-2 sensitivity.
Specificity2LStage-2 specificity.
PPV2LStage-2 positive predictive value.
NPV2LStage-2 negative predictive value.
F12LStage-2 F1 score.
RMST2LOptional stage-2 value summary.
AccTotalJoint-path accuracy.
MCCTotalMulticlass Matthews correlation coefficient for the joint path.
SensitivityTotalMacroMacro-averaged sensitivity across joint classes.
SpecificityTotalMacroMacro-averaged specificity across joint classes.
PPVTotalMacroMacro-averaged positive predictive value across joint classes.
NPVTotalMacroMacro-averaged negative predictive value across joint classes.
F1TotalMacroMacro-averaged F1 score across joint classes.
SensitivityTotalWtdPrevalence-weighted sensitivity across joint classes.
SpecificityTotalWtdPrevalence-weighted specificity across joint classes.
PPVTotalWtdPrevalence-weighted positive predictive value across joint classes.
NPVTotalWtdPrevalence-weighted negative predictive value across joint classes.
F1TotalWtdPrevalence-weighted F1 score across joint classes.
RMSTTotalOptional total value summary.
Details
Stage-1 and stage-2 summaries include accuracy, Matthews correlation coefficient (MCC), sensitivity, specificity, positive predictive value (PPV), negative predictive value (NPV), and F1 score. For the joint two-stage treatment path, the function additionally returns multiclass MCC together with macro-averaged and prevalence-weighted classification summaries across the four possible treatment paths.
Optional RMST-style value summaries can also be computed when corresponding outcome columns are supplied.
The function assumes binary treatment coding with values -1 and 1.
Internally, estimated and observed treatments are converted to factors with
levels c(-1, 1).
Stage-1 metrics are computed using all complete cases for the estimated and
observed stage-1 treatment assignments. Stage-2 and joint metrics are
computed only among subjects satisfying eta2 == 1.
Joint treatment paths are defined as the four-level factor
c("-1_-1", "-1_1", "1_-1", "1_1"), corresponding to the sequence of
stage-1 and stage-2 treatment assignments.
Macro-averaged metrics are calculated as the unweighted mean of class-wise statistics from the joint confusion matrix. Weighted summaries use empirical class prevalences from the observed joint treatment paths.
Optional RMST-style summaries are computed when the corresponding column
names are supplied and found in tmpData. These use an internal scoring
rule that assigns subject-level values based on the estimated treatment.
Examples
if (FALSE) { # \dontrun{
set.seed(1)
n <- 100
dat <- data.frame(
A1.var = sample(c(-1, 1), n, replace = TRUE),
A2.var = sample(c(-1, 1), n, replace = TRUE),
eta2 = sample(c(0, 1), n, replace = TRUE, prob = c(0.3, 0.7))
)
estA1 <- sample(c(-1, 1), n, replace = TRUE)
estA2 <- sample(c(-1, 1), n, replace = TRUE)
policy_summary_metrics(
tmpData = dat,
estA1 = estA1,
estA2 = estA2
)
} # }