v_s: Create splines for use in vglmer

View source: R/spline_functions.R

v_sR Documentation

Create splines for use in vglmer

Description

This function estimates splines in vglmer, similar to s(...) in mgcv albeit with many fewer options than mgcv. It allows for truncated (linear) splines (type="tpf"), O'Sullivan splines (type="o"), or kernel ridge regression (type="gKRLS"). Please see vglmer for more discussion and examples. For information on kernel ridge regression, please consult gKRLS.

Usage

v_s(
  ...,
  type = "tpf",
  knots = NULL,
  by = NA,
  xt = NULL,
  by_re = TRUE,
  force_vector = FALSE,
  outer_okay = FALSE
)

Arguments

...

Variable name, e.g. v_s(x)

type

Default ("tpf") uses truncated linear splines for the basis. "o" uses O'Sullivan splines (Wand and Ormerod 2008). Smoothing across multiple covariates, e.g. v_s(x,x2,type="gKRLS"), can be done using kernel ridge regression. Chang and Goplerud (2024) provide a detailed discussion. Note that "gKRLS" by default uses random sketching to create the relevant bases and thus a seed would need to be set to ensure exact replicability.

knots

Default (NULL) uses K=min(N/4,35) knots evenly spaced at quantiles of the covariate x. A single number specifies a specific number of knots; a vector can set custom locations for knots.

by

A categorical or factor covariate to interact the spline with; for example, v_s(x, by = g).

xt

Arguments passed to xt from mgcv; at the moment, this is only used for type="gKRLS" to pass the function gKRLS(). Please see the documentation of gKRLS for more details.

by_re

Default (TRUE) regularizes the interactions between the categorical factor and the covariate. See "Details" in vglmer for more discussion.

force_vector

Force that argument to knots is treated as vector. This is usually not needed unless knots is a single integer that should be treated as a single knot (vs. the number of knots).

outer_okay

Default (FALSE) does not permit values in x to exceed the outer knots.

Value

This function returns a list of class of vglmer_spline that is passed to unexported functions. It contains the arguments noted above where ... is parsed into an argument called term.

References

Chang, Qing, and Max Goplerud. 2024. "Generalized Kernel Regularized Least Squares." Political Analysis 32(2):157-171.

Wand, Matt P. and Ormerod, John T. 2008. "On Semiparametric Regression with O'Sullivan Penalized Splines". Australian & New Zealand Journal of Statistics. 50(2): 179-198.

Wood, Simon N. 2017. Generalized Additive Models: An Introduction with R. Chapman and Hall/CRC.


vglmer documentation built on Sept. 13, 2024, 1:11 a.m.