Skip to content

Commit

Permalink
Cleaning and updates
Browse files Browse the repository at this point in the history
  • Loading branch information
ngreifer committed Oct 3, 2024
1 parent 62e040b commit 674ffb0
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 59 deletions.
3 changes: 2 additions & 1 deletion R/glm_weightit-methods.R
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#' @param thresholds `logical`; whether to include thresholds in the `summary()` output for `ordinal_weightit` objects. Default is `TRUE`.
#' @param vcov either a string indicating the method used to compute the variance of the estimated parameters for `object`, a function used to extract the variance, or the variance matrix itself. Default is to use the variance matrix already present in `object`. If a string or function, arguments passed to `...` are supplied to the method or function. (Note: for `vcov()`, can also be supplied as `type`.)
#' @param complete `logical`; whether the full variance-covariance matrix should be returned also in case of an over-determined system where some coefficients are undefined and `coef(.)` contains `NA`s correspondingly. When `complete = TRUE`, `vcov()` is compatible with `coef()` also in this singular case.
#' @param formula. changes to the model formula, passed to the `new` argument of [udpdate.formula()].
#' @param formula. changes to the model formula, passed to the `new` argument of [update.formula()].
#' @param \dots for `vcov()` or `summary()` or `confint()` with `vcov` supplied, other arguments used to compute the variance matrix depending on the method supplied to `vcov`, e.g., `cluster`, `R`, or `fwb.args`. For `update()`, additional arguments to the call or arguments with changed values. See [glm_weightit()] for details.
#' @param evaluate whether to evaluate the call (`TRUE`, the default) or just return it.
#'
Expand Down Expand Up @@ -714,6 +714,7 @@ update.glm_weightit <- function(object, formula. = NULL, ..., evaluate = TRUE) {
object
}

#Note: the following need to be fun.foo <- fun.bar for environment reasons
#' @exportS3Method stats::update multinom_weightit
update.multinom_weightit <- update.glm_weightit

Expand Down
4 changes: 2 additions & 2 deletions R/multinom_weightit.R
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@
maxit = 1e3,
reltol = 1e-12)

control <- modifyList(control,
dots[intersect(names(dots), c("trace", "maxit", "reltol", "ndeps", "REPORT"))])
control <- utils::modifyList(control,
dots[intersect(names(dots), c("trace", "maxit", "reltol", "ndeps", "REPORT"))])

out <- optim(par = start[!aliased_B],
ll,
Expand Down
4 changes: 2 additions & 2 deletions R/ordinal_weightit.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@
maxit = 1e3,
reltol = 1e-12)

control <- modifyList(control,
dots[intersect(names(dots), c("trace", "maxit", "reltol", "ndeps", "REPORT"))])
control <- utils::modifyList(control,
dots[intersect(names(dots), c("trace", "maxit", "reltol", "ndeps", "REPORT"))])

# Estimate using cumsum parameterization to get estimates
out0 <- optim(par = start,
Expand Down
11 changes: 4 additions & 7 deletions README.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,9 @@ knitr::opts_chunk$set(
```
# WeightIt: Weighting for Covariate Balance in Observational Studies <img src="man/figures/logo.png" align="right" width="150"/>

<!-- badges: start -->
[![CRAN status](https://www.r-pkg.org/badges/version/WeightIt?color=00622B)](https://CRAN.R-project.org/package=WeightIt)
[![CRAN_Downloads_Badge](https://cranlogs.r-pkg.org/badges/WeightIt?color=00622B)](https://cran.r-project.org/package=WeightIt)
<!-- badges: end -->

------
### Overview

*WeightIt* is a one-stop package to generate balancing weights for point and longitudinal treatments in observational studies. Support is included for binary, multi-category, and continuous treatments, a variety of estimands including the ATE, ATT, ATC, ATO, and others, and support for a wide variety of weighting methods, including those that rely on parametric modeling, machine learning, or optimization. *WeightIt* also provides functionality for fitting regression models in weighted samples that account for estimation of the weights in quantifying uncertainty. *WeightIt* uses a familiar formula interface and is meant to complement `MatchIt` as a package that provides a unified interface to basic and advanced weighting methods.
Expand All @@ -33,10 +30,10 @@ To install and load *WeightIt* , use the code below:

```{r, eval = FALSE}
#CRAN version
install.packages("WeightIt")
pak::pkg_install("WeightIt")
#Development version
remotes::install_github("ngreifer/WeightIt")
pak::pkg_install("ngreifer/WeightIt")
library("WeightIt")
```
Expand Down Expand Up @@ -75,8 +72,8 @@ Desirable qualities include small coefficients of variation close to 0 and large
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:

```{r}
fit <- lm_weightit(re78 ~ treat, data = lalonde,
weightit = W)
fit <- glm_weightit(re78 ~ treat, data = lalonde,
weightit = W)
summary(fit, ci = TRUE)
```
Expand Down
85 changes: 40 additions & 45 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,9 @@

# WeightIt: Weighting for Covariate Balance in Observational Studies <img src="man/figures/logo.png" align="right" width="150"/>

<!-- badges: start -->

[![CRAN
status](https://www.r-pkg.org/badges/version/WeightIt?color=00622B)](https://CRAN.R-project.org/package=WeightIt)
[![CRAN_Downloads_Badge](https://cranlogs.r-pkg.org/badges/WeightIt?color=00622B)](https://cran.r-project.org/package=WeightIt)
<!-- badges: end -->

------------------------------------------------------------------------

### Overview

Expand All @@ -34,10 +29,10 @@ To install and load *WeightIt* , use the code below:

``` r
#CRAN version
install.packages("WeightIt")
pak::pkg_install("WeightIt")

#Development version
remotes::install_github("ngreifer/WeightIt")
pak::pkg_install("ngreifer/WeightIt")

library("WeightIt")
```
Expand Down Expand Up @@ -149,9 +144,9 @@ summary(fit, ci = TRUE)
#> lm_weightit(formula = re78 ~ treat, data = lalonde, weightit = W)
#>
#> Coefficients:
#> Estimate Std. Error z value Pr(>|z|) 2.5 % 97.5 %
#> (Intercept) 5135 583.8 8.797 1.411e-18 3990.9 6279
#> treat 1214 798.2 1.521 1.282e-01 -350.3 2778
#> Estimate Std. Error z value Pr(>|z|) 2.5 % 97.5 %
#> (Intercept) 5135.1 583.8 8.797 <1e-06 3990.9 6279.2 ***
#> treat 1214.1 798.2 1.521 0.128 -350.3 2778.4
#> Standard error: HC0 robust (adjusted for estimation of weights)

The tables below contains the available methods in *WeightIt* for
Expand All @@ -162,47 +157,47 @@ install packages that are used.

#### Binary Treatments

| Method | `method` |
|---------------------------------------|--------------------------------------------------------------------------------------|
| Binary regression PS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html) |
| Generalized boosted modeling PS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html) |
| Covariate balancing PS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html) |
| Non-Parametric covariate balancing PS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html) |
| Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html) |
| Inverse probability tilting | [`"ipt"`](https://ngreifer.github.io/WeightIt/reference/method_ipt.html) |
| Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html) |
| SuperLearner PS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html) |
| Bayesian additive regression trees PS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html) |
| Energy balancing | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html) |
| Method | `method` |
|----|----|
| Binary regression PS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html) |
| Generalized boosted modeling PS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html) |
| Covariate balancing PS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html) |
| Non-Parametric covariate balancing PS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html) |
| Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html) |
| Inverse probability tilting | [`"ipt"`](https://ngreifer.github.io/WeightIt/reference/method_ipt.html) |
| Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html) |
| SuperLearner PS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html) |
| Bayesian additive regression trees PS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html) |
| Energy balancing | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html) |

#### Multi-Category Treatments

| Method | `method` |
|---------------------------------------|--------------------------------------------------------------------------------------|
| Multinomial regression PS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html) |
| Generalized boosted modeling PS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html) |
| Covariate balancing PS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html) |
| Non-Parametric covariate balancing PS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html) |
| Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html) |
| Inverse probability tilting | [`"ipt"`](https://ngreifer.github.io/WeightIt/reference/method_ipt.html) |
| Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html) |
| SuperLearner PS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html) |
| Bayesian additive regression trees PS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html) |
| Energy balancing | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html) |
| Method | `method` |
|----|----|
| Multinomial regression PS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html) |
| Generalized boosted modeling PS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html) |
| Covariate balancing PS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html) |
| Non-Parametric covariate balancing PS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html) |
| Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html) |
| Inverse probability tilting | [`"ipt"`](https://ngreifer.github.io/WeightIt/reference/method_ipt.html) |
| Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html) |
| SuperLearner PS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html) |
| Bayesian additive regression trees PS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html) |
| Energy balancing | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html) |

#### Continuous Treatments

| Method | `method` |
|----------------------------------------|--------------------------------------------------------------------------------------|
| Generalized linear model GPS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html) |
| Generalized boosted modeling GPS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html) |
| Covariate balancing GPS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html) |
| Non-Parametric covariate balancing GPS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html) |
| Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html) |
| Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html) |
| SuperLearner GPS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html) |
| Bayesian additive regression trees GPS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html) |
| Distance covariance optimal weighting | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html) |
| Method | `method` |
|----|----|
| Generalized linear model GPS | [`"glm"`](https://ngreifer.github.io/WeightIt/reference/method_glm.html) |
| Generalized boosted modeling GPS | [`"gbm"`](https://ngreifer.github.io/WeightIt/reference/method_gbm.html) |
| Covariate balancing GPS | [`"cbps"`](https://ngreifer.github.io/WeightIt/reference/method_cbps.html) |
| Non-Parametric covariate balancing GPS | [`"npcbps"`](https://ngreifer.github.io/WeightIt/reference/method_npcbps.html) |
| Entropy balancing | [`"ebal"`](https://ngreifer.github.io/WeightIt/reference/method_ebal.html) |
| Stable balancing weights | [`"optweight"`](https://ngreifer.github.io/WeightIt/reference/method_optweight.html) |
| SuperLearner GPS | [`"super"`](https://ngreifer.github.io/WeightIt/reference/method_super.html) |
| Bayesian additive regression trees GPS | [`"bart"`](https://ngreifer.github.io/WeightIt/reference/method_bart.html) |
| Distance covariance optimal weighting | [`"energy"`](https://ngreifer.github.io/WeightIt/reference/method_energy.html) |

In addition, *WeightIt* implements the subgroup balancing propensity
score using the function `sbps()`. Several other tools and utilities are
Expand Down
1 change: 1 addition & 0 deletions _pkgdown.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ reference:
- contents:
- glm_weightit
- predict.glm_weightit
- anova.glm_weightit
- glm_weightit-methods
- title: Modify weights
- contents:
Expand Down
2 changes: 1 addition & 1 deletion man/glm_weightit-methods.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/method_bart.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 674ffb0

Please sign in to comment.