Skip to content

Commit

Permalink
some basic work on developing the package
Browse files Browse the repository at this point in the history
* Rdpack added
* @param and text added to function
* testthat scaffolding
  • Loading branch information
n8thangreen committed Dec 5, 2023
1 parent c25002a commit 2e7452c
Show file tree
Hide file tree
Showing 9 changed files with 130 additions and 43 deletions.
16 changes: 12 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
Package: mimR
Title: Multiple Imputation Marginalisation
Version: 0.0.0.9000
Authors@R:
Authors@R: c(
person("Nathan", "Green", , "[email protected]",
role = c("aut", "cre"),
comment = c(ORCID = "0000-0003-2745-1736"))
Description: Multiple Imputation Marginalisation.
comment = c(ORCID = "0000-0003-2745-1736")),
person("Antonio", "Remiro-Azocar", email = "[email protected]",
role = c("aut"),
comment = c(ORCID = "0000-0002-7263-4251")))
Description: Multiple Imputation Marginalisation with several different computation approaches.
See Remiro‐Azócar A, Heath A, Baio G (2022). “Parametric G‐computation for compatibl
indirect treatment comparisons with limited individual patient data.”
Res. Synth. Methods, 1–31. ISSN 1759-2879, doi:10.1002/jrsm.1565, 2108.12208
License: GPL (>= 3)
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.3.9000
Imports:
boot,
copula,
rstanarm
rstanarm,
Rdpack (>= 0.7)
Suggests:
dplyr,
ggplot2,
Expand All @@ -26,3 +33,4 @@ Suggests:
testthat (>= 3.0.0)
VignetteBuilder: knitr
Config/testthat/edition: 3
RdMacros: Rdpack
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ export(strategy_maic)
export(strategy_stc)
export(trial_treatment_effect)
export(trial_variance)
importFrom(Rdpack,reprompt)
110 changes: 79 additions & 31 deletions R/IPD_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
# create class for each approach

#' @rdname strategy
#' strategy_maic
#' Matching-adjusted indirect comparison strategy Used to compare marginal
#' treatment effects where there are cross-trial differences in effect modifiers
#' and limited patient-level data.
#'
#' @param formula
#' The default formula is
#' \deqn{
#' y = X3 + X4 + trt*X1 + trt*X2
#' }
#'
#' @param formula Linear regression formula object
#' @param R
#' @param ald
#' @param ald Aggregate-level data
#'
#' @return
#' @return `maic` class object
#' @export
#'
strategy_maic <- function(formula = as.formula("y ~ X3 + X4 + trt*X1 + trt*X2"),
Expand All @@ -21,11 +28,17 @@ strategy_maic <- function(formula = as.formula("y ~ X3 + X4 + trt*X1 + trt*X2"),
}

#' @rdname strategy
#' strategy_stc
#'
#' @param formula
#' Simulated treatment comparison strategy
#' outcome regression-based method which targets a conditional treatment effect.
#'
#' The default formula is
#' \deqn{
#' y = X3 + X4 + trt*I(X1 - mean(X1)) + trt*I(X2 - mean(X2))
#' }
#'
#' @param formula Linear regression formula object
#'
#' @return
#' @return `stc` class object
#' @export
#
strategy_stc <- function(formula =
Expand All @@ -39,12 +52,17 @@ strategy_stc <- function(formula =
}

#' @rdname strategy
#' strategy_gcomp_ml
#' G-computation maximum likelihood strategy
#'
#' @param formula
#' @param formula Linear regression formula object
#' @param R
#'
#' @return
# The default formula is
#' \deqn{
#' y = X3 + X4 + trt*X1 + trt*X2)
#' }
#'
#' @return `gcomp_ml` class object
#' @export
#'
strategy_gcomp_ml <- function(formula =
Expand All @@ -57,11 +75,16 @@ strategy_gcomp_ml <- function(formula =
}

#' @rdname strategy
#' strategy_gcomp_stan
#' G-computation Bayesian strategy
#'
#' @param formula
#' The default formula is
#' \deqn{
#' y = X3 + X4 + trt*X1 + trt*X2)
#' }
#'
#' @param formula Linear regression formula object
#'
#' @return
#' @return `gcomp_stan` class object
#' @export
#'
strategy_gcomp_stan <- function(formula =
Expand All @@ -73,9 +96,11 @@ strategy_gcomp_stan <- function(formula =
}

#' @name strategy
#' New_strategy
#' New strategy objects
#'
#' Create class for each approach
#'
#' @param strategy
#' @param strategy Class name
#' @param ... Additional arguments
#'
#' @return
Expand All @@ -86,12 +111,23 @@ new_strategy <- function(strategy, ...) {
}


#' Main wrapper for hat_Delta_stats
#' Calculate the difference between treatments using all evidence
#'
#' This is the main wrapper for `hat_Delta_stats()`.
#'
#' @param AC.IPD
#' @param BC.ALD
#' @param strategy
#' \insertCite{RemiroAzocar2022}{mimR}
#'
#' @param AC.IPD Individual-level patient data. Suppose between studies A and C.
#' @param BC.ALD Aggregate-level data. Suppose between studies B and C.
#' @param strategy Computation strategy function. These can be
#' `strategy_maic()`, `strategy_stc`, `strategy_gcomp_ml` and `strategy_gcomp_stan`
#' @param ... Additional arguments
#' @return List of statistics as a `mimR` class object
#' @importFrom Rdpack reprompt
#'
#' @references
#' \insertRef{RemiroAzocar2022}{mimR}
#'
#' @export
#'
hat_Delta_stats <- function(AC.IPD, BC.ALD, strategy, ...) {
Expand Down Expand Up @@ -126,7 +162,13 @@ hat_Delta_stats <- function(AC.IPD, BC.ALD, strategy, ...) {

#' @name IPD_stats
#' Individual level data statistics
#' @return mean, variance
#'
#' @param strategy A list corresponding to different approaches
#' @template args-ipd
#' @template args-ald
#' @param ... Additional arguments
#'
#' @return Mean and variance
#' @export
#'
IPD_stats <- function(strategy, ipd, ald, ...)
Expand All @@ -141,14 +183,15 @@ IPD_stats.default <- function() {


#' @rdname IPD_stats
#' IPD_stats.maic
#' Matching-adjusted indirect comparison statistics
#'
#' marginal A vs C treatment effect estimates
#' using bootstrapping
#'
#' @param strategy
#' @param strategy A list corresponding to different approaches
#' @template args-ipd
#' @template args-ald
#' @return Mean and variance
#'
#' @export
#'
Expand All @@ -171,11 +214,16 @@ IPD_stats.maic <- function(strategy,


#' @rdname IPD_stats
#' IPD_stats.stc
#' Simulated treatment comparison statistics
#'
#' IPD from the AC trial are used to fit a regression model describing the
#' observed outcomes `y` in terms of the relevant baseline characteristics `x` and
#' the treatment variable `z`.
#'
#' @param strategy
#' @param strategy A list corresponding to different approaches
#' @template args-ipd
#' @template args-ald
#' @return Mean and variance
#' @export
#'
IPD_stats.stc <- function(strategy,
Expand All @@ -193,13 +241,13 @@ IPD_stats.stc <- function(strategy,


#' @rdname IPD_stats
#' IPD_stats.gcomp_ml
#' G-computation maximum likelihood statistics
#'
#' @param strategy
#' @param strategy A list corresponding to different approaches
#' @template args-ipd
#' @template args-ald
#'
#' @return
#' @return Mean and variance
#' @export
#'
IPD_stats.gcomp_ml <- function(strategy,
Expand All @@ -217,13 +265,13 @@ IPD_stats.gcomp_ml <- function(strategy,


#' @rdname IPD_stats
#' IPD_stats.gcomp_stan
#' G-computation Bayesian statistics
#'
#' @param strategy
#' @param strategy A list corresponding to different approaches
#' @template args-ipd
#' @template args-ald
#'
#' @return
#' @return Mean and variance
#' @export
#'
IPD_stats.gcomp_stan <- function(strategy,
Expand Down
4 changes: 2 additions & 2 deletions R/gcomp_stan.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@

#' G-computation using Stan
#'
#' @param formula
#' @param formula Linear regression formula object
#' @template args-ipd
#' @template args-ald
#'
#' @return
#' @return A list of `y.star.A` and `y.star.C` posterior predictions
#' @export
#'
gcomp_stan <- function(formula = as.formula("y ~ X3 + X4 + trt*X1 + trt*X2"),
Expand Down
10 changes: 10 additions & 0 deletions inst/REFERENCES.bib
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@article{RemiroAzocar2022,
author = {Remiro‐Az{\'{o}}car, Antonio and Heath, Anna and Baio, Gianluca},
doi = {10.1002/jrsm.1565},
eprint = {2108.12208},
issn = {1759-2879},
journal = {Res. Synth. Methods},
pages = {1--31},
title = {{Parametric G‐computation for compatible indirect treatment comparisons with limited individual patient data}},
year = {2022}
}
5 changes: 4 additions & 1 deletion man/gcomp_stan.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 15 additions & 5 deletions man/hat_Delta_stats.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions tests/testthat/test-hat_Delta_stats.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_that("multiplication works", {
expect_equal(2 * 2, 4)
})
4 changes: 4 additions & 0 deletions vignettes/Example.Rmd → vignettes/Basic_example.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ knitr::opts_chunk$set(

## Introduction

Population adjustment methods such as matching-adjusted indirect comparison (MAIC) are increasingly used to compare marginal treatment effects when there are cross-trial differences in effect modifiers and limited patient-level data. MAIC is based on propensity score weighting, which is sensitive to poor covariate over- lap and cannot extrapolate beyond the observed covariate space. Current out- come regression-based alternatives can extrapolate but target a conditional treatment effect that is incompatible in the indirect comparison. When adjusting for covariates, one must integrate or average the conditional estimate over the rel- evant population to recover a compatible marginal treatment effect. We propose a marginalization method based on parametric G-computation that can be easily applied where the outcome regression is a generalized linear model or a Cox model. The approach views the covariate adjustment regression as a nuisance model and separates its estimation from the evaluation of the marginal treatment effect of interest. The method can accommodate a Bayesian statistical framework, which naturally integrates the analysis into a probabilistic framework. A simula- tion study provides proof-of-principle and benchmarks the method's performance against MAIC and the conventional outcome regression. Parametric G- computation achieves more precise and more accurate estimates than MAIC, par- ticularly when covariate overlap is poor, and yields unbiased marginal treatment effect estimates under no failures of assumptions. Furthermore, the marginalized regression-adjusted estimates provide greater precision and accuracy than the conditional estimates produced by the conventional outcome regression, which are

## Example

```{r setup, warning=FALSE, message=FALSE}
library(boot) # non-parametric bootstrap in MAIC and ML G-computation
library(copula) # simulating BC covariates from Gaussian copula
Expand Down

0 comments on commit 2e7452c

Please sign in to comment.