Overview
precmed is an R package for estimating average treatment effects (ATEs) and estimating and validating conditional average treatment effects (CATEs) in randomized trials and observational studies, with methods for binary, count and survival outcomes. The ATE describes an effect across a population, while the CATE describes an average effect among patients with particular observed characteristics. Together, they support the study of treatment effect heterogeneity and precision medicine.
Use precmed when you want to:
- Estimate the ATE comparing two treatments using doubly robust augmented inverse probability weighting (AIPW).
- Explore treatment effect heterogeneity by developing and assessing CATE models for binary, count and survival outcomes.
- Visualize and compare estimated effects across patient subgroups.
For CATE scores, T-learners compare predictions from outcome models fitted separately in each treatment arm. The package also provides doubly robust two-regression and contrast-regression scores, as well as cross-validation and subgroup visualizations. The ratio-based doubly robust methods build on Yadlowsky et al. (2021); the T-learner framework is described by Künzel et al. (2019). Related methods for treatment selection are described by Zhao et al. (2013), and Jiang et al. (2026) discuss interpretation and visualization.
The methods support causal inference under appropriate assumptions; for observational data, these include adequate control of confounding and sufficient treatment overlap. Survival analyses also use a censoring model for inverse probability of censoring weighting and require appropriate censoring assumptions. Fitting a CATE score and assessing its performance are distinct tasks.
See Is precmed suitable for me? for a quick overview of supported data, outcomes and analyses.
Learning resources
For a broader introduction to personalized medicine using real-world data, see Comparative Effectiveness and Personalized Medicine Research Using Real-World Data (Debray, Nguyen, and Platt 2026). The following chapters are particularly relevant to precmed:
- Chapter 5: defining causal effects and understanding marginal and conditional treatment effects (Nguyen et al. 2026).
- Chapter 17: principles of CATE prediction and model development in randomized and non-randomized data (Hoogland et al. 2026).
- Chapter 19: validation strategies and assessment of discrimination, calibration, and decision accuracy (Thao et al. 2026).
- Chapter 20: visualization and interpretation of individualized treatment rules, validation curves, and responder diagnostics, with examples using precmed (Jiang et al. 2026).
The original methodological references are Yadlowsky et al. (2021) for ratio-based CATE estimation and validation, and Zhao et al. (2013) for target-population selection.
Two free courses complement the book and introduce precmed, its practical use, and the underlying statistical methods. An Introduction to Precision Medicine covers the foundations through recorded webinars, exercises, and readings. The free companion course to the book provides background materials, example R code, and curated references to support practical analyses.
Installation
The precmed package can be installed from CRAN as follows:
install.packages("precmed")The latest version can be installed from GitHub as follows:
install.packages("devtools")
devtools::install_github(repo = "smartdata-analysis-and-statistics/precmed")Try the quick start for a complete count-outcome example and validation plot.
Citation and support
To cite the installed version of precmed, run citation("precmed") in R, or see the authors and citation page. Please also cite the methodological references relevant to your analysis.
For questions, bug reports, or feature requests, use GitHub issues. For a bug report, please include your package and R versions, the error message, and a minimal reproducible example using simulated or non-sensitive data.
Package capabilities
The package compares two treatments using outcome-specific effect measures:
| Outcome | Effect measure | Examples |
|---|---|---|
| Binary | Risk difference in outcome probabilities (treatment 1 minus treatment 0) | ATE, CATE |
| Count | Ratio of event rates (treatment 1 over treatment 0) | ATE, CATE |
| Survival | At a specified follow-up horizon: population-average risk difference (treatment 1 minus treatment 0), ratio of restricted mean time lost, and population-level cumulative hazard ratio (treatment 1 over treatment 0) | ATE, CATE |
Count rate ratios and survival RMTL and cumulative hazard ratios from atefit() are returned on the log scale; exponentiate them to obtain ratios. Survival risk differences are returned on the difference scale. Count and survival CATE scores are log rate ratios and log RMTL ratios, respectively. The ATE summarizes the population, while CATE scores describe effects conditional on observed characteristics. Survival subgroup assessment also reports risk differences at the follow-up horizon.
The main functions in the precmed package are:
| Function | Description |
|---|---|
| catefit() | Estimation of the conditional average treatment effect (CATE) |
| atefit() | Doubly robust estimator for the average treatment effect (ATE) |
| catecv() | Development and cross-validation of CATE scores |
| abc() | Compute the area between the average treatment difference curve of competing models for the CATE (Zhao et al. 2013) |
| plot() | Two side-by-side line plots of validation curves from the precmed object |
| boxplot() | Plot the proportion of subjects with an estimated treatment effect no less than over a range of values for (Zhao et al. 2013). |
For more info: https://smartdata-analysis-and-statistics.github.io/precmed/
Recommended workflow
For count and survival outcomes, the following workflow estimates the ATE and develops and validates a CATE model:
- Use
atefit()to estimate the overall ATE between two treatment groups and its uncertainty using bootstrap resampling. - Compare up to five modelling approaches (e.g., Poisson regression, boosting) for estimating the CATE using cross-validation through catecv.
- Select the best modelling approach using 3 metrics:
- Compare the steepness of the validation curves in the validation samples across methods using
plot(). Two side-by-side plots are generated, visualizing the estimated average treatment effects in a series of nested subgroups. On the left side the curve is shown for the training set, and on the right side the curve is shown for the validation set. Each line in the plots represents one scoring method included in the fit. - The area between curves (ABC) using abc quantifies a model’s ability to capture treatment effect heterogeneity. Higher ABC values are preferable as they indicate that more treatment effect heterogeneity is captured by the scoring method.
- Compare the distribution of the estimated ATE across different levels of the CATE score percentiles using
boxplot().
- Compare the steepness of the validation curves in the validation samples across methods using
- Fit the chosen modelling approach using
catefit(); assess performance in an independent dataset where possible.
For binary outcomes, the binary example illustrates atefit(), catefit() and a separate held-out subgroup assessment.
In the vignettes, we will adopt a different workflow to gradually expose the user from simple to more complex methods.

