Estimate Inverse Probability Weights
Overview
Functions to estimate the probability to receive the observed treatment, based on individual characteristics. The inverse of these probabilities can be used as weights when estimating causal effects from observational data via marginal structural models. Both point treatment situations and longitudinal studies can be analysed. The same functions can be used to correct for informative censoring.
- **New Maintainer**: Hung Thai Tran (Research Assistant, OUCRU Biostatistics Group).
- **Documentation Infrastructure**: Converted all package documentation to
roxygen2. - **Testing**: Integrated a comprehensive suite of 22 unit tests using
testthatto verify math foripwpointandipwtm. - **Data Documentation**: Updated
haartdatvariables and fixed documentation for datasets to resolve CRAN warnings. - **Examples**: Corrected example line widths in
.Rdfiles to prevent truncation in PDF manuals. - **UI**: Added a
README.Rmdwith updated simulation examples for point-treatment and time-varying causal inference workflows.
From NEWS.md in the release
Install
Health
ERRORexamplesr-devel-linux-x86_64-debian-gcc
Running examples in ‘ipw-Ex.R’ failed
The error most likely occurred in:
> base::assign(".ptime", proc.time(), pos = "CheckExEnv")
> ### Name: ipwtm
> ### Title: Estimate Inverse Probability Weights (Time Varying)
> ### Aliases: ipwtm
> ### Keywords: htest models
>
> ### ** Examples
>
> ########################################################################
> #EXAMPLE 1
>
> #Load longitudinal data from HIV positive individuals.
> data(haartdat)
>
> #CD4 is confounder for the effect of initiation of HAART therapy on mortality.
> #Estimate inverse probability weights to correct for confounding.
> #Exposure allocation model is Cox proportional hazards model.
> temp <- ipwtm(
+ exposure = haartind,
+ family = "survival",
+ numerator = ~ sex + age,
+ denominator = ~ sex + age + cd4.sqrt,
+ id = patient,
+ tstart = tstart,
+ timevar = fuptime,
+ type = "first",
+ data = haartdat)
Error in a$specials[[i]] : subscript out of bounds
Calls: ipwtm ... survfit.coxph -> model.matrix.coxph -> delete.response -> off
Execution haltedERRORtestsr-devel-linux-x86_64-debian-gcc
Running ‘testthat.R’ [3s/4s]
Running the tests in ‘tests/testthat.R’ failed.
Complete output:
> # This file is part of the standard setup for testthat.
> # It is recommended that you do not modify it.
> #
> # Where should you do additional test configuration?
> # Learn more about the roles of various files in:
> # * https://r-pkgs.org/testing-design.html#sec-tests-files-overview
> # * https://testthat.r-lib.org/articles/special-files.html
>
> library(testthat)
> library(ipw)
>
> test_check("ipw")
Saving _problems/test-ipwtm-20.R
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 18 ]
══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-ipwtm.R:10:3'): ipwtm correctly calculates cumulative weights for survival family ──
<subscriptOutOfBoundsError/error/condition>
Error in `a$specials[[i]]`: subscript out of bounds
Backtrace:
▆
1. └─ipw::ipwtm(...) at test-ipwtm.R:10:3
2. └─survival::basehaz(mod1, centered = TRUE)
3. ├─survival::survfit(fit, se.fit = FALSE)
4. └─survival:::survfit.coxph(fit, se.fit = FALSE)
5. └─survival:::model.matrix.coxph(object, data = mf)
6. └─stats::delete.response(object$terms)
7. └─stats (local) off(a$specials[[i]])
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 18 ]
Error:
! Test failures.
Execution halted- ERROR12 OK, 1 ERROR2026-10-24
- OK13 OK2026-08-05
- NOTE12 OK, 1 NOTE2026-08-01
- OK13 OK2026-06-09
- ERROR12 OK, 1 ERROR2026-06-08
Show 1 earlier changeHide 1 earlier change
- OK14 OK2026-03-10
Documentation
- Help pages
- 8
- Examples that run
- 38%3 run in a plain check · 5 hold no code
- Exported functions with examples
- 100%
- Documented parameters
- 100%
- Return-value docs
- 100%
- Help pages citing references
- 100%
Downloads
Repository
- PRs merged (all time)
- not measured
- Median days to close, 50 most recently updated closed issues
- 0
- Median days to close, 50 most recently updated closed PRs
- not measured
Stars over time
Forks over time
Issues over time
7 development-tooling and community-health practices detected across 5 families in the upstream repository
Checks run against github.com/tranhung93/ipw on 2026-10-21.
Show all practicesHide 1 practice
Dependencies
Installing ipw adds 23 packages (14 with compiled code, 18 MB of source tarballs). Heaviest: stringi 11 MB, vctrs 1.0 MB, dplyr 902 KB.
Code & Tests
Datasets
People & History
Previously maintained by Willem M. van der Wal (1.2 to 1.2.1.1) and Ronald B. Geskus (1.0 to 1.0-11).
Show 3 peopleHide 3 people
Pick two releases to compare their code metrics.
- RR 4.6.0 released · 2026-04-24
- 1.3.0Latest
- 1.2.22025-12-08 · diff ↗
- 1.2.1.12025-07-28 · diff ↗
- RR 4.5.0 released · 2025-04-11
- RR 4.4.0 released · 2024-04-24
- 1.2.12023-12-11 · diff ↗
- RR 4.3.0 released · 2023-04-21
- unarchivedReturned to CRAN2023-01-07
- 1.22023-01-07 · diff ↗
- archivedRemoved from CRAN2022-10-07email to the maintainer is undeliverable
- RR 4.2.0 released · 2022-04-22
- RR 4.1.0 released · 2021-05-18
- RR 4.0.0 released · 2020-04-24
- RR 3.6.0 released · 2019-04-26
- RR 3.5.0 released · 2018-04-23
Show 24 earlier eventsHide 24 earlier events
- RR 3.4.0 released · 2017-04-21
- RR 3.3.0 released · 2016-05-03
- 1.0-112015-08-18 · diff ↗
- RR 3.2.0 released · 2015-04-16
- RR 3.1.0 released · 2014-04-10
- orphanedOrphaned by its maintainer2013-12-21maintainer address <w.m.vd.wal@umcutrecht.nl> bounced
- RR 3.0.0 released · 2013-04-03
- RR 2.15.0 released · 2012-03-30
- RR 2.14.0 released · 2011-10-31
- 1.0-102011-09-11 · diff ↗
- RR 2.13.0 released · 2011-04-13
- 1.0-92011-04-04 · diff ↗
- RR 2.12.0 released · 2010-10-15
- 1.0-82010-09-30 · diff ↗
- 1.0-72010-09-09 · diff ↗
- 1.0-62010-08-20 · diff ↗
- RR 2.11.0 released · 2010-04-22
- 1.0-52010-03-25 · diff ↗
- 1.0-42010-03-08 · diff ↗
- 1.0-32010-03-05 · diff ↗
- 1.0-22010-02-14 · diff ↗
- 1.0-12010-02-08 · diff ↗
- 1.02010-02-04
- RR 2.10.0 released · 2009-10-26
Package metadata
- First published
- 2010-02-04
- Total releases
- 17 / 16 yrs
- License
- MIT + file LICENSE OSI · relicensed from GPL (>= 2) in 1.3.0
- Minimum R
- ≥ 3.2.0
- Bundled data
- 78 KB / 4 files
- Download size
- 121 KB
Cite
Cite this package
Run in R for the authors' entry:
citation("ipw")The package provides a citation file, so citation() returns the authors' own entry.
It points to 10.18637/jss.v043.i13.
Cite the R Observatory
For a number measured here: a download total, a coverage figure, an archival date.
From data release v2026-10-24, which the citation names so these numbers can be found later. More on citing and the projects behind them.