predict.ss | R Documentation |
predict
method for class "ss".
## S3 method for class 'ss'
predict(object, x, deriv = 0, se.fit = TRUE, ...)
object |
a fit from |
x |
the new values of x. |
deriv |
integer; the order of the derivative required. |
se.fit |
a switch indicating if standard errors are required. |
... |
additional arguments affecting the prediction produced (currently ignored). |
Inspired by the predict.smooth.spline
function in R's stats package.
A list with components
x |
The input |
y |
The fitted values or derivatives at x. |
se |
The standard errors of the fitted values or derivatives (if requested). |
Nathaniel E. Helwig <helwig@umn.edu>
https://stat.ethz.ch/R-manual/R-devel/library/stats/html/predict.smooth.spline.html
Craven, P. and Wahba, G. (1979). Smoothing noisy data with spline functions: Estimating the correct degree of smoothing by the method of generalized cross-validation. Numerische Mathematik, 31, 377-403. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/BF01404567")}
Gu, C. (2013). Smoothing spline ANOVA models, 2nd edition. New York: Springer. \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1007/978-1-4614-5369-7")}
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
# 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)
# GCV selection (default)
ss.GCV <- ss(x, y, nknots = 10)
# get predictions and SEs (at design points)
fit <- predict(ss.GCV, x = x)
head(fit)
# compare to original fit
mean((fit$y - ss.GCV$y)^2)
# plot result (with default 95% CI)
plotci(fit)
# estimate first derivative
d1 <- 3 + 2 * pi * cos(2 * pi * x)
fit <- predict(ss.GCV, x = x, deriv = 1)
head(fit)
# plot result (with default 95% CI)
plotci(fit)
lines(x, d1, lty = 2) # truth
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.