Skip to contents

frmtmb::conditional_smooths() on draws from frm_sample(): each smooth term over its grid once per draw, summarized the way brms summarizes it. estimate__ is the median of the drawn curves, se__ their median absolute deviation, and lower__ and upper__ their quantiles at prob. The grid, the keys and the columns are core's, so the frame has the layout of the fit method's.

spaghetti = TRUE adds brms's "spaghetti" attribute: the grid once per draw, stacked, with that draw's curve in estimate__ and the draw in sample__. brms adds it only for a term whose first covariate is numeric and that is not drawn as a surface, and so does this method.

Draws from frm_sample(laplace = TRUE) are refused: they hold no penalized smooth coefficients.

Usage

# S3 method for class 'frmtmb_draws'
conditional_smooths(
  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,
  ...
)

Arguments

x

A frmtmb_draws object.

smooths

Character vector of the terms to draw, as written in the formula (whitespace does not matter): "s(x)", "s(z, by = f)". NULL (the default) draws every smooth term.

int_conditions

Named list of the values a covariate takes, as in conditional_effects().

prob

Coverage of the band.

spaghetti

TRUE adds one curve per posterior draw as the attribute "spaghetti", for a term whose first covariate is numeric and that is not drawn as a surface. A maximum-likelihood fit has no draws and refuses it.

surface

Whether a term of two numeric covariates is drawn as a surface over both. FALSE draws the second covariate as a moderator at three values.

resolution

Number of grid points for a varied numeric covariate.

too_far

For a surface: remove grid points farther than this from the data, on the unit square. 0 (the default) keeps all.

ndraws, draw_ids

For draws: how many evenly spaced draws, or which draws, to use. A maximum-likelihood fit refuses both.

nsamples, subset

brms's deprecated spellings of ndraws and draw_ids.

probs

brms's deprecated spelling of the two band quantiles, which replaces prob with a warning.

...

Refused by name.

Examples

# \donttest{
if (requireNamespace("tmbstan", quietly = TRUE) &&
    requireNamespace("rstan", quietly = TRUE) &&
    !frmtmb.sample:::tmbstan_build_broken()) {
  set.seed(1)
  dd <- data.frame(x = runif(80))
  dd$y <- sin(2 * pi * dd$x) + rnorm(80, 0, 0.3)
  ds <- frm_sample(bf(y ~ s(x)), family = gaussian(), data = dd,
                   chains = 1, iter = 400, seed = 1, refresh = 0)
  cs <- conditional_smooths(ds, spaghetti = TRUE, ndraws = 20)
  nrow(attr(cs[["mu: s(x)"]], "spaghetti"))
}
#> frm_sample(): default priors (brms 2.23 defaults; prior = "flat" puts brms's (flat) in every slot)
#>   Intercept          student_t(3, 0, 2.5)
#>   sigma              student_t(3, 0, 2.5)  [natural scale]
#>   sds                student_t(3, 0, 2.5)  [natural sd scale]
#>   b                  (flat), as brms leaves slopes
#> Warning: Bulk Effective Samples Size (ESS) is too low, indicating posterior means and medians may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#bulk-ess
#> Warning: Tail Effective Samples Size (ESS) is too low, indicating posterior variances and tail quantiles may be unreliable.
#> Running the chains for more iterations may help. See
#> https://mc-stan.org/misc/warnings.html#tail-ess
#> [1] 2000
# }