Description Usage Arguments Details Value Examples
View source: R/piecewise_cors.R
Independently for each variable of interest ...
and .target
, calculate
the piecewise correlation. Observations included for each correlation
calculation are segmented based on local extrema (minima / maxima) of the
smoothed model fit.
1 2 3 4 5 6 7 8 | piecewise_cors(
data,
.target,
...,
custom_model_spec = NULL,
fit_formula = ".target ~ s(...)",
cor_function = "~cor(.x, method = 'spearman')[2,1]"
)
|
data |
Dataframe containing columns of interest. |
.target |
Column name of target (unquoted). Numeric with sufficient unique observations. |
... |
Column names of variables of interest (unquoted), or a tidy
selection specification (see:
https://dplyr.tidyverse.org/reference/select.html). Separate models are
created for each variable passed into |
custom_model_spec |
parsnip::gen_additive_mod() %>% parsnip::set_engine("mgcv", method = "REML") %>% parsnip::set_mode("regression") (At this point) must be a generalized additive model with |
fit_formula |
Character string. Pseudo representation of formula passed
to |
cor_function |
Character string of a lambda function passed to
Should be written in tidyverse friendly shortcut lambda notation (like
above), as opposed to traditional lambda function notation: Must evaluate to a numeric vector of length one. Could pass in functions specification unrelated to correlation. |
If the smoothing model has no local minima / maxima, correlation is calculated across all observations.
Named list of named list of models $mods
and named list of
dataframes $cors
for each variable of interest specified in ...
. Each
dataframe in .cors
has the columns:
gtoe
: (greater than or equal to)
lt
: (less than)
data
: list column containing dataframes of observations within segment
n_obs
: number of rows in data
segment
cor
: value returned by cor_function
for segment of observations
1 | # See README
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.