| hospital_staff | R Documentation |
A comprehensive example dataset for demonstrating couplr functionality across vignettes. Contains hospital staff scheduling data with nurses, shifts, costs, and preference scores suitable for assignment problems, as well as nurse characteristics for matching workflows.
hospital_staff
A list containing eight related datasets:
A 10x10 numeric cost matrix for assigning 10 nurses
to 10 shifts. Values range from approximately 1-15, where lower values
indicate better fit (less overtime, matches skills, respects preferences).
Use with lap_solve() for basic assignment.
A 10x10 numeric preference matrix on a 0-10 scale,
where higher values indicate stronger nurse preference for a shift.
Use with lap_solve(..., maximize = TRUE) to optimize preferences
rather than minimize costs.
A tibble with 100 rows (10 nurses x 10 shifts) in long format for data frame workflows:
Integer 1-10. Unique identifier for each nurse.
Integer 1-10. Unique identifier for each shift.
Numeric. Assignment cost (same values as basic_costs).
Numeric 0-10. Nurse preference score.
Integer 0/1. Binary indicator: 1 if nurse skills match shift requirements, 0 otherwise.
A tibble with 10 rows describing nurse characteristics:
Integer 1-10. Links to schedule_df and basic_costs rows.
Numeric 1-20. Years of nursing experience.
Character. Primary department: "ICU", "ER", "General", or "Pediatrics".
Character. Preferred shift type: "day", "evening", or "night".
Integer 1-3. Certification level where 3 is highest (e.g., 1=RN, 2=BSN, 3=MSN).
A tibble with 10 rows describing shift requirements:
Integer 1-10. Links to schedule_df and basic_costs cols.
Character. Department needing coverage.
Character. Shift type: "day", "evening", or "night".
Numeric. Minimum years of experience required.
Integer 1-3. Minimum certification level.
A tibble for batch solving with 500 rows (5 days x 10 nurses x 10 shifts):
Character. Day of week: "Mon", "Tue", "Wed", "Thu", "Fri".
Integer 1-10. Nurse identifier.
Integer 1-10. Shift identifier.
Numeric. Daily assignment cost (varies by day).
Numeric 0-10. Daily preference score.
Use with group_by(day) for solving each day's schedule.
A tibble with 200 nurses for matching examples, representing a treatment group (e.g., full-time nurses):
Integer 1-200. Unique identifier.
Numeric 22-65. Nurse age in years.
Numeric 0-40. Years of nursing experience.
Numeric 25-75. Hourly wage in dollars.
Character. Primary department assignment.
Integer 1-3. Certification level.
Logical. TRUE for full-time status.
A tibble with 300 potential control nurses (e.g., part-time or registry nurses) for matching. Same structure as nurses_extended. Designed to have systematic differences from nurses_extended (older, less experience on average) to demonstrate matching's ability to create comparable groups.
This dataset is used throughout the couplr documentation to provide a consistent, realistic example that evolves in complexity. It supports three use cases: (1) basic LAP solving with cost matrices, (2) batch solving across multiple days, and (3) matching workflows comparing nurse groups.
The dataset is designed to demonstrate progressively complex scenarios:
Basic LAP (vignette("getting-started")):
basic_costs: Simple 10x10 assignment
preferences: Maximization problem
schedule_df: Data frame input, grouped workflows
weekly_df: Batch solving across days
Algorithm comparison (vignette("algorithms")):
Use basic_costs to compare algorithm behavior
Modify with NA values for sparse scenarios
Matching workflows (vignette("matching-workflows")):
nurses_extended: Treatment group (full-time nurses)
controls_extended: Control pool (part-time/registry nurses)
Match on age, experience, department for causal analysis
lap_solve for basic assignment solving,
lap_solve_batch for batch solving,
match_couples for matching workflows,
vignette("getting-started") for introductory tutorial
# Basic assignment: assign nurses to shifts minimizing cost
lap_solve(hospital_staff$basic_costs)
# Maximize preferences instead
lap_solve(hospital_staff$preferences, maximize = TRUE)
# Data frame workflow
library(dplyr)
hospital_staff$schedule_df |>
lap_solve(nurse_id, shift_id, cost)
# Batch solve weekly schedule
hospital_staff$weekly_df |>
group_by(day) |>
lap_solve(nurse_id, shift_id, cost)
# Matching workflow: match full-time to part-time nurses
match_couples(
left = hospital_staff$nurses_extended,
right = hospital_staff$controls_extended,
vars = c("age", "experience_years", "certification_level"),
auto_scale = TRUE
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.