CausalGPS

Matching on generalized propensity scores with continuous exposures

https://github.com/nsaph-software/causalgps

Science Score: 23.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
  • codemeta.json file
  • .zenodo.json file
  • DOI references
    Found 1 DOI reference(s) in README
  • Academic publication links
  • Committers with academic emails
    2 of 7 committers (28.6%) from academic institutions
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (15.4%) to scientific vocabulary
Last synced: 11 months ago · JSON representation

Repository

Matching on generalized propensity scores with continuous exposures

Basic Info
Statistics
  • Stars: 25
  • Watchers: 3
  • Forks: 6
  • Open Issues: 6
  • Releases: 12
Fork of NSAPH/GPSmatching
Created over 5 years ago · Last pushed about 1 year ago
Metadata Files
Readme Code of conduct

README.md

CausalGPS

| Resource | Github Actions | Code Coverage | | ---------- | -------------------- |-----------------| | Platforms | Windows, macOS, Linux| codecov | | R CMD check | R build status | codecov |

Matching on generalized propensity scores with continuous exposures

Summary

CausalGPS is an R package that implements matching on generalized propensity scores with continuous exposures. The package introduces a novel approach for estimating causal effects using observational data in settings with continuous exposures, and a new framework for GPS caliper matching that jointly matches on both the estimated GPS and exposure levels to fully adjust for confounding bias.

Installation

  • Installing from source

r library("devtools") install_github("NSAPH-Software/CausalGPS") library("CausalGPS")

  • Installing from CRAN

r install.packages("CausalGPS")

  • Setting up docker environment

Developing Docker image can be downloaded from Docker Hub. See more details in docker_singularity.

Usage

The CausalGPS package encompasses two primary stages: Design and Analysis. The Design stage comprises estimating GPS values, generating weights or counts of matched data, and evaluating the generated population. The Analysis stage is focused on estimating the exposure-response function. The following figure represents the process workflow

Processing flow

Estimating GPS values

GPS values can be estimated using two distinct approaches: kernel and normal.

```r set.seed(967) md <- generatesyndata(samplesize = 500)

mxgboost <- function(nthread = 1, ntrees = 35, shrinkage = 0.3, maxdepth = 5, ...) {SuperLearner::SL.xgboost( nthread = nthread, ntrees = ntrees, shrinkage=shrinkage, maxdepth=maxdepth, ...)}

gpsobj <- estimategps(.data = md, .formula = w ~ I(cf1^2) + cf2 + I(cf3^2) + cf4 + cf5 + cf6, sllib = c("mxgboost"), gpsdensity = "normal")

```

where

  • .data A data.frame of input data including the id column.
  • .formula The formula for modeling exposure based on provided confounders.
  • sl_lib A vector of prediction algorithms.
  • gps_density A model type which is used for estimating GPS value, including normal (default) and kernel.

Computing weight or count of matched data

The second step in processing involves computing the weight or count of matched data. For the former, the weighting approach is used, and for the latter, the matching approach.

```r cwobjectmatching <- computecounterweight(gpsobj = gpsobj, ciappr = "matching", binseq = NULL, nthread = 1, deltan = 0.1, distmeasure = "l1", scale = 0.5)

```

where

  • ci_appr The causal inference approach. Possible values are:
    • "matching": Matching by GPS
    • "weighting": Weighting by GPS
  • bin_seq Sequence of w (treatment) to generate pseudo population. If NULL is passed the default value will be used, which is seq(min(w)+delta_n/2,max(w), by=delta_n).
  • nthread An integer value that represents the number of threads to be used by internal packages in a shared memory system.

If ci.appr = matching:
- dist_measure: Distance measuring function. Available options:
- l1: Manhattan distance matching
- delta_n: caliper parameter.
- scale: a specified scale parameter to control the relative weight that is attributed to the distance measures of the exposure versus the GPS.

Estimating psuedo population

The pseudo population is created by combining the counter_weight of data samples with the original data, including the outcome variable.

r pseudo_pop_matching <- generate_pseudo_pop(.data = m_d, cw_obj = cw_object_matching, covariate_col_names = c("cf1", "cf2", "cf3", "cf4", "cf5", "cf6"), covar_bl_trs = 0.1, covar_bl_trs_type = "maximal", covar_bl_method = "absolute")

where

  • covar_bl_method: covariate balance method. Available options:
    • 'absolute'
  • covar_bl_trs: covariate balance threshold
  • covar_bl_trs_type: covariate balance type (mean, median, maximal)

Estimating exposure response function

The exposure-response function can be computed using parametric, semiparametric, and nonparametric approaches.

```r erfobjnonparametric <- estimateerf(.data = pseudopopmatching$.data, .formula = Y ~ w, weightscolname = "counterweight", modeltype = "nonparametric", wvals = seq(2,20,0.5), bwseq = seq(0.2,2,0.2), kernelappr = "kernsmooth")

```

where

  • w_vals: A numeric vector of values at which you want to calculate the exposure response function.
  • bw_seq: A vector of bandwidth values.
  • kernel_appr: Internal kernel approach. Available options are locpol and kernsmooth.

Notes

  • Trimming data for extreme exposure value, or trimmming gpsobj for extreme GPS values, can be done by using `trimit` function.

r trimmed_data <- trim_it(data_obj = m_d, trim_quantiles = c(0.05, 0.95), variable = "w")

  • For the prediction model, we use the SuperLearner package. Users must prepare a wrapper function for the options available in SuperLearner to have a function with customized parameters. For instance, in the code below, we override the default values of nthread, ntrees, shrinkage, and maxdepth. For example, in the following code, we override nthread, ntrees, shrinkage, and `maxdepth` default values.

r m_xgboost <- function(nthread = 1, ntrees = 35, shrinkage = 0.3, max_depth = 5, ...) {SuperLearner::SL.xgboost( nthread = nthread, ntrees = ntrees, shrinkage=shrinkage, max_depth=max_depth, ...)}

  • To test your code and run examples, you can generate synthetic data.

```r syndata <- generatesyndata(samplesize=1000, outcomesd = 10, gpsspec = 1, cova_spec = 1)

```

Contribution

For more information about reporting bugs and contribution, please read the contribution page from the package web page.

Code of Conduct

Please note that the CausalGPS project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

References

  • CausalGPS method paper

@article{wu2022matching, title={Matching on generalized propensity scores with continuous exposures}, author={Wu, Xiao and Mealli, Fabrizia and Kioumourtzoglou, Marianthi-Anna and Dominici, Francesca and Braun, Danielle}, journal={Journal of the American Statistical Association}, pages={1--29}, year={2022}, publisher={Taylor \& Francis} }

  • CausalGPS software paper

@misc{khoshnevis2023causalgps, title={CausalGPS: An R Package for Causal Inference With Continuous Exposures}, author={Naeem Khoshnevis and Xiao Wu and Danielle Braun}, year={2023}, eprint={2310.00561}, archivePrefix={arXiv}, primaryClass={stat.CO}, DOI={h10.48550/arXiv.2310.00561} }

Owner

  • Name: National Studies on Air Pollution and Health Software
  • Login: NSAPH-Software
  • Kind: organization
  • Location: United States of America

NSAPH Software is a collection of open-source packages to carry out National Studies on Air Pollution and Health.

GitHub Events

Total
  • Issues event: 2
  • Watch event: 1
  • Issue comment event: 3
  • Push event: 7
  • Pull request review event: 1
  • Pull request event: 4
Last Year
  • Issues event: 2
  • Watch event: 1
  • Issue comment event: 3
  • Push event: 7
  • Pull request review event: 1
  • Pull request event: 4

Committers

Last synced: over 2 years ago

All Time
  • Total Commits: 519
  • Total Committers: 7
  • Avg Commits per committer: 74.143
  • Development Distribution Score (DDS): 0.071
Past Year
  • Commits: 123
  • Committers: 1
  • Avg Commits per committer: 123.0
  • Development Distribution Score (DDS): 0.0
Top Committers
Name Email Commits
naeemkh k****m@g****m 482
wxwx1993 w****1@1****m 16
Xiao Wu x****u@m****u 14
jennyjyounglee j****e@g****m 2
mbsabath b****1@g****m 2
daniellebraun d****n@h****u 2
Michelle Qin 5****n 1
Committer Domains (Top 20 + Academic)

Issues and Pull Requests

Last synced: 11 months ago

All Time
  • Total issues: 66
  • Total pull requests: 68
  • Average time to close issues: 5 months
  • Average time to close pull requests: 4 days
  • Total issue authors: 17
  • Total pull request authors: 4
  • Average comments per issue: 1.91
  • Average comments per pull request: 0.76
  • Merged pull requests: 62
  • Bot issues: 0
  • Bot pull requests: 0
Past Year
  • Issues: 2
  • Pull requests: 4
  • Average time to close issues: 1 day
  • Average time to close pull requests: 8 days
  • Issue authors: 1
  • Pull request authors: 1
  • Average comments per issue: 1.5
  • Average comments per pull request: 0.0
  • Merged pull requests: 4
  • Bot issues: 0
  • Bot pull requests: 0
Top Authors
Issue Authors
  • Naeemkh (21)
  • m-qin (14)
  • wxwx1993 (11)
  • jennyjyounglee (4)
  • PetrichorSjj (2)
  • QAZqaz123wkx (2)
  • pdbailey0 (2)
  • daniellebraun (1)
  • fbargaglistoffi (1)
  • zhangc927 (1)
  • juliagegeran (1)
  • danielmork (1)
  • andrepython (1)
  • macork (1)
  • MatteoCorsiUnige (1)
Pull Request Authors
  • Naeemkh (57)
  • wxwx1993 (8)
  • jennyjyounglee (3)
  • m-qin (1)
Top Labels
Issue Labels
enhancement (26) good first issue (8) bug (4) documentation (1) help wanted (1)
Pull Request Labels
documentation (1) enhancement (1)

Packages

  • Total packages: 1
  • Total downloads:
    • cran 434 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 1
  • Total versions: 11
  • Total maintainers: 1
cran.r-project.org: CausalGPS

Matching on Generalized Propensity Scores with Continuous Exposures

  • Versions: 11
  • Dependent Packages: 0
  • Dependent Repositories: 1
  • Downloads: 434 Last month
Rankings
Forks count: 10.8%
Stargazers count: 11.2%
Average: 19.8%
Dependent repos count: 24.0%
Downloads: 24.1%
Dependent packages count: 28.8%
Maintainers (1)
Last synced: 11 months ago

Dependencies

.github/workflows/R-CMD-check.yaml actions
  • actions/cache v2 composite
  • actions/checkout v2 composite
  • actions/upload-artifact main composite
  • r-lib/actions/setup-pandoc v1 composite
  • r-lib/actions/setup-r v1 composite
.github/workflows/test-coverage.yaml actions
  • actions/checkout v2 composite
  • r-lib/actions/setup-r v1 composite
  • r-lib/actions/setup-r-dependencies v1 composite
DESCRIPTION cran
  • R >= 3.5.0 depends
  • Ecume * imports
  • MASS * imports
  • Rcpp * imports
  • SuperLearner * imports
  • data.table * imports
  • gam * imports
  • ggplot2 * imports
  • gnm * imports
  • locpol * imports
  • logger * imports
  • parallel * imports
  • polycor * imports
  • rlang * imports
  • stats * imports
  • wCorr * imports
  • xgboost * imports
  • covr * suggests
  • knitr * suggests
  • ranger * suggests
  • rmarkdown * suggests
  • testthat * suggests
docker_singularity/Dockerfile docker
  • rocker/verse 4.1.0 build