The MatchedDataFrame class is a subclass of both
Matched and DFrame. Therefore, it contains slots
and methods for both of these classes.
The MatchedDataFrame class uses a delegate object
during initialization to assign its DFrame slots.
MatchedDataFrame behaves as a DataFrame but also
includes additional Matched object functionality
(see ?Matched). For more information about
DataFrame see ?S4Vectors::DataFrame.
focalA DataFrame object containing the focal
data to match.
poolA DataFrame object containing the pool
from which to select matches.
delegateA DataFrame object used to initialize
DataFrame-specific slots. matchRanges() assigns
the matched set to the slot.
matchedDataA data.table with matched data
matchedIndexAn integer vector corresponding
to the indices in the pool which comprise the
matched set.
covarA character vector describing the covariates used for matching.
methodCharacter describing replacement method used for matching.
replaceTRUE/FALSE describing if matching was done with or without replacement.
rownamesrownames(delegate)
nrowsnrows(delegate)
listDataas.list(delegate)
elementTypeelementType(delegate)
elementMetadataelementMetadata(delegate)
metadatametadata(delegate)
Functions that get data from Matched subclasses (x)
such as MatchedDataFrame, MatchedGRanges,
and MatchedGInteractions are listed below:
matchedData(x): Get matched data from a Matched object
covariates(x): Get covariates from a Matched object
method(x): Get matching method used for Matched object
withReplacement(x): Get replace method
indices(x, set): Get indices of matched set
For more detail check the help pages for these functions.
Additional functions that get data from Matched subclasses
(x) such as MatchedDataFrame, MatchedGRanges,
and MatchedGInteractions include:
focal(x): Get focal set from a Matched object
pool(x): Get pool set from a Matched object
matched(x): Get matched set from a Matched object
unmatched(x): Get unmatched set from a Matched object
For more detail check the help pages for these functions.
## Constructing MatchedDataFrame with matchRanges
## data.frame
set.seed(123)
x <- makeExampleMatchedDataSet(type = "data.frame")
mx <- matchRanges(
focal = x[x$feature1, ],
pool = x[!x$feature1, ],
covar = ~ feature2 + feature3,
method = "rejection",
replace = FALSE
)
class(mx)
#> [1] "MatchedDataFrame"
#> attr(,"package")
#> [1] "nullranges"
## data.table
set.seed(123)
x <- makeExampleMatchedDataSet(type = "data.table")
mx <- matchRanges(
focal = x[x$feature1],
pool = x[!x$feature1],
covar = ~ feature2 + feature3,
method = "rejection",
replace = FALSE
)
class(mx)
#> [1] "MatchedDataFrame"
#> attr(,"package")
#> [1] "nullranges"
## DataFrame
set.seed(123)
x <- makeExampleMatchedDataSet(type = "DataFrame")
mx <- matchRanges(
focal = x[x$feature1, ],
pool = x[!x$feature1, ],
covar = ~ feature2 + feature3,
method = "rejection",
replace = FALSE
)
class(mx)
#> [1] "MatchedDataFrame"
#> attr(,"package")
#> [1] "nullranges"
## Make MatchedDataFrame example
set.seed(123)
x <- makeExampleMatchedDataSet(type = "DataFrame", matched = TRUE)
## Accessor functions for Matched class
matchedData(x)
#> Index: <set>
#> id feature2 feature3 ps set
#> <fctr> <num> <char> <num> <char>
#> 1: 1 2.879049 c 0.21095908 focal
#> 2: 1 3.539645 c 0.19210984 focal
#> 3: 1 7.117417 c 0.11193396 focal
#> 4: 1 4.141017 a 0.01771986 focal
#> 5: 1 4.258575 c 0.17308581 focal
#> ---
#> 20496: 0 1.235781 b 0.08945367 unmatched
#> 20497: 0 1.696712 a 0.02707977 unmatched
#> 20498: 0 6.111404 a 0.01255772 unmatched
#> 20499: 0 2.216575 d 0.07578989 unmatched
#> 20500: 0 5.330029 b 0.04535856 unmatched
covariates(x)
#> [1] "feature2" "feature3"
method(x)
#> [1] "rejection"
withReplacement(x)
#> [1] FALSE
head(indices(x, set = 'matched'))
#> [1] 5975 5154 9730 3514 8940 6689
## Accessor functions for Matched subclasses
focal(x)
#> DataFrame with 500 rows and 3 columns
#> feature1 feature2 feature3
#> <logical> <numeric> <character>
#> 1 TRUE 2.87905 c
#> 2 TRUE 3.53965 c
#> 3 TRUE 7.11742 c
#> 4 TRUE 4.14102 a
#> 5 TRUE 4.25858 c
#> ... ... ... ...
#> 496 TRUE 1.28384 d
#> 497 TRUE 4.36369 a
#> 498 TRUE 4.32968 b
#> 499 TRUE 4.72823 b
#> 500 TRUE 5.10432 b
pool(x)
#> DataFrame with 10000 rows and 3 columns
#> feature1 feature2 feature3
#> <logical> <numeric> <character>
#> 1 FALSE 3.28347 e
#> 2 FALSE 7.12640 a
#> 3 FALSE 1.92222 b
#> 4 FALSE 10.24116 a
#> 5 FALSE 10.17287 c
#> ... ... ... ...
#> 9996 FALSE 1.23578 b
#> 9997 FALSE 1.69671 a
#> 9998 FALSE 6.11140 a
#> 9999 FALSE 2.21657 d
#> 10000 FALSE 5.33003 b
matched(x)
#> DataFrame with 500 rows and 3 columns
#> feature1 feature2 feature3
#> <logical> <numeric> <character>
#> 1 FALSE 5.27263 c
#> 2 FALSE 10.02427 c
#> 3 FALSE 8.19732 a
#> 4 FALSE 7.83727 c
#> 5 FALSE 4.69472 c
#> ... ... ... ...
#> 496 FALSE 1.95550 a
#> 497 FALSE 4.98042 c
#> 498 FALSE 2.62560 e
#> 499 FALSE 1.40300 c
#> 500 FALSE 3.89279 b
unmatched(x)
#> DataFrame with 9500 rows and 3 columns
#> feature1 feature2 feature3
#> <logical> <numeric> <character>
#> 1 FALSE 3.28347 e
#> 2 FALSE 7.12640 a
#> 3 FALSE 1.92222 b
#> 4 FALSE 10.24116 a
#> 5 FALSE 10.17287 c
#> ... ... ... ...
#> 9496 FALSE 1.23578 b
#> 9497 FALSE 1.69671 a
#> 9498 FALSE 6.11140 a
#> 9499 FALSE 2.21657 d
#> 9500 FALSE 5.33003 b