From f8e3434ae94b47c0692f9a94a1875ab4a8aa54c2 Mon Sep 17 00:00:00 2001 From: Oskar Gauffin Date: Wed, 14 Feb 2024 12:57:03 +0100 Subject: [PATCH 1/2] expanded news 0.0.3 --- NEWS.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index e5c8928..12cc276 100644 --- a/NEWS.md +++ b/NEWS.md @@ -5,5 +5,5 @@ This is the first version of the package. Fixing a minor bug discovered by the CRAN checks. # version 0.0.3 -Fixing a bug where the group_by-variable was hard-coded as "group". From now, any group_by column name should work. +Fixing a bug where the group_by-variable was hard-coded as "group". From now, any group_by column name should work. Removed the export tag from a few internal functions for a cleaner reference manual. From 6e14170825948dadef6f8e4f90579c69dd5fcfb4 Mon Sep 17 00:00:00 2001 From: Oskar Gauffin Date: Fri, 16 Feb 2024 14:21:02 +0100 Subject: [PATCH 2/2] Added quality check on the IC025, unit test nr 19 --- tests/testthat/test-disprop_analysis.R | 61 ++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/tests/testthat/test-disprop_analysis.R b/tests/testthat/test-disprop_analysis.R index 2df72de..23d1f00 100644 --- a/tests/testthat/test-disprop_analysis.R +++ b/tests/testthat/test-disprop_analysis.R @@ -186,3 +186,64 @@ test_that("18. It's possible to name the group_by something else than 'group'", expect_equal(2L, ncol(summary_output)) }) + +test_that("19. The IC values match manually calculated IC-values", { + + report_dt <- + data.table::as.data.table(pvda::drug_event_df) |> + dplyr::select(report_id, drug, event) + + counts_dt <- + report_dt |> + dplyr::group_by(drug) |> + dplyr::mutate(n_drugs = dplyr::n_distinct(report_id)) |> + dplyr::group_by(event) |> + dplyr::mutate(n_events = dplyr::n_distinct(report_id)) |> + dplyr::distinct(drug, event, report_id, .keep_all = TRUE) |> + dplyr::group_by(drug, event, n_drugs, n_events) |> # Setting n_drugs and n_pts in the group_by preserves them in the count-step + dplyr::count(name="obs") + + # Need a total count, probably easiest to do it separately + n_tot <- + report_dt |> + dplyr::distinct(report_id) |> + dplyr::count() |> + dplyr::pull(n) + + # Calculate the 2.5th percentiles of the posterior + ic_dt <- + counts_dt |> + dplyr::mutate(n_tot = n_tot) |> + dplyr::mutate(exp = as.numeric(n_drugs)*as.numeric(n_events)/as.numeric(n_tot)) |> + dplyr::mutate(ic025 = log2(qgamma(0.025, obs + 0.5, exp + 0.5))) + + ic_dt |> + dplyr::mutate(sign = ifelse(ic025>0, TRUE, FALSE)) |> + dplyr::group_by(sign) |> + dplyr::count() + + ic_dt <- + ic_dt |> + dplyr::ungroup() |> + dplyr::select(drug, event, ic025) + + ############################################## + da1 <- pvda::drug_event_df |> pvda::da() + output_pvda <- da1$da_df |> dplyr::select(drug, event, ic2.5) + + compare_pvda_to_manual <- + ic_dt |> + dplyr::left_join(output_pvda, dplyr::join_by(drug==drug, event==event)) |> + dplyr::mutate(same = ifelse(round(ic025,2) == round(ic2.5,2), TRUE, FALSE)) + + all_the_same <- all(compare_pvda_to_manual$same) + + + + + + expect_equal(all_the_same, TRUE) +}) + + +