local_slope | R Documentation |
Calculate the local slope of a smooth term using finite differences
local_slope(
input,
object,
x_var,
epsilon = 0.001,
smooth,
g_var = NULL,
add_vars = NULL,
pts = 200,
...
)
input |
A dataframe for which to generate model predictions. |
object |
A |
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 |
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 |
A tibble
containing the (tidy) output of brms::posterior_smooth()
and the calculated slopes.
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)")
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.