Skip to content

Commit 29e2f74

Browse files
committed
Typo fixes
1 parent 6737e0f commit 29e2f74

File tree

8 files changed

+89
-85
lines changed

8 files changed

+89
-85
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: WeightIt
22
Type: Package
33
Title: Weighting for Covariate Balance in Observational Studies
4-
Version: 1.4.0.9000
4+
Version: 1.4.0.9001
55
Authors@R: c(
66
person("Noah", "Greifer", role=c("aut", "cre"),
77
email = "[email protected]",

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ WeightIt News and Updates
55

66
* Fixed a bug in which the output of `bread()` was off by a factor of -1. This doesn't affect its use in `sandwich::sandwich()`.
77

8+
* Typo fixes in vignettes and documentation.
9+
810
# `WeightIt` 1.4.0
911

1012
* Entropy balancing works slightly differently when sampling weights are supplied. The negative entropy between the estimated weights and the product of the sampling weights and base weights (if any) is now the quantity minimized in the optimization. Previously, the negative entropy between the product of the sampling weights and estimated weights and the base weights was minimized. The new behavior ensures entropy balancing is consistent with mathematically equivalent methods when it ought to be (i.e., CBPS and IPT for the ATT) and prevents counter-intuitive results, like that the ESS after weighting could be larger than that before weighting. Note this will cause results to differ between this and previous versions of `WeightIt`.

README.Rmd

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ knitr::opts_chunk$set(
2626

2727
For a complete vignette, see the [website](https://ngreifer.github.io/WeightIt/articles/WeightIt.html) for *WeightIt* or `vignette("WeightIt")`.
2828

29-
To install and load *WeightIt* , use the code below:
29+
To install and load *WeightIt*, use the code below:
3030

3131
```{r, eval = FALSE}
3232
#CRAN version
@@ -67,7 +67,7 @@ For the second goal, qualities of the distributions of weights can be assessed u
6767
summary(W)
6868
```
6969

70-
Desirable qualities include large effective sample sizes, which imply low variability in the weights (and therefore increased precision in estimating the treatment effect).
70+
Large effective sample sizes imply low variability in the weights, and therefore increased precision in estimating the treatment effect.
7171

7272
Finally, we can estimate the effect of the treatment using a weighted outcome model, accounting for estimation of the weights in the standard error of the effect estimate:
7373

@@ -78,7 +78,7 @@ fit <- lm_weightit(re78 ~ treat, data = lalonde,
7878
summary(fit, ci = TRUE)
7979
```
8080

81-
The tables below contains the available methods in *WeightIt* for estimating weights for binary, multi-category, and continuous treatments. Many of these methods do not require any other package to use; see `vignette("installing-packages")` for information on how to install packages that are used.
81+
The tables below contain the available methods in *WeightIt* for estimating weights for binary, multi-category, and continuous treatments. Some of these methods require installing other packages to use; see `vignette("installing-packages")` for information on how to install them.
8282

8383
#### Binary Treatments
8484

@@ -124,7 +124,7 @@ The tables below contains the available methods in *WeightIt* for estimating wei
124124
Bayesian additive regression trees GPS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html)
125125
Distance covariance optimal weighting | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html)
126126

127-
In addition, *WeightIt* implements the subgroup balancing propensity score using the function `sbps()`. Several other tools and utilities are available, including `trim()` to trim or truncate weights, `calibrate()` to calibrate propensity scores, `get_w_from_ps()` to compute weights from propensity scores.
127+
In addition, *WeightIt* implements the subgroup balancing propensity score using the function `sbps()`. Several other tools and utilities are available, including `trim()` to trim or truncate weights, `calibrate()` to calibrate propensity scores, and `get_w_from_ps()` to compute weights from propensity scores.
128128

129129
*WeightIt* provides functions to fit weighted models that account for the uncertainty in estimating the weights. These include `glm_weightit()` for fitting generalized linear models, `ordinal_weightit()` for ordinal regression models, `multinom_weightit()` for multinomial regression models, and `coxph_weightit()` for Cox proportional hazards models. Several methods are available for computing the parameter variances, including asymptotically correct M-estimation-based variances, robust variances that treat the weights as fixed, and traditional and fractional weighted bootstrap variances. Clustered variances are supported. See `vignette("estimating-effects")` for information on how to use these after weighting to estimate treatment effects.
130130

README.md

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ For a complete vignette, see the
2525
[website](https://ngreifer.github.io/WeightIt/articles/WeightIt.html)
2626
for *WeightIt* or `vignette("WeightIt")`.
2727

28-
To install and load *WeightIt* , use the code below:
28+
To install and load *WeightIt*, use the code below:
2929

3030
``` r
3131
#CRAN version
@@ -125,9 +125,8 @@ summary(W)
125125
#> Unweighted 429. 185
126126
#> Weighted 99.82 185
127127

128-
Desirable qualities include large effective sample sizes, which imply
129-
low variability in the weights (and therefore increased precision in
130-
estimating the treatment effect).
128+
Large effective sample sizes imply low variability in the weights, and
129+
therefore increased precision in estimating the treatment effect.
131130

132131
Finally, we can estimate the effect of the treatment using a weighted
133132
outcome model, accounting for estimation of the weights in the standard
@@ -150,11 +149,11 @@ summary(fit, ci = TRUE)
150149
#> treat 1214.1 798.2 1.521 0.128 -350.3 2778.4
151150
#> Standard error: HC0 robust (adjusted for estimation of weights)
152151

153-
The tables below contains the available methods in *WeightIt* for
152+
The tables below contain the available methods in *WeightIt* for
154153
estimating weights for binary, multi-category, and continuous
155-
treatments. Many of these methods do not require any other package to
154+
treatments. Some of these methods require installing other packages to
156155
use; see `vignette("installing-packages")` for information on how to
157-
install packages that are used.
156+
install them.
158157

159158
#### Binary Treatments
160159

@@ -203,7 +202,7 @@ install packages that are used.
203202
In addition, *WeightIt* implements the subgroup balancing propensity
204203
score using the function `sbps()`. Several other tools and utilities are
205204
available, including `trim()` to trim or truncate weights, `calibrate()`
206-
to calibrate propensity scores, `get_w_from_ps()` to compute weights
205+
to calibrate propensity scores, and `get_w_from_ps()` to compute weights
207206
from propensity scores.
208207

209208
*WeightIt* provides functions to fit weighted models that account for

vignettes/WeightIt.Rmd

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,21 @@ set.seed(1000)
2525

2626
## Introduction
2727

28-
`WeightIt` contains several functions for estimating and assessing balancing weights for observational studies. These weights can be used to estimate the causal parameters of marginal structural models. I will not go into the basics of causal inference methods here. For good introductory articles, see @austinIntroductionPropensityScore2011, @austinMovingBestPractice2015, @robinsMarginalStructuralModels2000, or @thoemmesPrimerInverseProbability2016.
28+
*WeightIt* contains several functions for estimating and assessing balancing weights for observational studies. These weights can be used to estimate the causal parameters of marginal structural models. I will not go into the basics of causal inference methods here. For good introductory articles, see @austinIntroductionPropensityScore2011, @austinMovingBestPractice2015, @robinsMarginalStructuralModels2000, or @thoemmesPrimerInverseProbability2016.
2929

30-
Typically, the analysis of an observation study might proceed as follows: identify the covariates for which balance is required; assess the quality of the data available, including missingness and measurement error; estimate weights that balance the covariates adequately; and estimate a treatment effect and corresponding standard error or confidence interval. This guide will go through all these steps for two observational studies: estimating the causal effect of a point treatment on an outcome, and estimating the causal parameters of a marginal structural model with multiple treatment periods. This is not meant to be a definitive guide, but rather an introduction to the relevant issues.
30+
Typically, the analysis of an observational study might proceed as follows: identify the covariates for which balance is required; assess the quality of the data available, including missingness and measurement error; estimate weights that balance the covariates adequately; and estimate a treatment effect and corresponding standard error or confidence interval. This guide will go through these steps for two observational studies: estimating the causal effect of a point treatment on an outcome, and estimating the causal parameters of a marginal structural model with multiple treatment periods. This is not meant to be a definitive guide, but rather an introduction to the relevant issues.
3131

3232
## Balancing Weights for a Point Treatment
3333

34-
First we will use the Lalonde dataset to estimate the effect of a point treatment. We'll use the version of the data set that resides within the `cobalt` package, which we will use later on as well. Here, we are interested in the average treatment effect on the treated (ATT).
34+
First we will use the Lalonde dataset to estimate the effect of a point treatment. We'll use the version of the data set that comes with the *cobalt* package, which we will use later on as well. Here, we are interested in the average treatment effect on the treated (ATT).
3535

3636
```{r}
3737
library("cobalt")
3838
data("lalonde", package = "cobalt")
3939
head(lalonde)
4040
```
4141

42-
We have our outcome (`re78`), our treatment (`treat`), and the covariates for which balance is desired (`age`, `educ`, `race`, `married`, `nodegree`, `re74`, and `re75`). Using `cobalt`, we can examine the initial imbalance on the covariates:
42+
We have our outcome (`re78`), our treatment (`treat`), and the covariates for which balance is desired (`age`, `educ`, `race`, `married`, `nodegree`, `re74`, and `re75`). Using *cobalt*, we can examine the initial imbalance on the covariates:
4343

4444
```{r}
4545
bal.tab(treat ~ age + educ + race + married + nodegree + re74 + re75,
@@ -48,7 +48,7 @@ bal.tab(treat ~ age + educ + race + married + nodegree + re74 + re75,
4848

4949
Based on this output, we can see that all variables are imbalanced in the sense that the standardized mean differences (for continuous variables) and differences in proportion (for binary variables) are greater than .05 for all variables. In particular, `re74` and `re75` are quite imbalanced, which is troubling given that they are likely strong predictors of the outcome. We will estimate weights using `weightit()` to try to attain balance on these covariates.
5050

51-
First, we'll start simple, and use inverse probability weights from propensity scores generated through logistic regression. We need to supply `weightit()` with the formula for the model, the data set, the estimand (ATT), and the method of estimation (`"glm"`) for generalized linear model propensity score weights).
51+
First, we'll start simple, and use inverse probability weights from propensity scores generated through logistic regression. We need to supply `weightit()` with the formula for the model, the data set, the estimand (ATT), and the method of estimation (`"glm"` for generalized linear model propensity score weights).
5252

5353
```{r}
5454
library("WeightIt")
@@ -57,7 +57,7 @@ W.out <- weightit(treat ~ age + educ + race + married + nodegree + re74 + re75,
5757
W.out #print the output
5858
```
5959

60-
Printing the output of `weightit()` displays a summary of how the weights were estimated. Let's examine the quality of the weights using `summary()`. Weights with low variability are desirable because they improve the precision of the estimator. This variability is presented in several ways: by the ratio of the largest weight to the smallest in each group, the coefficient of variation (standard deviation divided by the mean) of the weights in each group, and the effective sample size computed from the weights. We want a small ratio, a smaller coefficient of variation, and a large effective sample size (ESS). What constitutes these values is mostly relative, though, and must be balanced with other constraints, including covariate balance. These metrics are best used when comparing weighting methods, but the ESS can give a sense of how much information remains in the weighted sample on a familiar scale.
60+
Printing the output of `weightit()` displays a summary of how the weights were estimated. Let's examine the quality of the weights using `summary()`. Weights with low variability are desirable because they improve the precision of the estimator. This variability is presented in several ways, but the most important is the effective sample size (ESS) computed from the weights, which we hope is as close to the original sample size as possible. What constitutes a "large enough" ESS is mostly relative, though, and must be considered with respect other constraints, including covariate balance.
6161

6262
```{r}
6363
summary(W.out)
@@ -69,7 +69,7 @@ These weights have quite high variability, and yield an ESS of close to 100 in t
6969
bal.tab(W.out, stats = c("m", "v"), thresholds = c(m = .05))
7070
```
7171

72-
For nearly all the covariates, these weights yielded very good balance. Only `age` remained imbalanced, with a standardized mean difference greater than .05 and a variance ratio greater than 2. Let's see if we can do better. We'll choose a different method: entropy balancing [@hainmuellerEntropyBalancingCausal2012], which guarantees perfect balance on specified moments of the covariates while minimizing the entropy (a measure of dispersion) of the weights.
72+
For nearly all the covariates, these weights yielded very good balance. Only `age` remained imbalanced, with a standardized mean difference greater than .05 and a variance ratio greater than 2. Let's see if we can do better. We'll choose a different method: entropy balancing [@hainmuellerEntropyBalancingCausal2012], which guarantees perfect balance on specified moments of the covariates while minimizing the negative entropy (a measure of dispersion) of the weights.
7373

7474
```{r}
7575
W.out <- weightit(treat ~ age + educ + race + married + nodegree + re74 + re75,
@@ -85,7 +85,7 @@ bal.tab(W.out, stats = c("m", "v"), thresholds = c(m = .05))
8585

8686
Indeed, we have achieved perfect balance on the means of the covariates. However, the variance ratio of `age` is still quite high. We could continue to try to adjust for this imbalance, but if there is reason to believe it is unlikely to affect the outcome, it may be best to leave it as is. (You can try adding `I(age^2)` to the formula and see what changes this causes.)
8787

88-
Now that we have our weights stored in `W.out`, let's extract them and estimate our treatment effect. The functions `lm_weightit()` and `glm_weightit()` make it easy to fit (generalized) linear models that account for estimation of of the weights in their standard errors. We can then use functions in `marginaleffects` to perform g-computation to extract a treatment effect estimation from the outcome model.
88+
Now that we have our weights stored in `W.out`, let's estimate our treatment effect in the weighted sample. The functions `lm_weightit()`, `glm_weightit()`, and friends make it easy to fit (generalized) linear models that account for estimation of of the weights in their standard errors. We can then use functions in *marginaleffects* to perform g-computation to extract a treatment effect estimation from the outcome model.
8989

9090
```{r, message=FALSE}
9191
# Fit outcome model
@@ -100,11 +100,11 @@ avg_comparisons(fit, variables = "treat",
100100
newdata = subset(treat == 1))
101101
```
102102

103-
Our confidence interval for `treat` contains 0, so there isn't evidence that `treat` has an effect on `re78`. Several types of standard errors are available in `WeightIt`, including analytical standard errors that account for estimation of the weights using M-estimation, robust standard errors that treat the weights as fixed, and bootstrapping. All type are described in detail at `vignette("estimating-effects")`.
103+
Our confidence interval for `treat` contains 0, so there isn't evidence that `treat` has an effect on `re78`. Several types of standard errors are available in *WeightIt*, including analytical standard errors that account for estimation of the weights using M-estimation, robust standard errors that treat the weights as fixed, and bootstrapping. All type are described in detail at `vignette("estimating-effects")`.
104104

105105
## Balancing Weights for a Longitudinal Treatment
106106

107-
`WeightIt` can estimate weights for longitudinal treatment marginal structural models as well. This time, we'll use the sample data set `msmdata` to estimate our weights. Data must be in "wide" format, with one row per unit.
107+
*WeightIt* can estimate weights marginal structural models with longitudinal treatment as well. This time, we'll use the sample data set `msmdata` to estimate our weights. Data must be in "wide" format, with one row per unit.
108108

109109
```{r}
110110
data("msmdata")
@@ -113,7 +113,7 @@ head(msmdata)
113113

114114
We have a binary outcome variable (`Y_B`), pre-treatment time-varying variables (`X1_0` and `X2_0`, measured before the first treatment, `X1_1` and `X2_1` measured between the first and second treatments, and `X1_2` and `X2_2` measured between the second and third treatments), and three time-varying binary treatment variables (`A_1`, `A_2`, and `A_3`). We are interested in the joint, unique, causal effects of each treatment period on the outcome. At each treatment time point, we need to achieve balance on all variables measured prior to that treatment, including previous treatments.
115115

116-
Using `cobalt`, we can examine the initial imbalance at each time point and overall:
116+
Using *cobalt*, we can examine the initial imbalance at each time point and overall:
117117

118118
```{r}
119119
library("cobalt") #if not already attached
@@ -156,7 +156,7 @@ bal.tab(Wmsm.out, stats = c("m", "ks"),
156156

157157
By setting `which.time = .none` in `bal.tab()`, we can focus on the overall balance assessment, which displays the greatest imbalance for each covariate across time points. We can see that our estimated weights balance all covariates all time points with respect to means and KS statistics. Now we can estimate our treatment effects.
158158

159-
First, we fit a marginal structural model for the outcome using `glm()` with the weights included:
159+
First, we fit a marginal structural model for the outcome using `glm_weightit()` with the `weightit` object supplied:
160160

161161
```{r}
162162
# Fit outcome model

0 commit comments

Comments
 (0)