Skip to content

Commit

Permalink
Merge pull request #642 from easystats/cleanup-.clean_priors_and_post…
Browse files Browse the repository at this point in the history
…eriors.stanreg

Move some args into ...
  • Loading branch information
mattansb authored Feb 7, 2024
2 parents d29b70c + df3fcb7 commit bb68c2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
4 changes: 2 additions & 2 deletions R/bayesfactor_restricted.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ bayesfactor_restricted.stanreg <- function(posterior, hypothesis, prior = NULL,
component <- match.arg(component)

samps <- .clean_priors_and_posteriors(posterior, prior,
effects, component,
effects = effects, component = component,
verbose = verbose
)

Expand Down Expand Up @@ -217,7 +217,7 @@ bayesfactor_restricted.data.frame <- function(posterior, hypothesis, prior = NUL

posterior_l <- as.data.frame(lapply(p_hypothesis, .test_hypothesis, data = posterior))
prior_l <- as.data.frame(lapply(p_hypothesis, .test_hypothesis, data = prior))
colnames(posterior_l) <- colnames(prior_l) <- if (!is.null(names(hypothesis))) names(hypothesis) else hypothesis
colnames(posterior_l) <- colnames(prior_l) <- if (is.null(names(hypothesis))) hypothesis else names(hypothesis)

posterior_p <- sapply(posterior_l, mean)
prior_p <- sapply(prior_l, mean)
Expand Down
13 changes: 5 additions & 8 deletions R/utils_bayesfactor.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@

#' @keywords internal
.clean_priors_and_posteriors.stanreg <- function(posterior, prior,
effects, component,
parameters = NULL,
verbose = TRUE,
...) {
# Get Priors
Expand All @@ -30,8 +28,8 @@
insight::format_error(prior)
}

prior <- insight::get_parameters(prior, effects = effects, component = component, ...)
posterior <- insight::get_parameters(posterior, effects = effects, component = component, ...)
prior <- insight::get_parameters(prior, ...)
posterior <- insight::get_parameters(posterior, ...)

list(
posterior = posterior,
Expand Down Expand Up @@ -192,11 +190,10 @@

# Prior and post odds
Modelnames <- BFGrid$Model
if (!is.null(priorOdds)) {
priorOdds <- c(1, priorOdds)
} else {
priorOdds <- rep(1, length(Modelnames))
if (is.null(priorOdds)) {
priorOdds <- rep(1, length(Modelnames) - 1)
}
priorOdds <- c(1, priorOdds)

prior_logodds <- log(priorOdds)
posterior_logodds <- prior_logodds + BFGrid$log_BF
Expand Down

0 comments on commit bb68c2b

Please sign in to comment.