From 7a126c52e733fbcbb655ae42cafb7dfd28aa3432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Iv=C3=A1n=20Guti=C3=A9rrez?= Date: Wed, 17 Apr 2024 17:44:34 -0400 Subject: [PATCH] Implement `joint_significance_probability()`. --- DESCRIPTION | 3 ++- R/joint_significance_probability.R | 15 +++++++++++++++ extra/demo_bernoulli.R | 3 +++ extra/demo_berpoi.R | 3 +++ extra/demo_normal.R | 3 +++ 5 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 R/joint_significance_probability.R diff --git a/DESCRIPTION b/DESCRIPTION index 54ef2c9..08fbd68 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -15,7 +15,8 @@ Imports: dplyr (>= 1.0.7), ggplot2 (>= 3.3.5), JuliaConnectoR (>= 1.0.0), - rlang (>= 0.4.11) + rlang (>= 0.4.11), + tidyr (>= 1.0.0) Encoding: UTF-8 LazyData: true Roxygen: list(markdown = TRUE) diff --git a/R/joint_significance_probability.R b/R/joint_significance_probability.R new file mode 100644 index 0000000..0657b3e --- /dev/null +++ b/R/joint_significance_probability.R @@ -0,0 +1,15 @@ +#' Compute the posterior probability of having at least one relevant factor +#' +#' @param fit An object of class anova_bnp_model. +#' @return The corresponding probability. +#' @export +joint_significance_probability <- function(fit) { + prob <- + fit$gamma_post |> + dplyr::arrange(dplyr::pick(dplyr::starts_with("group"))) |> + dplyr::slice_head(n = 1) |> + tidyr::pivot_longer(-prob) |> + dplyr::summarise(prob = mean(prob) * all(!value)) + out <- 1 - prob + return(out) +} diff --git a/extra/demo_bernoulli.R b/extra/demo_bernoulli.R index f15602f..78a1166 100644 --- a/extra/demo_bernoulli.R +++ b/extra/demo_bernoulli.R @@ -19,3 +19,6 @@ group_codes(fit) # Show the posterior distribution of gamma gamma_post(fit) + +# Perform our Dunnet-like test +joint_significance_probability(fit) diff --git a/extra/demo_berpoi.R b/extra/demo_berpoi.R index ce9d409..46aec54 100644 --- a/extra/demo_berpoi.R +++ b/extra/demo_berpoi.R @@ -19,3 +19,6 @@ group_codes(fit) # Show the posterior distribution of gamma gamma_post(fit) + +# Perform our Dunnet-like test +joint_significance_probability(fit) diff --git a/extra/demo_normal.R b/extra/demo_normal.R index 1a726db..72234b6 100644 --- a/extra/demo_normal.R +++ b/extra/demo_normal.R @@ -19,3 +19,6 @@ group_codes(fit) # Show the posterior distribution of gamma gamma_post(fit) + +# Perform our Dunnet-like test +joint_significance_probability(fit)