plot_diff_subgroup: Visualize Difference in Risk (Human+AI v. Human) for a...

View source: R/ability_human_override.R

plot_diff_subgroupR Documentation

Visualize Difference in Risk (Human+AI v. Human) for a Subgroup Defined by AI Recommendation

Description

Visualize the the difference in risk between human+AI and human decision makers using AIPW estimators, for a subgroup defined by AI recommendation. Generate a plot based on the overall agreement and subgroup-specific agreement.

Usage

plot_diff_subgroup(
  Y,
  D,
  Z,
  A,
  a = 1,
  V = NULL,
  l01 = l01,
  nuis_funcs = NULL,
  true.pscore = NULL,
  subgroup1,
  subgroup2,
  label.subgroup1 = "Subgroup 1",
  label.subgroup2 = "Subgroup 2",
  x.order = NULL,
  p.title = NULL,
  p.lb = -1,
  p.ub = 1,
  y.lab = "Impact of PSA",
  p.label = c("Human correct", "PSA correct"),
  label = "TNP - FNP",
  metrics = c("Misclassification Rate", "False Negative Proportion",
    "False Positive Proportion")
)

Arguments

Y

An observed outcome (binary: numeric vector of 0 or 1).

D

An observed decision (binary: numeric vector of 0 or 1).

Z

A treatment indicator (binary: numeric vector of 0 or 1).

A

An AI recommendation (binary: numeric vector of 0 or 1).

a

A specific AI recommendation value to create the subset (numeric: 0 or 1).

V

A matrix of pretreatment covariates (numeric matrix). Optional.

l01

Ratio of the loss between false positives and false negatives. Default 1.

nuis_funcs

output from compute_nuisance_functions. If NULL, the function will compute the nuisance functions using the provided data. Note that V must be provided if nuis_funcs is NULL.

true.pscore

A vector of true propensity scores (numeric), if available. Optional.

subgroup1

A pretreatment covariate used for subgroup analysis (vector).

subgroup2

A pretreatment covariate used for subgroup analysis (vector).

label.subgroup1

A label for subgroup1 (character). Default "Subgroup 1".

label.subgroup2

A label for subgroup2 (character). Default "Subgroup 2".

x.order

An order for the x-axis (character vector). Default NULL.

p.title

A title for the plot (character). Default NULL.

p.lb

A lower bound for the y-axis (numeric). Default -1.

p.ub

An upper bound for the y-axis (numeric). Default 1.

y.lab

A label for the y-axis (character). Default "Impact of PSA".

p.label

A vector of two labels for the annotations (character). Default c("Human correct", "PSA correct").

label

A label for the plot (character). Default "TNP - FNP".

metrics

A vector of metrics to include in the plot (character). Default c("Misclassification Rate", "False Negative Proportion", "False Positive Proportion").

Value

A ggplot object.

Examples

plot_diff_subgroup(
  Y = NCAdata$Y,
  D = ifelse(NCAdata$D == 0, 0, 1),
  Z = NCAdata$Z,
  A = PSAdata$DMF,
  a = 1,
  l01 = 1,
  nuis_funcs = nuis_func,
  true.pscore = rep(0.5, nrow(NCAdata)),
  subgroup1 = ifelse(NCAdata$White == 1, "White", "Non-white"),
  subgroup2 = ifelse(NCAdata$Sex == 1, "Male", "Female"),
  label.subgroup1 = "Race",
  label.subgroup2 = "Gender",
  x.order = c("Overall", "Non-white", "White", "Female", "Male"),
  p.title = NULL, p.lb = -0.5, p.ub = 0.5,
  label = "TNP - FNP",
  metrics = c("True Negative Proportion (TNP)", "False Negative Proportion (FNP)", "TNP - FNP")
)


aihuman documentation built on April 12, 2025, 1:47 a.m.