Skip to contents

A penalised-spline alternative to the kernel methods above. Fits y ~ s(x, k = k) and returns fitted values at x_eval.

Usage

gam_smoother(x, y, x_eval = NULL, k = 10, family = stats::gaussian())

Arguments

x

Numeric covariate vector.

y

Numeric outcome vector.

x_eval

Evaluation grid (defaults to x).

k

Basis dimension for the smoother (default 10).

family

"gaussian", "binomial" or "poisson", or the matching family object (default gaussian()).

Value

A list with fit (the morie_gam fit), x_eval, y_hat (predictions), and edf (effective degrees of freedom).

Examples

set.seed(1)
x <- sort(runif(40, -2, 2))
y <- sin(x) + 0.2 * rnorm(40)
xe <- seq(-1.5, 1.5, length.out = 20)
r <- gam_smoother(x, y, x_eval = xe, k = 5)
head(r$y_hat)
#> [1] -0.9758711 -0.9677393 -0.9382220 -0.8824321 -0.7990993 -0.6891930