From e05b16481732e88d166bdef21343e63c7f2d3b1b Mon Sep 17 00:00:00 2001 From: Indrajeet Patil Date: Thu, 5 Oct 2023 11:23:16 +0200 Subject: [PATCH] re-trigger CI to see if badges update --- R/bayesfactor_parameters.R | 71 +++++++++++++++++------------------ man/bayesfactor_parameters.Rd | 71 +++++++++++++++++------------------ man/sensitivity_to_prior.Rd | 19 +++------- 3 files changed, 75 insertions(+), 86 deletions(-) diff --git a/R/bayesfactor_parameters.R b/R/bayesfactor_parameters.R index ef9574b88..8e71399b4 100644 --- a/R/bayesfactor_parameters.R +++ b/R/bayesfactor_parameters.R @@ -113,54 +113,51 @@ #' Bayes factor smaller than 1/3 indicates substantial evidence in favor of the #' null-model) (\cite{Wetzels et al. 2011}). #' -#' @examples +#' @examplesIf require("logspline") #' library(bayestestR) -#' if (require("logspline")) { -#' prior <- distribution_normal(1000, mean = 0, sd = 1) -#' posterior <- distribution_normal(1000, mean = .5, sd = .3) -#' (BF_pars <- bayesfactor_parameters(posterior, prior, verbose = FALSE)) +#' prior <- distribution_normal(1000, mean = 0, sd = 1) +#' posterior <- distribution_normal(1000, mean = .5, sd = .3) +#' (BF_pars <- bayesfactor_parameters(posterior, prior, verbose = FALSE)) #' -#' as.numeric(BF_pars) -#' } +#' as.numeric(BF_pars) +#' +#' @examplesIf require("rstanarm") && require("emmeans") && require("logspline") #' \donttest{ #' # rstanarm models #' # --------------- -#' if (require("rstanarm") && require("emmeans") && require("logspline")) { -#' contrasts(sleep$group) <- contr.equalprior_pairs # see vingette -#' stan_model <- suppressWarnings(stan_lmer( -#' extra ~ group + (1 | ID), -#' data = sleep, -#' refresh = 0 -#' )) -#' bayesfactor_parameters(stan_model, verbose = FALSE) -#' bayesfactor_parameters(stan_model, null = rope_range(stan_model)) +#' contrasts(sleep$group) <- contr.equalprior_pairs # see vingette +#' stan_model <- suppressWarnings(stan_lmer( +#' extra ~ group + (1 | ID), +#' data = sleep, +#' refresh = 0 +#' )) +#' bayesfactor_parameters(stan_model, verbose = FALSE) +#' bayesfactor_parameters(stan_model, null = rope_range(stan_model)) #' -#' # emmGrid objects -#' # --------------- -#' group_diff <- pairs(emmeans(stan_model, ~group, data = sleep)) -#' bayesfactor_parameters(group_diff, prior = stan_model, verbose = FALSE) +#' # emmGrid objects +#' # --------------- +#' group_diff <- pairs(emmeans(stan_model, ~group, data = sleep)) +#' bayesfactor_parameters(group_diff, prior = stan_model, verbose = FALSE) #' -#' # Or -#' # group_diff_prior <- pairs(emmeans(unupdate(stan_model), ~group)) -#' # bayesfactor_parameters(group_diff, prior = group_diff_prior, verbose = FALSE) +#' # Or +#' # group_diff_prior <- pairs(emmeans(unupdate(stan_model), ~group)) +#' # bayesfactor_parameters(group_diff, prior = group_diff_prior, verbose = FALSE) #' } -#' +#' @examplesIf require("brms") && require("logspline") #' # brms models #' # ----------- -#' if (require("brms") && require("logspline")) { -#' contrasts(sleep$group) <- contr.equalprior_pairs # see vingette -#' my_custom_priors <- -#' set_prior("student_t(3, 0, 1)", class = "b") + -#' set_prior("student_t(3, 0, 1)", class = "sd", group = "ID") +#' contrasts(sleep$group) <- contr.equalprior_pairs # see vingette +#' my_custom_priors <- +#' set_prior("student_t(3, 0, 1)", class = "b") + +#' set_prior("student_t(3, 0, 1)", class = "sd", group = "ID") +#' +#' brms_model <- suppressWarnings(brm(extra ~ group + (1 | ID), +#' data = sleep, +#' prior = my_custom_priors, +#' refresh = 0 +#' )) +#' bayesfactor_parameters(brms_model, verbose = FALSE) #' -#' brms_model <- suppressWarnings(brm(extra ~ group + (1 | ID), -#' data = sleep, -#' prior = my_custom_priors, -#' refresh = 0 -#' )) -#' bayesfactor_parameters(brms_model, verbose = FALSE) -#' } -#' } #' @references #' \itemize{ #' \item Wagenmakers, E. J., Lodewyckx, T., Kuriyal, H., and Grasman, R. (2010). diff --git a/man/bayesfactor_parameters.Rd b/man/bayesfactor_parameters.Rd index 1eb285199..b9904d92b 100644 --- a/man/bayesfactor_parameters.Rd +++ b/man/bayesfactor_parameters.Rd @@ -260,53 +260,52 @@ null-model) (\cite{Wetzels et al. 2011}). } \examples{ +\dontshow{if (require("logspline")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(bayestestR) -if (require("logspline")) { - prior <- distribution_normal(1000, mean = 0, sd = 1) - posterior <- distribution_normal(1000, mean = .5, sd = .3) - (BF_pars <- bayesfactor_parameters(posterior, prior, verbose = FALSE)) +prior <- distribution_normal(1000, mean = 0, sd = 1) +posterior <- distribution_normal(1000, mean = .5, sd = .3) +(BF_pars <- bayesfactor_parameters(posterior, prior, verbose = FALSE)) - as.numeric(BF_pars) -} +as.numeric(BF_pars) +\dontshow{\}) # examplesIf} +\dontshow{if (require("rstanarm") && require("emmeans") && require("logspline")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ # rstanarm models # --------------- -if (require("rstanarm") && require("emmeans") && require("logspline")) { - contrasts(sleep$group) <- contr.equalprior_pairs # see vingette - stan_model <- suppressWarnings(stan_lmer( - extra ~ group + (1 | ID), - data = sleep, - refresh = 0 - )) - bayesfactor_parameters(stan_model, verbose = FALSE) - bayesfactor_parameters(stan_model, null = rope_range(stan_model)) +contrasts(sleep$group) <- contr.equalprior_pairs # see vingette +stan_model <- suppressWarnings(stan_lmer( + extra ~ group + (1 | ID), + data = sleep, + refresh = 0 +)) +bayesfactor_parameters(stan_model, verbose = FALSE) +bayesfactor_parameters(stan_model, null = rope_range(stan_model)) - # emmGrid objects - # --------------- - group_diff <- pairs(emmeans(stan_model, ~group, data = sleep)) - bayesfactor_parameters(group_diff, prior = stan_model, verbose = FALSE) +# emmGrid objects +# --------------- +group_diff <- pairs(emmeans(stan_model, ~group, data = sleep)) +bayesfactor_parameters(group_diff, prior = stan_model, verbose = FALSE) - # Or - # group_diff_prior <- pairs(emmeans(unupdate(stan_model), ~group)) - # bayesfactor_parameters(group_diff, prior = group_diff_prior, verbose = FALSE) +# Or +# group_diff_prior <- pairs(emmeans(unupdate(stan_model), ~group)) +# bayesfactor_parameters(group_diff, prior = group_diff_prior, verbose = FALSE) } - +\dontshow{\}) # examplesIf} +\dontshow{if (require("brms") && require("logspline")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # brms models # ----------- -if (require("brms") && require("logspline")) { - contrasts(sleep$group) <- contr.equalprior_pairs # see vingette - my_custom_priors <- - set_prior("student_t(3, 0, 1)", class = "b") + - set_prior("student_t(3, 0, 1)", class = "sd", group = "ID") +contrasts(sleep$group) <- contr.equalprior_pairs # see vingette +my_custom_priors <- + set_prior("student_t(3, 0, 1)", class = "b") + + set_prior("student_t(3, 0, 1)", class = "sd", group = "ID") - brms_model <- suppressWarnings(brm(extra ~ group + (1 | ID), - data = sleep, - prior = my_custom_priors, - refresh = 0 - )) - bayesfactor_parameters(brms_model, verbose = FALSE) -} -} +brms_model <- suppressWarnings(brm(extra ~ group + (1 | ID), + data = sleep, + prior = my_custom_priors, + refresh = 0 +)) +bayesfactor_parameters(brms_model, verbose = FALSE) +\dontshow{\}) # examplesIf} } \references{ \itemize{ diff --git a/man/sensitivity_to_prior.Rd b/man/sensitivity_to_prior.Rd index 3602bee73..99da2ac3a 100644 --- a/man/sensitivity_to_prior.Rd +++ b/man/sensitivity_to_prior.Rd @@ -30,26 +30,19 @@ antagonistic prior (a prior of same shape located on the opposite of the effect). } \examples{ +\dontshow{if (require("rstanarm")) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} \donttest{ library(bayestestR) # rstanarm models # ----------------------------------------------- -if (require("rstanarm")) { - model <- rstanarm::stan_glm(mpg ~ wt, data = mtcars) - sensitivity_to_prior(model) +model <- rstanarm::stan_glm(mpg ~ wt, data = mtcars) +sensitivity_to_prior(model) - model <- rstanarm::stan_glm(mpg ~ wt + cyl, data = mtcars) - sensitivity_to_prior(model, index = c("Median", "MAP")) -} - -# brms models -# ----------------------------------------------- -if (require("brms")) { - model <- brms::brm(mpg ~ wt + cyl, data = mtcars) - # sensitivity_to_prior(model) -} +model <- rstanarm::stan_glm(mpg ~ wt + cyl, data = mtcars) +sensitivity_to_prior(model, index = c("Median", "MAP")) } +\dontshow{\}) # examplesIf} } \seealso{ DescTools