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

View source: R/iptw.R

iptwR Documentation

Inverse probability of treatment weighting for marginal structural models.


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


  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,



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


The dataset, includes treatment assignment as well as covariates.


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


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


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


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


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


Number of gbm iterations passed on to gbm.


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


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


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.


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.


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.


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


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


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").


Optional sampling weights.


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


uses gradient boosting from the gbm package.


uses gradient boosting from the xgboost package.


uses the prior implementation of the ps function.

Default: "gbm".


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.


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.


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.


For user more comfortable with the options of 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.


Returns an object of class iptw, a list containing


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


The specified estimand.


The stopping rules used to optimize iptw balance.


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


The unique times in the specified model.

See Also

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

twang documentation built on May 29, 2024, 4:40 a.m.