Learn R Programming

twang (version 2.6.1)

iptw: Inverse probability of treatment weighting for marginal structural models.

Description

iptw calculates propensity scores for sequential treatments using gradient boosted logistic regression and diagnoses the resulting propensity scores using a variety of methods

Usage

iptw(
  formula,
  data,
  timeInvariant = NULL,
  cumulative = TRUE,
  timeIndicators = NULL,
  ID = NULL,
  priorTreatment = TRUE,
  n.trees = 10000,
  interaction.depth = 3,
  shrinkage = 0.01,
  bag.fraction = 1,
  n.minobsinnode = 10,
  perm.test.iters = 0,
  print.level = 2,
  verbose = TRUE,
  stop.method = c("es.max"),
  sampw = NULL,
  version = "gbm",
  ks.exact = NULL,
  n.keep = 1,
  n.grid = 25,
  ...
)

Value

Returns an object of class iptw, a list containing

psList

A list of ps objects with length equal to the number of time periods.

estimand

The specified estimand.

stop.methods

The stopping rules used to optimize iptw balance.

nFits

The number of ps objects (i.e., the number of distinct time points).

uniqueTimes

The unique times in the specified model.

Arguments

formula

Either a single formula (long format) or a list with formulas.

data

The dataset, includes treatment assignment as well as covariates.

timeInvariant

An optional formula (with no left-hand variable) specifying time-invariant chararacteristics.

cumulative

If TRUE, the time t model includes time-varying characteristics from times 1 through t-1. Default: TRUE.

timeIndicators

For long format fits, a vector of times for each observation.

ID

For long format fits, a vector of numeric identifiers for unique analytic units.

priorTreatment

For long format fits, includes treatment levels from previous times if TRUE. This argument is ignored for wide format fits. Default: TRUE.

n.trees

Number of gbm iterations passed on to gbm::gbm().

interaction.depth

A positive integer denoting the tree depth used in gradient boosting. Default: 3.

shrinkage

A numeric value between 0 and 1 denoting the learning rate. See gbm for more details. Default: 0.01.

bag.fraction

A numeric value between 0 and 1 denoting the fraction of the observations randomly selected in each iteration of the gradient boosting algorithm to propose the next tree. See gbm for more details. Default: 1.0.

n.minobsinnode

An integer specifying the minimum number of observations in the terminal nodes of the trees used in the gradient boosting. See gbm for more details. Default: 10.

perm.test.iters

A non-negative integer giving the number of iterations of the permutation test for the KS statistic. If perm.test.iters=0 then the function returns an analytic approximation to the p-value. Setting perm.test.iters=200 will yield precision to within 3% if the true p-value is 0.05. Use perm.test.iters=500 to be within 2%. Default: 0.

print.level

The amount of detail to print to the screen. Default: 2.

verbose

If TRUE, lots of information will be printed to monitor the the progress of the fitting. Default: TRUE.

stop.method

A method or methods of measuring and summarizing balance across pretreatment variables. Current options are ks.mean, ks.max, es.mean, and es.max. ks refers to the Kolmogorov-Smirnov statistic and es refers to standardized effect size. These are summarized across the pretreatment variables by either the maximum (.max) or the mean (.mean). Default: c("es.max").

sampw

Optional sampling weights.

version

"gbm", "xgboost", or "legacy", indicating which version of the twang package to use.

"gbm"

uses gradient boosting from the gbm package.

"xgboost"

uses gradient boosting from the xgboost package.

"legacy"

uses the prior implementation of the ps function.

Default: "gbm".

ks.exact

NULL or a logical indicating whether the Kolmogorov-Smirnov p-value should be based on an approximation of exact distribution from an unweighted two-sample Kolmogorov-Smirnov test. If NULL, the approximation based on the exact distribution is computed if the product of the effective sample sizes is less than 10,000. Otherwise, an approximation based on the asymptotic distribution is used. **Warning:** setting ks.exact = TRUE will add substantial computation time for larger sample sizes. Default: NULL.

n.keep

A numeric variable indicating the algorithm should only consider every n.keep-th iteration of the propensity score model and optimize balance over this set instead of all iterations. Default: 1.

n.grid

A numeric variable that sets the grid size for an initial search of the region most likely to minimize the stop.method. A value of n.grid=50 uses a 50 point grid from 1:n.trees. It finds the minimum, say at grid point 35. It then looks for the actual minimum between grid points 34 and 36. If specified with n.keep>1, n.grid corresponds to a grid of points on the kept iterations as defined by `n.keep. Default: 25.

...

Additional arguments that are passed to ps function.

Details

For user more comfortable with the options of xgboost::xgboost(), the options for iptw controlling the behavior of the gradient boosting algorithm can be specified using the xgboost naming scheme. This includes nrounds, max_depth, eta, and subsample. In addition, the list of parameters passed to xgboost can be specified with params.

See Also

ps, mnps, gbm, xgboost, plot, bal.table