Perform propensity score matching as described in Lu (2005) "Propensity Score Matching with Time-Dependent Covariates". Given a longitudinal data frame with covariate information, along with treatment time, match treated individuals to those that haven't been treated yet (or are never treated) based on time-dependent propensity scores from a Cox proportional hazards model. Each treated individual is matched to one other individual, unless the number of pairs is specified.
Usage
coxpsmatch(
n_pairs = 10^10,
data,
id = "id",
time = "time",
trt_time = "trt_time",
covariates = NULL,
exact_match = NULL,
options = list(time_lag = FALSE)
)
Arguments
- n_pairs
The number of pairs desired from matching.
- data
A data.frame or similar containing columns matching the
id, time, trt_time
arguments, and covariates. This data frame is expected to be in tidy, long format, so thatid
,trt_time
, and other variables may be repeated for different values oftime
. The data.frame should be unique atid
andtime
.- id
A character specifying the id column name (default
'id'
).- time
A character specifying the time column name (default
'time'
).- trt_time
A character specifying the treatment time column name (default
'trt_time'
).- covariates
A character vector specifying the covariates to use for matching (default
NULL
). IfNULL
, this will default to all columns except those named by theid
,time
, andtrt_time
arguments.- exact_match
A vector of optional covariates to perform exact matching on. If
NULL
, no exact matching is done.- options
A list of additional parameters with the following components:
time_lag
A logical value indicating whether the matches should be made on the time period preceding treatment. This can help avoid confounding if treatment happens between two periods.
Value
A data frame containing the pair information. The data frame has
columns id
, pair_id
, and type
. id
matches the input parameter and
will contain all ids from the input data frame. pair_id
refers to the id
of the computed pairs; NA
values indicate unmatched individuals. type
indicates whether the individual in the pair is considered as treatment ("trt") or control ("all") in that pair.
References
Lu, Bo. 2005. "Propensity Score Matching with Time-Dependent Covariates." Biometrics 61 (3): 721-28. doi:10.1111/j.1541-0420.2005.00356.x
Examples
if (requireNamespace("survival", quietly = TRUE) &
requireNamespace("nbpMatching", quietly = TRUE)) {
library(dplyr, quietly = TRUE)
pairs <- coxpsmatch(
n_pairs = 13,
data = oasis,
id = "subject_id",
time = "visit",
trt_time = "time_of_ad"
)
na.omit(pairs)
# evaluate the first match
first_match <- pairs$subject_id[which(pairs$pair_id == 1)]
oasis %>% dplyr::filter(subject_id %in% first_match)
}
#> Warning: Loglik converged before variable 7 ; beta may be infinite.
#> Warning: There must be an even number of elements
#> Adding a ghost value
#> # A tibble: 4 × 11
#> subject_id visit time_of_ad m_f educ ses age mr_delay e_tiv n_wbv asf
#> <chr> <int> <dbl> <chr> <int> <fct> <int> <int> <int> <dbl> <dbl>
#> 1 OAS2_0009 1 NA M 12 2 68 0 1457 0.806 1.20
#> 2 OAS2_0009 2 NA M 12 2 69 576 1480 0.791 1.19
#> 3 OAS2_0046 1 2 F 15 2 83 0 1476 0.75 1.19
#> 4 OAS2_0046 2 2 F 15 2 85 575 1483 0.748 1.18