knitr::opts_chunk$set(eval = FALSE)
WeightIt
is a wrapper for several other packages that aid in estimating balancing weights. In many ways, this is WeigthIt
's strength, because it is easy to try out several weighting methods without having to learn a completely new syntax for each one. One weakness of this is that when one of these packages is not available (e.g., on CRAN), the method that relies on that package cannot be used.
This document explains how to install each package WeightIt
uses. You do not need to install every single one; you only need the one you want to use. For example, the miseam
package provides support for logistic regression with missing data, but if you have no missing data or you don't want to use the approach implemented in miseam
, you don't need to install it. WeightIt
strongly depends on four packages, which are automatically installed along with WeightIt
, so you don't need to worry about installing them separately; these are cobalt
, ggplot2
, crayon
, and backports
.
Below we note each method (by name and by the input to the method
argument of weightit()
) and how to install the required packages either from CRAN or otherwise when the CRAN version is not available. In many cases, this involves installing the package from the author's GitHub repository, which requires either the remotes
or devtools
package, which both contain the function install_github()
.
method = "glm"
)Several options are available for estimating propensity score weights using GLMs depending on the treatment type and other features of the desired model. For binary treatments, weightit()
uses stats::glm()
by default, and for continuous treatments, weightit()
uses stats::lm()
by default, so no additional packages are required. For multi-category treatments with use.mlogit = FALSE
, weightit()
uses stats::glm()
.
missing = "saem"
For binary and continuous treatments, when missing data is present and missing = "saem"
is supplied, the misaem
package is required. To install misaem
from CRAN, run
install.packages("misaem")
If misaem
is not on CRAN, or if you want to install the development version from source, you can do so from the developer's GitHub repo using the following code:
remotes::install_github("julierennes/misaem")
link = "br.logit"
For binary and multicategory treatments, when link
is supplied as "br.logit"
or another link beginning with "br."
, the brglm2
package is required. To install brglm2
from CRAN, run
install.packages("brglm2")
If brglm2
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Ioannis Kosmidis's, GitHub repo using the following code:
remotes::install_github("ikosmidis/brglm2")
brglm2
requires compilation, which means you may need additional software installed on your computer to install it from source.
use.mlogit = TRUE
For multicategory treatments, when use.mlogit = TRUE
(the default), the mlogit
package is required for multinomial logistic regression. To install mlogit
from CRAN, run
install.packages("mlogit")
If mlogit
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Yves Croissant's, R-Forge repo using the following code:
install.packages("mlogit", repos = "http://R-Forge.R-project.org")
use.mclogit = TRUE
For multicategory treatments, when use.mclogit = TRUE
, the mclogit
package is required for multinomial logistic regression. To install mclogit
from CRAN, run
install.packages("mclogit")
If mclogit
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Martin Elff's, GitHub repo using the following code:
remotes::install_github("melff/mclogit")
link = "bayes.probit"
For multicategory treatments, when link = "bayes.probit"
, the MNP
package is required for Bayesian multinomial probit regression. To install MNP
from CRAN, run
install.packages("MNP")
If MNP
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Kosuke Imai's, GitHub repo using the following code:
remotes::install_github("kosukeimai/MNP")
MNP
requires compilation, which means you may need additional software installed on your computer to install it from source.
For multicategory ordinal treatments (i.e., where the treatment variable is an ordered factor), the MASS
package is required unless link = "br.logit"
(in which case the brglm2
package is needed; see above). MASS is a core package and can always be installed from CRAN using the code below:
install.packages("MASS")
method = "gbm"
)WeightIt
uses the R package gbm
to estimate propensity score weights using GBM. It does not rely on the twang
package at all. To install gbm
from CRAN, run
install.packages("gbm")
If gbm
is not on CRAN, or if you want to install the development version from source, you can do so from the developer's GitHub repo using the following code:
remotes::install_github("gbm-developers/gbm")
gbm
requires compilation, which means you may need additional software installed on your computer to install it from source.
method = "cbps"
and method = "npcbps"
)WeightIt
uses the R package CBPS
to perform (nonparametric) covariate balancing propensity score weighting. To install CBPS
from CRAN, run
install.packages("CBPS")
If CBPS
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Kosuke Imai's, GitHub repo using the following code:
remotes::install_github("kosukeimai/CBPS")
method = "ebal"
)WeightIt
uses code written for WeightIt
, so no additional packages need to be installed to use entropy balancing.
method = "ebcw"
)Empirical balancing calibration weighting is no longer available with WeightIt
. Use entropy balancing, which in most cases is mathematically identical.
method = "optweight"
)WeightIt
uses the R package optweight
to perform optimization-based weighting. To install optweight
from CRAN, run
install.packages("optweight")
If optweight
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Noah Greifer's (my), GitHub repo using the following code:
remotes::install_github("ngreifer/optweight")
optweight
depends on the osqp
package, which requires compilation, which means you may need additional software installed on your computer to install it from source.
method = "super"
)WeightIt
uses the R package SuperLearner
to estimate propensity score weights using SuperLearner. To install SuperLearner
from CRAN, run
install.packages("SuperLearner")
If SuperLearner
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Eric Polley's, GitHub repo using the following code:
remotes::install_github("ecpolley/SuperLearner")
SuperLearner
itself is a wrapper for many other packages. The whole point of using SuperLearner is to include many different machine learning algorithms to combine them into a well-fitting stacked model. These algorithms exist in many different R packages, which each need to be installed to use them. See the Suggested packages on the SuperLearner
CRAN page to see what packages might be used with SuperLearner
.
There are additional functions for use with SuperLearner
in the SuperLearnerExtra
repository. To read these into your R session to be used with method = "super"
, use source()
on the raw text file URL. For example, to read in the code for SL.dbarts
, run
source("https://raw.githubusercontent.com/ecpolley/SuperLearnerExtra/master/SL/SL.dbarts.R")
method = "bart"
)WeightIt
uses the R package dbarts
to estimate propensity score weights using BART. To install dbarts
from CRAN, run
install.packages("dbarts")
If dbarts
is not on CRAN, or if you want to install the development version from source, you can do so from the developer, Vincent Dorie's, GitHub repo using the following code:
remotes::install_github("vdorie/dbarts")
dbarts
requires compilation, which means you may need additional software installed on your computer to install it from source.
method = "energy"
)WeightIt
uses the R package osqp
to perform the optimization required for energy balancing. To install osqp
from CRAN, run
install.packages("osqp")
If osqp
is not on CRAN, or if you want to install the development version from source, you can do so from the developer's site using the instructions given here, though it is a bit more involved than other installations from source.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.