fitted: Extract Smooth Model Fitted Values

fittedR Documentation

Extract Smooth Model Fitted Values

Description

Extracts the fitted values from a fit smoothing spline (fit by ss), smooth model (fit by sm), or generalized smooth model (fit by gsm).

Usage

## S3 method for class 'ss'
fitted(object, ...)

## S3 method for class 'sm'
fitted(object, ...)

## S3 method for class 'gsm'
fitted(object, ...)

Arguments

object

an object of class "gsm" output by the gsm function, "sm" output by the sm function, or "ss" output by the ss function

...

other arugments (currently ignored)

Details

For objects of class ss, fitted values are predicted via predict(object, object$data$x)$y

For objects of class sm, fitted values are extracted via object$fitted.values

For objects of class gsm, fitted values are computed via ginv(object$linear.predictors) where ginv = object$family$linkinv

Value

Fitted values extracted (or predicted) from object

Author(s)

Nathaniel E. Helwig <helwig@umn.edu>

References

Chambers, J. M. and Hastie, T. J. (1992) Statistical Models in S. Wadsworth & Brooks/Cole.

Helwig, N. E. (2020). Multiple and Generalized Nonparametric Regression. In P. Atkinson, S. Delamont, A. Cernat, J. W. Sakshaug, & R. A. Williams (Eds.), SAGE Research Methods Foundations. doi: 10.4135/9781526421036885885

See Also

ss, sm, gsm

Examples

# generate data
set.seed(1)
n <- 100
x <- seq(0, 1, length.out = n)
fx <- 2 + 3 * x + sin(2 * pi * x)
y <- fx + rnorm(n, sd = 0.5)

# smoothing spline
mod.ss <- ss(x, y, nknots = 10)
fit.ss <- fitted(mod.ss)

# smooth model
mod.sm <- sm(y ~ x, knots = 10)
fit.sm <- fitted(mod.sm)

# generalized smooth model (family = gaussian)
mod.gsm <- gsm(y ~ x, knots = 10)
fit.gsm <- fitted(mod.gsm)

# compare fitted values
mean((fit.ss - fit.sm)^2)
mean((fit.ss - fit.gsm)^2)
mean((fit.sm - fit.gsm)^2)

npreg documentation built on July 21, 2022, 1:06 a.m.

Related to fitted in npreg...