The standardized (mean) difference is a measure of distance between two group means in terms of one or more variables. In practice it is often used as a balance measure of individual covariates before and after propensity score matching. As it is standardized, comparison across variables on different scales is possible. For definitions see https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3144483/#s11title.
Standardized mean differences can be easily calculated with tableone. All standardized mean differences in this package are absolute values, thus, there is no directionality.
The right heart catheterization dataset is available at https://biostat.app.vumc.org/wiki/Main/DataSets. This dataset was originally used in Connors et al. JAMA 1996;276:889-897, and has been made publicly available.
## Right heart cath dataset
rhc <- read.csv("https://biostat.app.vumc.org/wiki/pub/Main/DataSets/rhc.csv")
Error in file(file, "rt"): cannot open the connection to 'https://biostat.app.vumc.org/wiki/pub/Main/DataSets/rhc.csv'
Out of the 50 covariates, 32 have standardized mean differences of greater than 0.1, which is often considered the sign of important covariate imbalance (https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3144483/#s11title).
## Covariates
vars <- c("age","sex","race","edu","income","ninsclas","cat1","das2d3pc","dnr1",
"ca","surv2md1","aps1","scoma1","wtkilo1","temp1","meanbp1","resp1",
"hrt1","pafi1","paco21","ph1","wblc1","hema1","sod1","pot1","crea1",
"bili1","alb1","resp","card","neuro","gastr","renal","meta","hema",
"seps","trauma","ortho","cardiohx","chfhx","dementhx","psychhx",
"chrpulhx","renalhx","liverhx","gibledhx","malighx","immunhx",
"transhx","amihx")
## Construct a table
tabUnmatched <- CreateTableOne(vars = vars, strata = "swang1", data = rhc, test = FALSE)
Error: object 'rhc' not found
Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'tabUnmatched' not found
Error: object 'tabUnmatched' not found
Usually a logistic regression model is used to estimate individual propensity scores. The model here is taken from “How To Use Propensity Score Analysis”. Predicted probabilities of being assigned to right heart catheterization, being assigned no right heart catheterization, being assigned to the true assignment, as well as the smaller of the probabilities of being assigned to right heart catheterization or no right heart catheterization are calculated for later use in propensity score matching and weighting.
Error: object 'rhc' not found
## Fit model
psModel <- glm(formula = swang1 ~ age + sex + race + edu + income + ninsclas +
cat1 + das2d3pc + dnr1 + ca + surv2md1 + aps1 + scoma1 +
wtkilo1 + temp1 + meanbp1 + resp1 + hrt1 + pafi1 +
paco21 + ph1 + wblc1 + hema1 + sod1 + pot1 + crea1 +
bili1 + alb1 + resp + card + neuro + gastr + renal +
meta + hema + seps + trauma + ortho + cardiohx + chfhx +
dementhx + psychhx + chrpulhx + renalhx + liverhx + gibledhx +
malighx + immunhx + transhx + amihx,
family = binomial(link = "logit"),
data = rhc)
Error in eval(mf, parent.frame()): object 'rhc' not found
Error: object 'psModel' not found
Error: object 'rhc' not found
## Predicted probability of being assigned to the
## treatment actually assigned (either RHC or no RHC)
rhc$pAssign <- NA
Error: object 'rhc' not found
Error: object 'rhc' not found
Error: object 'rhc' not found
Error: object 'rhc' not found
The Matching package can be used for propensity score matching. The logit of the propensity score is often used as the matching scale, and the matching caliper is often 0.2 × SD(logit(PS)). See https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3144483/#s5title for suggestions. After matching, all the standardized mean differences are below 0.1.
listMatch <- Match(Tr = (rhc$swang1 == "RHC"), # Need to be in 0,1
## logit of PS,i.e., log(PS/(1-PS)) as matching scale
X = log(rhc$pRhc / rhc$pNoRhc),
## 1:1 matching
M = 1,
## caliper = 0.2 * SD(logit(PS))
caliper = 0.2,
replace = FALSE,
ties = TRUE,
version = "fast")
Error: object 'rhc' not found
Error: object 'rhc' not found
## Construct a table
tabMatched <- CreateTableOne(vars = vars, strata = "swang1", data = rhcMatched, test = FALSE)
Error: object 'rhcMatched' not found
Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'tabMatched' not found
Error: object 'tabMatched' not found
The matching weight method is a weighting analogue to the 1:1 pairwise algorithmic matching (https://pubmed.ncbi.nlm.nih.gov/23902694/). The matching weight is defined as the smaller of the predicted probabilities of receiving or not receiving the treatment over the predicted probability of being assigned to the arm the patient is actually in. After weighting, all the standardized mean differences are below 0.1. The standardized mean differences in weighted data are explained in https://pubmed.ncbi.nlm.nih.gov/26238958/.
Error: object 'rhc' not found
Error: object 'rhc' not found
## Construct a table (This is a bit slow.)
tabWeighted <- svyCreateTableOne(vars = vars, strata = "swang1", data = rhcSvy, test = FALSE)
Error: object 'rhcSvy' not found
Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'tabWeighted' not found
Error: object 'tabWeighted' not found
The overlap weight method is another alternative weighting method (https://amstat.tandfonline.com/doi/abs/10.1080/01621459.2016.1260466). After weighting, all the standardized mean differences are below 0.1.
Error: object 'rhc' not found
Error: object 'rhc' not found
## Construct a table (This is a bit slow.)
tabWeightedOw <- svyCreateTableOne(vars = vars, strata = "swang1", data = rhcSvyOw, test = FALSE)
Error: object 'rhcSvyOw' not found
Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'tabWeightedOw' not found
Error: object 'tabWeightedOw' not found
A plot showing covariate balance is often constructed to demonstrate the balancing effect of matching and/or weighting. Given the same propensity score model, the matching weight method often achieves better covariate balance than matching.
## Construct a data frame containing variable name and SMD from all methods
dataPlot <- data.frame(variable = rownames(ExtractSmd(tabUnmatched)),
Unmatched = as.numeric(ExtractSmd(tabUnmatched)),
Matched = as.numeric(ExtractSmd(tabMatched)),
Weighted = as.numeric(ExtractSmd(tabWeighted)),
WeightedOw = as.numeric(ExtractSmd(tabWeightedOw)))
Error: object 'tabUnmatched' not found
## Create long-format data for ggplot2
dataPlotMelt <- melt(data = dataPlot,
id.vars = c("variable"),
variable.name = "Method",
value.name = "SMD")
Error: object 'dataPlot' not found
## Order variable names by magnitude of SMD
varNames <- as.character(dataPlot$variable)[order(dataPlot$Unmatched)]
Error: object 'dataPlot' not found
## Order factor levels in the same order
dataPlotMelt$variable <- factor(dataPlotMelt$variable,
levels = varNames)
Error: object 'dataPlotMelt' not found
## Plot using ggplot2
ggplot(data = dataPlotMelt,
mapping = aes(x = variable, y = SMD, group = Method, color = Method)) +
geom_line() +
geom_point() +
geom_hline(yintercept = 0.1, color = "black", size = 0.1) +
coord_flip() +
theme_bw() +
theme(legend.key = element_blank())
Error: object 'dataPlotMelt' not found
To construct a side-by-side table, data can be extracted as a matrix
and combined using the print()
method, which actually
invisibly returns a matrix.
## Column bind tables
resCombo <- cbind(print(tabUnmatched, printToggle = FALSE),
print(tabMatched, printToggle = FALSE),
print(tabWeighted, printToggle = FALSE),
print(tabWeightedOw, printToggle = FALSE))
Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'tabUnmatched' not found
## Add group name row, and rewrite column names
resCombo <- rbind(Group = rep(c("No RHC","RHC"), 4), resCombo)
Error: object 'resCombo' not found
Error: object 'resCombo' not found
Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'resCombo' not found
The final analysis can be conducted using matched and weighted data.
The results from the matching and matching weight are similar. The
ShowRegTable()
function may come in handy.
## Unmatched model (unadjusted)
glmUnmatched <- glm(formula = (death == "Yes") ~ swang1,
family = binomial(link = "logit"),
data = rhc)
Error in eval(mf, parent.frame()): object 'rhc' not found
## Matched model
glmMatched <- glm(formula = (death == "Yes") ~ swang1,
family = binomial(link = "logit"),
data = rhcMatched)
Error in eval(mf, parent.frame()): object 'rhcMatched' not found
## Weighted model
glmWeighted <- svyglm(formula = (death == "Yes") ~ swang1,
family = binomial(link = "logit"),
design = rhcSvy)
Error: object 'rhcSvy' not found
## Show results together
resTogether <- list(Unmatched = ShowRegTable(glmUnmatched, printToggle = FALSE),
Matched = ShowRegTable(glmMatched, printToggle = FALSE),
Weighted = ShowRegTable(glmWeighted, printToggle = FALSE))
Error: object 'glmUnmatched' not found
Error in h(simpleError(msg, call)): error in evaluating the argument 'x' in selecting a method for function 'print': object 'resTogether' not found