```
library(psborrow2)
library(cmdstanr)
```

Propensity scores (PS) methods offer various ways to adjust analyses for differences in groups of patients. Austin (2013) discusses various approaches for using PS with survival analyses to obtain effect measures similar to randomized controlled trials. Wang et al. (2021) discuss using PS for IPTW, matching and stratification in combination with a Bayesian analysis. These methods allow for the separation of the design and analysis into two stages, which may be attractive in a regulatory setting. Another approach is the direct inclusion of the PS as a covariate in the outcome model.

`WeightIt`

The `WeightIt`

package can calculate PS and other balancing weights with a number of
different methods, such as generalized boosted modeling
(`method = "gbm"`

). In addition, weights can be calculated
differently for different estimands. Here, we specifying
`estimand = "ATT"`

, to calculate weights for estimating the
average treatment effect among the treated (ATT).

```
library(WeightIt)
example_dataframe <- as.data.frame(example_matrix)
example_dataframe$int <- 1 - example_dataframe$ext
weightit_model <- weightit(
int ~ cov1 + cov2 + cov3 + cov4,
data = example_dataframe,
method = "gbm",
estimand = "ATT"
)
#> Warning: No `criterion` was provided. Using "smd.mean"FALSETRUE.
summary(weightit_model)
#> Summary of weights
#>
#> - Weight ranges:
#>
#> Min Max
#> treated 1.0000 || 1.0000
#> control 0.0826 |---------------------------| 5.8966
#>
#> - Units with the 5 most extreme weights by group:
#>
#> 5 4 3 2 1
#> treated 1 1 1 1 1
#> 195 158 465 438 371
#> control 2.7924 2.7924 5.8966 5.8966 5.8966
#>
#> - Weight statistics:
#>
#> Coef of Var MAD Entropy # Zeros
#> treated 0.000 0.00 0.0 0
#> control 1.582 0.82 0.6 0
#>
#> - Effective Sample Sizes:
#>
#> Control Treated
#> Unweighted 350. 150
#> Weighted 100.09 150
```

Another useful package is cobalt, which
provides tools for assessing balance between groups after weighting or
matching. It is compatible with many matching and weighting packages.
See the vignette
for more details. We can use the `cobalt`

package to assess
balance with `bal.plot()`

.

```
library(cobalt)
bal.plot(weightit_model)
```

“Love plots” can also be generated that compare the populations before and after weighting:

`love.plot(weightit_model, stars = "std")`