View source: R/matching_output.R
| match_data | R Documentation |
A generic function that converts any couplr matching result into a single
analysis-ready data frame with weights, subclass, and
distance columns. This is the couplr equivalent of MatchIt's
match.data().
match_data(result, ...)
## S3 method for class 'matching_result'
match_data(result, left, right, left_id = "id", right_id = "id", ...)
## S3 method for class 'full_matching_result'
match_data(result, left, right, left_id = "id", right_id = "id", ...)
## S3 method for class 'cem_result'
match_data(result, left, right, left_id = "id", right_id = "id", ...)
## S3 method for class 'subclass_result'
match_data(result, data = NULL, ...)
result |
A couplr result object (matching_result, full_matching_result, cem_result, or subclass_result) |
... |
Additional arguments passed to methods |
left |
Data frame of left (treated) units |
right |
Data frame of right (control) units |
left_id |
Name of ID column in left (default: |
right_id |
Name of ID column in right (default: |
data |
Data frame containing all units (for CEM and subclassification, left and right are not always needed separately) |
The output format is compatible with downstream packages like cobalt,
WeightIt, and marginaleffects. The stacked (long) format with
treatment and weights columns is the standard layout expected
by these tools.
A tibble with all original variables plus standardized columns:
Unit identifier
1 for left/treated, 0 for right/control
Matching weights
Matched group/stratum identifier
Matching distance (where applicable)
set.seed(42)
left <- data.frame(id = 1:5, age = c(25, 35, 45, 55, 65))
right <- data.frame(id = 6:15, age = runif(10, 20, 70))
result <- match_couples(left, right, vars = "age")
md <- match_data(result, left, right)
head(md)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.