plot_preference: Visualize Preference

View source: R/ability_preference.R

plot_preferenceR Documentation

Visualize Preference

Description

Compute the difference in risk between AI and human decision makers using AIPW estimators over a set of loss ratios, and then visualize when we prefer human over AI decision makers. Generate a plot based on the overall and subgroup-specific results.

Usage

plot_preference(
  Y,
  D,
  Z,
  V = NULL,
  A,
  z_compare = 0,
  true.pscore = NULL,
  nuis_funcs = NULL,
  nuis_funcs_ai = NULL,
  l01_seq = 10^seq(-2, 2, length.out = 100),
  alpha = 0.05,
  subgroup1,
  subgroup2,
  label.subgroup1 = "Subgroup 1",
  label.subgroup2 = "Subgroup 2",
  x.order = NULL,
  p.title = NULL,
  legend.position = "none",
  p.label = c("AI-alone preferred", "Human-alone preferred", "Ambiguous")
)

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).

V

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

A

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

z_compare

A compare treatment indicator (numeric). Default 0.

true.pscore

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

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.

nuis_funcs_ai

output from compute_nuisance_functions_ai

l01_seq

A candidate list of ratio of the loss between false positives and false negatives. Default 10^seq(-2, 2, length.out = 100).

alpha

A significance level (numeric). Default 0.05.

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.

legend.position

Position of the legend (character).

p.label

A vector of three labels for the annotations (character). Default c("AI-alone preferred", "Human-alone preferred", "Ambiguous").

Value

A ggplot object.

Examples

plot_preference(
  Y = NCAdata$Y,
  D = ifelse(NCAdata$D == 0, 0, 1),
  Z = NCAdata$Z,
  A = PSAdata$DMF,
  z_compare = 0,
  nuis_funcs = nuis_func,
  nuis_funcs_ai = nuis_func_ai,
  true.pscore = rep(0.5, nrow(NCAdata)),
  l01_seq = 10^seq(-2, 2, length.out = 10),
  alpha = 0.05,
  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, legend.position = "none",
  p.label = c("AI-alone preferred", "Human-alone preferred", "Ambiguous")
)


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