## ----setup, include = FALSE---------------------------------------------------
knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = requireNamespace("MatchIt", quietly = TRUE) &&
    requireNamespace("ranger", quietly = TRUE) &&
    requireNamespace("rpart", quietly = TRUE) &&
    requireNamespace("xgboost", quietly = TRUE)
)

## ----eval = FALSE-------------------------------------------------------------
# # install.packages("remotes")
# remotes::install_github("kabajiro/psAve")

## ----message = FALSE----------------------------------------------------------
library(psAve)
data("lalonde", package = "MatchIt")

## -----------------------------------------------------------------------------
set.seed(1234)
fit <- psave(treat ~ age + educ + race + married + nodegree + re74 + re75,
             data = lalonde, outcome = ~ re78)

## -----------------------------------------------------------------------------
fit

## ----eval = FALSE-------------------------------------------------------------
# m <- MatchIt::matchit(treat ~ age + educ + race + married + nodegree + re74 + re75,
#                       data = lalonde, distance = fit$ps,
#                       method = "nearest", caliper = .2)

## -----------------------------------------------------------------------------
m <- psave_match(fit, method = "nearest", caliper = .2)
m

## -----------------------------------------------------------------------------
cobalt::bal.tab(m, distance = data.frame(prog = fit$prog))

## -----------------------------------------------------------------------------
cobalt::bal.tab(fit)

## -----------------------------------------------------------------------------
summary(fit)

## ----fig.width = 7, fig.height = 5--------------------------------------------
plot(fit, type = "balance")

## ----fig.width = 7, fig.height = 5--------------------------------------------
plot(fit, type = "distribution")

## ----fig.width = 7, fig.height = 5--------------------------------------------
plot(fit, type = "criterion")

