Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ export(calculate_ate)
export(calculate_trial_mean)
export(calculate_trial_mean_binary)
export(calculate_trial_mean_continuous)
export(calculate_trial_mean_count)
export(calculate_trial_variance)
export(calculate_trial_variance_binary)
export(calculate_trial_variance_continuous)
export(calculate_trial_variance_count)
export(get_treatment_effect)
export(marginal_treatment_effect)
export(marginal_variance)
Expand Down
26 changes: 13 additions & 13 deletions R/calc_ALD_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@
#' @examples
#' \dontrun{
#' strategy <- list(family = list(family = "binomial")) # basic version
#' ald <- data.frame(trial = 1:5,
#' n_B = c(10, 20, 15, 30, 25),
#' n_C = c(12, 18, 20, 25, 22))
#' ald <- data.frame(trt = c("B","C","B","C"),
#' variable = c(NA, NA, "y", "y"),
#' statistic = c("N", "N", "sum", "sum"),
#' value = c(100, 100, 50, 60)
#'
#' calc_ALD_stats(strategy, ald, treatments = list("B", "C"), scale = "log")
#' }
#'
Expand All @@ -43,8 +45,6 @@ calc_ALD_stats <- function(strategy,
#' Marginal effect variance using the delta method
#'
#' Computes the total variance of marginal treatment effects using the delta method.
#' For binomial data, calculates:
#' \deqn{\frac{1}{n_C} + \frac{1}{n_{\bar{C}}} + \frac{1}{n_B} + \frac{1}{n_{\bar{B}}}}.
#'
#' @param ald Aggregate-level data
#' @param treatments A list of treatment labels; default _B_ vs _C_
Expand All @@ -54,7 +54,10 @@ calc_ALD_stats <- function(strategy,
#' @return The total variance of marginal treatment effects.
#' @examples
#' \dontrun{
#' ald <- data.frame(trial = 1:5, n_B = c(10, 20, 15, 30, 25), n_C = c(12, 18, 20, 25, 22))
#' ald <- data.frame(trt = c("B","C","B","C"),
#' variable = c(NA, NA, "y", "y"),
#' statistic = c("N", "N", "sum", "sum"),
#' value = c(100, 100, 50, 60)
#' marginal_variance(ald, treatments = list("B", "C"), scale = "log", family = "binomial")
#' }
#' @export
Expand All @@ -73,12 +76,6 @@ marginal_variance <- function(ald,
#' Marginal treatment effect from reported event counts
#'
#' Computes the relative treatment effect from aggregate-level data using event counts.
#' For binomial data, calculates:
#' \deqn{
#' \log\left( \frac{n_B/(N_B-n_B)}{n_C/(N_B-n_{B})} \right) = \log(n_B n_{\bar{C}}) - \log(n_C n_{\bar{B}})
#' }
#' where \eqn{\bar{C}} is the compliment of \eqn{C}
#' so e.g. \eqn{n_{\bar{C}} = N_C - n_c}.
#'
#' @param ald Aggregate-level data
#' @param treatments A list of treatment labels. Last variable is reference; default `B`, `C` (common; e.g. placebo)
Expand All @@ -88,7 +85,10 @@ marginal_variance <- function(ald,
#' @return The relative treatment effect.
#' @examples
#' \dontrun{
#' ald <- data.frame(trial = 1:5, n_B = c(10, 20, 15, 30, 25), n_C = c(12, 18, 20, 25, 22))
#' ald <- data.frame(trt = c("B","C","B","C"),
#' variable = c(NA, NA, "y", "y"),
#' statistic = c("N", "N", "sum", "sum"),
#' value = c(100, 100, 50, 60)
#' marginal_treatment_effect(ald, treatments = list("B", "C"), scale = "log", family = "binomial")
#' }
#' @export
Expand Down
21 changes: 13 additions & 8 deletions R/calc_IPD_stats.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#' including Matching-Adjusted Indirect Comparison (MAIC), Simulated Treatment Comparison (STC),
#' and G-computation via Maximum Likelihood Estimation (MLE) or Bayesian inference.
#'
#' @param strategy A list corresponding to different approaches
#' @param strategy A list corresponding to different modelling approaches
#' @eval study_data_args(include_ipd = TRUE, include_ald = TRUE)
#' @param scale A scaling parameter for the effect calculation.
#' @param ... Additional arguments
Expand All @@ -20,8 +20,13 @@
#' @examples
#' \dontrun{
#' strategy <- strategy_maic()
#' ipd <- data.frame(id = 1:100, treatment = sample(c("A", "C"), 100, replace = TRUE), outcome = rnorm(100))
#' ald <- data.frame(treatment = c("A", "C"), mean = c(0.2, 0.1), var = c(0.05, 0.03))
#' ipd <- data.frame(trt = sample(c("A", "C"), 100, replace = TRUE),
#' X1 = rnorm(100, 1, 1),
#' y = rnorm(100, 10, 2))
#' ald <- data.frame(trt = c(NA, "B", "C", "B", "C"),
#' variable = c("X1", "y", "y", NA, NA),
#' statistic = c("mean", "sum", "sum", "N", "N"),
#' value = c(0.5, 10, 12, 20, 25))
#' calc_IPD_stats(strategy, ipd, ald, scale = "log_odds")
#' }
#' @export
Expand All @@ -43,7 +48,7 @@ calc_IPD_stats.default <- function(...) {
#' @rdname calc_IPD_stats
#'
#' @section Multiple imputation marginalisation:
#' Using Stan, compute marginal relative treatment effect for _A_ vs _C_ for each MCMC sample
#' Using Stan, compute marginal relative treatment effect for IPD comparator "A" vs reference "C" arms for each MCMC sample
#' by transforming from probability to linear predictor scale. Approximate by
#' using imputation and combining estimates using Rubin's rules, in contrast to [calc_IPD_stats.gcomp_stan()].
#' @import stats
Expand Down Expand Up @@ -86,7 +91,7 @@ calc_IPD_stats.mim <- function(strategy,

#' Factory function for creating calc_IPD_stats methods
#'
#' Creates a method for computing mean and variance statistics based on the supplied function.
#' Creates a method for computing IPD mean and variance statistics based on the supplied function.
#'
#' @param ipd_fun A function that computes mean and variance statistics for individual-level patient data.
#' @return A function that computes mean and variance statistics for a given strategy.
Expand Down Expand Up @@ -128,7 +133,7 @@ IPD_stat_factory <- function(ipd_fun) {

#' @rdname calc_IPD_stats
#' @section Simulated treatment comparison statistics:
#' IPD from the _AC_ trial are used to fit a regression model describing the
#' IPD for reference "C" and comparator "A" trial arms are used to fit a regression model describing the
#' observed outcomes \eqn{y} in terms of the relevant baseline characteristics \eqn{x} and
#' the treatment variable \eqn{z}.
#' @export
Expand All @@ -137,7 +142,7 @@ calc_IPD_stats.stc <- IPD_stat_factory(outstandR:::calc_stc)

#' @rdname calc_IPD_stats
#' @section Matching-adjusted indirect comparison statistics:
#' Marginal _A_ vs _C_ treatment effect estimates
#' Marginal IPD comparator treatment "A" vs reference treatment "C" treatment effect estimates
#' using bootstrapping sampling.
#' @export
#'
Expand All @@ -152,7 +157,7 @@ calc_IPD_stats.gcomp_ml <- IPD_stat_factory(outstandR:::calc_gcomp_ml)

#' @rdname calc_IPD_stats
#' @section G-computation Bayesian statistics:
#' Using Stan, compute marginal log-odds ratio for _A_ vs _C_ for each MCMC sample
#' Using Stan, compute marginal relative effects for IPD comparator "A" vs reference "C" treatment arms for each MCMC sample
#' by transforming from probability to linear predictor scale.
#' @export
#'
Expand Down
5 changes: 5 additions & 0 deletions R/calc_stc.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@

#' Calculate simulated treatment comparison statistics
#' @return A list:
#' \describe{
#' \item{`mean_A`}{Mean for comparator treatment group "A".}
#' \item{`mean_C`}{Mean for reference treatment group "C".}
#' }
#' @importFrom stats glm
#' @export
#'
Expand Down
Loading
Loading