Description Usage Arguments Value Note Examples
View source: R/ps_match_strata.R
This function perfroms propensity score matching of two or more strata.
It could be used when arm1 has 2 or more strata, while strata information is unknown in arm2.
The function will fit a logistic regression (when 2 classes) or multinomial logistic
regression (when > 2 classes) based on strata labels in arm1 (model: label~features), then
predict strata labels in both arm1 and arm2 based on the fitted model.
The predicted probability of being stratum X will be used for propensity score matching.
The matching results will then be used to estimate treatment difference of two arms (Hazard ratio
for survival endpoint; response rate difference for binary endpoint). When ties are allowed,
weights from the ties will be used to calculate the HR or response rate difference.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
data.in |
( |
formula |
( |
indicator.var |
( |
ties |
(
|
class.of.int |
( |
tte |
( |
event |
( |
trt |
( |
response |
( |
caliper |
A scalar or vector denoting the caliper(s) which
should be used when matching. A caliper is the distance which is
acceptable for any match. Observations which are outside of the
caliper are dropped. If a scalar caliper is provided, this caliper is
used for all covariates in |
model |
(
|
weights |
( |
multinom.maxit |
see parameter |
return.data |
( |
return a list
containing the following components:
stat a matrix
with rows as strata and columns as Estimate and CIs.
converged logical
to indicate whether model converges.
any_warning_glm logical
to indicate whether there's warning from glm model.
warning.msg a list
to capture any warning message from the modeling process.
models a list
to capture the glm model results.
roc.list a list
to capture information about Area under the curve from glm model.
data a data.frame
which is the original input data plus predicted probabilities.
Different from the original version, iter is no longer a parameter
if tie = FALSE
is specified, user need to run for loops of sapply outside of this function
to get results from multiple seeds.
Three elements in the output list - the data element is a data frame that contains input data and
estimated probabilities. The stat element contains estimated treatment difference between 2 arms, in each of the strata of interest.
The converge element indicates whether the model converged (taking from $converged from glm and $convergency from multinom)
if return.data is FALSE
, data won't be returned.
model = "wri" is not supported in ps_match_strata
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
library(dplyr)
# example 1: Impute NA as one stratum in experimental arm; default model
clinical_1 <- clinical %>% mutate(
indicator = case_when(
STRATUM == "strata_1" ~ 0,
STRATUM == "strata_2" ~ 1,
is.na(STRATUM) & ARM == "experimental" ~ 1,
TRUE ~ -1
),
ARM = factor(ARM, levels = c("control","experimental")),
BNLR = case_when(
is.na(BNLR) ~ median(BNLR, na.rm = TRUE),
TRUE ~ BNLR
)
)
ps_res1 <- ps_match_strata(
data.in = clinical_1, formula = indicator ~ BECOG + SEX + BNLR,
indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
class.of.int = list("strata_1" = 1, "strata_2" = 0)
)
## Weighted HRs
ps_res1$stat
# example 2: "doubly weighted control" model
clinical_2 <- clinical %>% mutate(
indicator = case_when(
STRATUM == "strata_1" ~ 0,
STRATUM == "strata_2" ~ 1,
is.na(STRATUM) & ARM == "experimental" ~ 2,
TRUE ~ -1
),
ARM = factor(ARM, levels = c("control","experimental")),
BNLR = case_when(
is.na(BNLR) ~ median(BNLR, na.rm = TRUE),
TRUE ~ BNLR
)
)
ps_res2 <- ps_match_strata(
data.in = clinical_2, formula = indicator ~ BECOG + SEX + BNLR, model = "dwc",
indicator.var = "indicator", tte = "OS_MONTH", event = "OS_EVENT", trt = "ARM",
class.of.int = list("strata_1" = 0, "strata_2" = 1, "missing" = 2)
)
ps_res2$stat
ps_res2$converged
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.