local_slope: Calculate the local slope of a smooth term using finite...

View source: R/local_slope.R

local_slopeR Documentation

Calculate the local slope of a smooth term using finite differences

Description

Calculate the local slope of a smooth term using finite differences

Usage

local_slope(
  input,
  object,
  x_var,
  epsilon = 0.001,
  smooth,
  g_var = NULL,
  add_vars = NULL,
  pts = 200,
  ...
)

Arguments

input

A dataframe for which to generate model predictions.

object

A brms model object.

x_var

The predictor associated with the selected smooth term.

epsilon

The increment on which to generate differences.

smooth

The smooth term for which to calculate local slopes. Passed on to brms::posterior_smooths().

g_var

An optional grouping variable for factor-smooth interactions.

add_vars

In older versions of brms, brms::posterior_smooths() required that all variables used in constructing the autocorrelation term are also included in newdata arg... even if they are not used in the smooth. Add them here as a named list of new columns; if they don't appear in the smooth, they won't contribute to the output.

pts

Number of points at which to estimate the slope.

...

Additional arguments passed to brms::posterior_smooths().

Value

A tibble containing the (tidy) output of brms::posterior_smooth() and the calculated slopes.

Examples

library("brms")
seed <- 1
data_gam <- read.csv(paste0(system.file("extdata", package = "bgamcar1"), "/data_gam.csv"))
fit <- fit_stan_model(
  paste0(system.file("extdata", package = "bgamcar1"), "/test_gam"),
  seed,
  bf(y ~ s(x0) + s(x1) + s(x2) + s(x3)),
  data_gam,
  car1 = FALSE,
  chains = 2
)
local_slope(data_gam, fit, "x2", smooth = "s(x2)")


bentrueman/bgamcar1 documentation built on July 6, 2024, 11:16 p.m.