| residuals | R Documentation |
Extracts the residuals from a fit smoothing spline ("ss"), smooth model ("sm"), or generalized smooth model ("gsm") object.
## S3 method for class 'ss'
residuals(object, type = c("working", "response", "deviance",
"pearson", "partial"), ...)
## S3 method for class 'sm'
residuals(object, type = c("working", "response", "deviance",
"pearson", "partial"), ...)
## S3 method for class 'gsm'
residuals(object, type = c("deviance", "pearson", "working",
"response", "partial"), ...)
object |
an object of class "ss", "sm", or "gsm" |
type |
type of residuals |
... |
other arugments (currently ignored) |
For objects of class ss and sm
* the working and response residuals are defined as 'observed - fitted'
* the deviance and Pearson residuals multiply the working residuals by sqrt(weights(object))
For objects of class gsm, the residual types are the same as those produced by the residuals.glm function
Residuals from object
Nathaniel E. Helwig <helwig@umn.edu>
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. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.4135/9781526421036885885")}
ss, sm, gsm
# 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)
res.ss <- residuals(mod.ss)
# smooth model
mod.sm <- sm(y ~ x, knots = 10)
res.sm <- residuals(mod.sm)
# generalized smooth model (family = gaussian)
mod.gsm <- gsm(y ~ x, knots = 10)
res.gsm <- residuals(mod.gsm)
# y = fitted + residuals
mean((y - fitted(mod.ss) - res.ss)^2)
mean((y - fitted(mod.sm) - res.sm)^2)
mean((y - fitted(mod.gsm) - res.gsm)^2)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.