Skip to contents

Creates a visualization of participant retention/attrition over time using event day_offset values. Requires ggplot2 to be installed.

Usage

plot_attrition_curve(
  project,
  baseline_event = NULL,
  definition = c("any_data", "complete_form"),
  form = NULL,
  metric = c("retention_rate", "attrition_rate", "n_retained", "n_lost"),
  show_points = TRUE,
  show_labels = FALSE
)

Arguments

project

A redcap_project object, or an attrition_over_time data frame

baseline_event

Character. Name of the baseline event (if project is provided)

definition

Character. How to define retention (if project is provided)

form

Character. Form to check if definition = "complete_form" (if project is provided)

metric

Character. Which metric to plot: "retention_rate" (default), "attrition_rate", "n_retained", or "n_lost"

show_points

Logical. Whether to show points at each event (default: TRUE)

show_labels

Logical. Whether to show event labels (default: FALSE)

Value

A ggplot2 object

Examples

if (FALSE) { # \dontrun{
project <- redcap_project()

# Quick plot
plot_attrition_curve(project)

# Customize
plot_attrition_curve(project, metric = "n_retained", show_labels = TRUE)

# Or pass pre-calculated attrition data
attrition <- get_attrition_over_time(project)
plot_attrition_curve(attrition)
} # }