Coerce matchit to Matched object

matchitToMatched(x, ranges = NULL, keep_mcols = TRUE)

# S4 method for class 'matchit'
matchitToMatched(x, ranges = NULL, keep_mcols = TRUE)

Arguments

x

A matchit object from MatchIt package.

ranges

A GRanges or GInteractions object that is the same length as the data used to create the matchit object, x.

keep_mcols

Logical whether to keep or existing mcols of the object supplied in ranges or not. Default is TRUE.

Value

A Matched subclass object, depending on the value of ranges. If is(ranges, "GRanges") then a MatchedGRanges object is returned. If is(ranges, "GInteractions") then a MatchedGInteractions object is returned. If is.null(ranges) then a the function first attempts to coerce into the other classes before coercing to MatchedDataFrame.

Examples

# \donttest{
if (!requireNamespace("MatchIt", quietly=TRUE)) {
 set.seed(123)
 x <- makeExampleMatchedDataSet(type="GRanges")
 
 ## Convert GRanges to data.frame, pass to matchit,
 ## and convert to MatchedGRanges object
 set.seed(123)
 mgr <- 
   as.data.frame(x) |>
   matchit(formula=feature1 ~ feature2 + feature3,
           data=_,
           method='nearest',
           replace=FALSE) |>
   matchitToMatched()
 
 ## Compatible with GRanges & Matched functions
 mgr
 plotCovariate(mgr)
} else {
 message("The 'MatchIt' package is required to run this example.")
}
#> The 'MatchIt' package is required to run this example.
# }