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
1 change: 1 addition & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions R/outstandR.R
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
36 changes: 36 additions & 0 deletions man/calc_bucher_naive.Rd

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

2 changes: 1 addition & 1 deletion man/outstandR-package.Rd

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

10 changes: 9 additions & 1 deletion man/plot.outstandR.Rd

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

589 changes: 390 additions & 199 deletions scripts/exercises2.html

Large diffs are not rendered by default.

33 changes: 28 additions & 5 deletions scripts/exercises2.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,24 @@ prob_C_raw_BC <- BC_ALD_binY_contX |>
pull(value)

# 3. Naive Anchored Risk Difference
naive_anchored_rd <- (prob_A_raw - prob_C_raw_AC) - (prob_B_raw - prob_C_raw_BC)
# Explicit manual calculation (direct subtraction):
naive_anchored_rd_explicit <- (prob_A_raw - prob_C_raw_AC) - (prob_B_raw - prob_C_raw_BC)

# Or using outstandR's built-in calc_bucher_naive() function:
# This calculates it on the log-odds scale and back-transforms, which is HTA best practice.
naive_results_pkg <- calc_bucher_naive(
ipd_trial = AC_IPD_binY_contX,
ald_trial = BC_ALD_binY_contX,
outcome_model = lin_form_bin,
family = binomial(link = "logit"),
ref_trt = "C",
scale = "risk_difference"
)
naive_anchored_rd <- naive_results_pkg$Estimate

# Note: You can also extract this directly from any of the outstandR output objects
# since the naive Bucher comparison is run automatically under the hood:
# naive_anchored_rd <- out_maic_rd$naive$Estimate

# 4. Extract and bind results
adjusted_results <- data.frame(
Expand Down Expand Up @@ -440,9 +457,6 @@ ggplot(data.frame(weights = out_maic$model$weights), aes(x = weights)) +

If a large percentage of your weights are near zero, your MAIC estimates may be highly unstable, suggesting poor covariate overlap between your IPD and target population.

<<<<<<< HEAD
2.\ Next, let's explore the Bias-Variance trade-off by running a minimal, correctly specified MAIC balancing *only one* the effect modifiers.
=======
2.\ Fit a deliberately misspecified G-computation model to observe the consequences. We will purposefully drop the `trt:EM` interaction terms.

```{r}
Expand All @@ -466,7 +480,6 @@ cat("Correct ML G-comp Risk Difference (A vs B):", out_gcomp_ml_rd$results$contr
```

3.\ Next, let's explore the Bias-Variance trade-off by running a minimal, correctly specified MAIC balancing *only one* effect modifier.
>>>>>>> f052889ab1209f78958e28b82c66c95af339a23c

```{r}
#| echo: true
Expand Down Expand Up @@ -625,6 +638,16 @@ prob_A_naive <- odds_A_naive / (1 + odds_A_naive)

naive_anchored_rd <- prob_A_naive - prob_B_raw

# Alternatively, the above back-transformation can be done in one line using calc_bucher_naive():
# naive_anchored_rd <- calc_bucher_naive(
# ipd_trial = AC_IPD_binY_contX,
# ald_trial = BC_ALD_binY_contX,
# outcome_model = lin_form_bin,
# family = binomial(link = "logit"),
# ref_trt = "C",
# scale = "risk_difference"
# )$Estimate

# 5. Naive Unanchored Risk Difference
# A simple unadjusted direct comparison of A vs B
naive_unanchored_rd <- prob_A_raw - prob_B_raw
Expand Down
Binary file modified scripts/exercises2_files/figure-html/unnamed-chunk-12-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scripts/exercises2_files/figure-html/unnamed-chunk-14-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scripts/exercises2_files/figure-html/unnamed-chunk-25-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified scripts/exercises2_files/figure-html/unnamed-chunk-9-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added scripts/practical_paic.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions tests/testthat/test-gcomp.R
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ test_that("different combinations of covariates in formula", {
ald_trial = BC_ALD,
strategy = strat_1234)

expect_length(res, 13)
expect_length(res, 14)
# expect_equal(outstandR(AC_IPD, BC_ALD, strategy = strat_31))
# expect_equal(outstandR(AC_IPD, BC_ALD, strategy = strat_13))
# expect_equal(outstandR(AC_IPD, BC_ALD, strategy = strat_1))
Expand Down Expand Up @@ -67,7 +67,7 @@ test_that("different combinations of covariates in formula", {
ald_trial = BC_ALD,
strategy = strat_1234)

expect_length(res, 13)
expect_length(res, 14)

# expect_equal(outstandR(AC_IPD, BC_ALD, strategy = strat_31))
# expect_equal(outstandR(AC_IPD, BC_ALD, strategy = strat_13))
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-maicstc.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ test_that("different combinations of covariates in formula MAIC", {
formula = list(balance_model = as.formula("~ X1")))

res <- outstandR(AC_IPD, BC_ALD, strategy = strat_1234)
expect_length(res, 13)
expect_length(res, 14)

res <- outstandR(AC_IPD, BC_ALD, strategy = strat_123)

Expand Down
4 changes: 2 additions & 2 deletions tests/testthat/test-mim.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ test_that("different combinations of covariates in formula", {

out_1234 <- outstandR(AC_IPD, BC_ALD, strategy = strat_1234)

expect_length(out_1234, 13)
expect_length(out_1234, 14)

expect_named(out_1234, expected =
c("results", "call",
c("results", "naive", "call",
"outcome_model", "balance_model", "formula",
"CI", "ref_trt", "ipd_comp",
"ald_comp", "scale", "var_method", "family", "model"))
Expand Down
Loading