R – How to Create Tables Before and After IPTW with Frequencies in R

propensity-scoresrweighted-dataweights

I am doing propensity score weighting with the package "Weightit" and I want to have a Table 1 "Before and After Weighting" like this one:

enter image description here

As you can see, data are displayed EITHER as MEANĀ±SD or frequency(percentage) depending whether the variable is continous or categorical.
I want to do the same thing. This is my code:

data("lalonde", package = "cobalt")
library(cobalt)
library(WeightIt)

W.out <- weightit(treat ~ age + educ + race + married + nodegree + re74 + re75,
                  data = lalonde, estimand = "ATT", method = "ps")
W.out

bal.tab(W.out, stats = c("m", "v"), thresholds = c(m = .05), disp=c("means", "sds"))

However, by using bal.tab from cobalt package the problem is that it only shows means (SD) and DOESN'T SHOW frequency(percentage) for categorical variables as I want to. How can I overcome this problem? I can also use another package both for IPTW and for creating tables. I just want to perform IPTW and create a table before and after.

Best Answer

It's kind of hard to talk about frequencies with weights. Let's say there are two units, one with the condition and one without. The frequency of the condition is 1 and the rate is 50%. But now let's give the unit with the condition a weight of .75 and the other unit a weight of .25. What is the frequency of the event? It's clear the weighted rate of the event is 75%. But what is the frequency? Is it .75? That doesn't make much sense because that would indicate the frequency decreased even though the unit with the condition received a higher weight. Is it 1? That doesn't make much sense because it ignores the weights, though it does reflect that only one unit, however they are weighted, has the condition. Is it 1.5? That also doesn't make much sense because it doesn't really make sense to talk about a frequency that isn't a whole number. So what number should be produced?

My intuition says don't report weighted frequencies. Just report weighted rates. It's the rates are are more meaningful when assessing covariate balance or generalizability to other population anyway. The frequency is a function of the rate and the sample size, but the sample size is incidental. A frequency of 100 doesn't tell you whether the condition is rare or common (it would be rare in a sample size of 1,000,000 but common in a sample size of 150). Only the rate does.

If you are absolutely desperate to report a frequency, multiply the weighted rate by the sample size. That will still leave you with a fractional number that doesn't make much sense, but at least it's close to what you probably want.

Related Question