Skip to content

Commit

Permalink
allow argument surface in conditional_smooths
Browse files Browse the repository at this point in the history
  • Loading branch information
paul-buerkner committed Oct 2, 2024
1 parent 481744d commit 39e6588
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ Package: brms
Encoding: UTF-8
Type: Package
Title: Bayesian Regression Models using 'Stan'
Version: 2.22.1
Date: 2024-09-24
Version: 2.22.2
Date: 2024-10-02
Authors@R:
c(person("Paul-Christian", "Bürkner", email = "[email protected]",
role = c("aut", "cre")),
Expand Down
16 changes: 13 additions & 3 deletions R/conditional_smooths.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
#' @param smooths Optional character vector of smooth terms
#' to display. If \code{NULL} (the default) all smooth terms
#' are shown.
#' @param surface Logical. Indicates if interactions or
#' two-dimensional smooths should be visualized as a surface.
#' Defaults to \code{TRUE}. The surface type can be controlled
#' via argument \code{stype} of the related plotting method.
#' @param ndraws Positive integer indicating how many
#' posterior draws should be used.
#' If \code{NULL} (the default) all draws are used.
Expand Down Expand Up @@ -49,12 +53,14 @@
conditional_smooths.brmsfit <- function(x, smooths = NULL,
int_conditions = NULL,
prob = 0.95, spaghetti = FALSE,
surface = TRUE,
resolution = 100, too_far = 0,
ndraws = NULL, draw_ids = NULL,
nsamples = NULL, subset = NULL,
probs = NULL, ...) {
probs <- validate_ci_bounds(prob, probs = probs)
spaghetti <- as_one_logical(spaghetti)
surface <- as_one_logical(surface)
draw_ids <- use_alias(draw_ids, subset)
ndraws <- use_alias(ndraws, nsamples)
contains_draws(x)
Expand All @@ -68,7 +74,7 @@ conditional_smooths.brmsfit <- function(x, smooths = NULL,
bterms, fit = x, smooths = smooths,
conditions = conditions, int_conditions = int_conditions,
too_far = too_far, resolution = resolution, probs = probs,
spaghetti = spaghetti, draw_ids = draw_ids
spaghetti = spaghetti, surface = surface, draw_ids = draw_ids
)
if (!length(out)) {
stop2("No valid smooth terms found in the model.")
Expand Down Expand Up @@ -118,7 +124,7 @@ conditional_smooths.brmsterms <- function(x, ...) {
#' @export
conditional_smooths.btl <- function(x, fit, smooths, conditions, int_conditions,
probs, resolution, too_far, spaghetti,
...) {
surface, ...) {
stopifnot(is.brmsfit(fit))
out <- list()
mf <- model.frame(fit)
Expand All @@ -139,7 +145,11 @@ conditional_smooths.btl <- function(x, fit, smooths, conditions, int_conditions,
covars <- all_vars(sub_smframe$covars[[1]])
byvars <- all_vars(sub_smframe$byvars[[1]])
ncovars <- length(covars)
if (ncovars > 2L) {
if (!surface && ncovars > 1L) {
byvars <- c(covars[2:ncovars], byvars)
covars <- covars[1]
ncovars <- 1L
} else if (ncovars > 2L) {
byvars <- c(covars[3:ncovars], byvars)
covars <- covars[1:2]
ncovars <- 2L
Expand Down
6 changes: 6 additions & 0 deletions man/conditional_smooths.brmsfit.Rd

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

0 comments on commit 39e6588

Please sign in to comment.