From cbebbd125b38984ef7a70cefbdef0f52faec3695 Mon Sep 17 00:00:00 2001 From: Dr Nathan Green Date: Fri, 19 Jun 2026 11:56:25 +0100 Subject: [PATCH] Update exercises2.qmd with calc_bucher_naive, fix outstandR undefined variables, and update unit tests --- NAMESPACE | 1 + R/outstandR.R | 8 +- man/calc_bucher_naive.Rd | 36 ++ man/outstandR-package.Rd | 2 +- man/plot.outstandR.Rd | 10 +- scripts/exercises2.html | 589 ++++++++++++------ scripts/exercises2.qmd | 33 +- .../figure-html/unnamed-chunk-12-1.png | Bin 25418 -> 26574 bytes .../figure-html/unnamed-chunk-14-1.png | Bin 22375 -> 22320 bytes .../figure-html/unnamed-chunk-25-1.png | Bin 25163 -> 25446 bytes .../figure-html/unnamed-chunk-9-1.png | Bin 25656 -> 26749 bytes scripts/practical_paic.pdf | Bin 0 -> 140217 bytes tests/testthat/test-gcomp.R | 4 +- tests/testthat/test-maicstc.R | 2 +- tests/testthat/test-mim.R | 4 +- 15 files changed, 474 insertions(+), 215 deletions(-) create mode 100644 man/calc_bucher_naive.Rd create mode 100644 scripts/practical_paic.pdf diff --git a/NAMESPACE b/NAMESPACE index 8dd026b..353643d 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -30,6 +30,7 @@ S3method(print,summary.outstandR) S3method(summary,outstandR) export(calc_ALD_stats) export(calc_IPD_stats) +export(calc_bucher_naive) export(calc_gcomp_bayes) export(calc_gcomp_ml) export(calculate_ate) diff --git a/R/outstandR.R b/R/outstandR.R index 8fe7b96..8e5be47 100644 --- a/R/outstandR.R +++ b/R/outstandR.R @@ -160,12 +160,12 @@ outstandR <- function(ipd_trial, ald_trial, strategy, stats <- result_stats(ipd_stats, ald_stats, CI) naive_results <- calc_bucher_naive( - ipd_trial = ipd_trial_clean, - ald_trial = ald_trial_clean, - outcome_model = strategy$formula$outcome_model, + ipd_trial = ipd_trial, + ald_trial = ald_trial, + outcome_model = strategy$outcome_model, family = strategy$family, ref_trt = ref_trt, - scale = scale_internal + scale = scale ) structure( diff --git a/man/calc_bucher_naive.Rd b/man/calc_bucher_naive.Rd new file mode 100644 index 0000000..3284700 --- /dev/null +++ b/man/calc_bucher_naive.Rd @@ -0,0 +1,36 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/calc_bucher_naive.R +\name{calc_bucher_naive} +\alias{calc_bucher_naive} +\title{Calculate Naive (Unadjusted) Bucher Indirect Comparison} +\usage{ +calc_bucher_naive( + ipd_trial, + ald_trial, + outcome_model, + family, + ref_trt = "C", + scale = NULL +) +} +\arguments{ +\item{ipd_trial}{Data frame containing the Individual Patient Data.} + +\item{ald_trial}{Data frame containing the Aggregate Level Data.} + +\item{outcome_model}{Formula specifying the outcome model (used to identify variables).} + +\item{family}{A family object (e.g., \code{binomial(link="logit")}).} + +\item{ref_trt}{Character string identifying the common comparator treatment.} + +\item{scale}{Character string specifying the desired output scale (e.g., "risk_difference").} +} +\value{ +A list containing the naive point estimate, variance, and standard error. +} +\description{ +Calculates the unadjusted indirect comparison between two active treatments +via a common comparator using the standard Bucher method. Estimates are calculated +on the link scale (e.g., log-odds) and back-transformed to the requested scale. +} diff --git a/man/outstandR-package.Rd b/man/outstandR-package.Rd index a645b08..1888188 100644 --- a/man/outstandR-package.Rd +++ b/man/outstandR-package.Rd @@ -18,7 +18,7 @@ Useful links: } \author{ -\strong{Maintainer}: Nathan Green \email{n.green@ucl.ac.uk} (\href{https://orcid.org/0000-0003-2745-1736}{ORCID}) (\href{https://ror.org/02jx3x895}{ROR}) [copyright holder] +\strong{Maintainer}: Nathan Green \email{n.green@ucl.ac.uk} (\href{https://orcid.org/0000-0003-2745-1736}{ORCID}) (02jx3x895) [copyright holder] Authors: \itemize{ diff --git a/man/plot.outstandR.Rd b/man/plot.outstandR.Rd index ae39f78..ba0bdce 100644 --- a/man/plot.outstandR.Rd +++ b/man/plot.outstandR.Rd @@ -4,7 +4,13 @@ \alias{plot.outstandR} \title{Default Plot Method for outstandR Objects} \usage{ -\method{plot}{outstandR}(x, ..., type = c("both", "contrasts", "absolute"), labels = NULL) +\method{plot}{outstandR}( + x, + ..., + type = c("both", "contrasts", "absolute"), + labels = NULL, + include_naive = TRUE +) } \arguments{ \item{x}{An object of class 'outstandR' or a list of 'outstandR' objects.} @@ -14,6 +20,8 @@ \item{type}{Character, one of "both" (default), "contrasts", or "absolute".} \item{labels}{Optional character vector of names for the models.} + +\item{include_naive}{Logical. Should naive (unadjusted) estimates be included in the plot? Default is TRUE.} } \value{ A \code{\link[ggplot2:ggplot]{ggplot2::ggplot()}} object representing the forest plot of the results. diff --git a/scripts/exercises2.html b/scripts/exercises2.html index 137136c..854ab4f 100644 --- a/scripts/exercises2.html +++ b/scripts/exercises2.html @@ -6,6 +6,7 @@ + Practical: Population-Adjusted Indirect Comparisons with outstandR