| nl_knots | R Documentation |
Performs a grid search over candidate degrees of freedom (df) for a
natural cubic spline ("ns") or B-spline ("bs") model and
selects the best value by an information criterion (AIC or BIC). A
diagnostic plot of the criterion against df is returned.
This function is called internally by nl_fit when
df = "auto", but it can also be called directly for exploration
before fitting the final model.
nl_knots(
data,
y,
x,
time = NULL,
cluster = NULL,
nested = FALSE,
controls = NULL,
method = c("ns", "bs"),
df_range = 2:10,
criterion = c("AIC", "BIC"),
family = stats::gaussian(),
plot = TRUE,
...
)
data |
A data frame. |
y |
Outcome variable name (string). |
x |
Focal predictor name (string). |
time |
Optional time variable name. |
cluster |
Optional character vector of cluster variable names. |
nested |
Logical; nested clustering. Default |
controls |
Optional character vector of control variable names. |
method |
Either |
df_range |
Integer vector of candidate df values. Default |
criterion |
Either |
family |
A family object. Default |
plot |
Logical; if |
... |
Additional arguments passed to the underlying fitter. |
A list with:
best_dfThe df value with the lowest criterion value.
search_tableData frame with columns df and
criterion.
criterionThe criterion used ("AIC" or
"BIC").
plotA ggplot object (if plot = TRUE).
nl_fit, nl_compare
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.