Description Usage Arguments Details Value Methods Note Author(s) References See Also Examples
Fits a smoothing spline with the smoothing parameter selected via one of eight methods: GCV, OCV, GACV, ACV, REML, ML, AIC, or BIC.
1 2 3 4 5  ss(x, y = NULL, w = NULL, df, spar = NULL, lambda = NULL,
method = c("GCV", "OCV", "GACV", "ACV", "REML", "ML", "AIC", "BIC"),
m = 2L, periodic = FALSE, all.knots = FALSE, nknots = .nknots.smspl,
knots = NULL, keep.data = TRUE, df.offset = 0, penalty = 1,
control.spar = list(), tol = 1e6 * IQR(x), bernoulli = TRUE)

x 
Predictor vector of length n. Can also input a list or a twocolumn matrix specifying x and y. 
y 
Response vector of length n. If y is missing or NULL, the responses are assumed to be specified by x, with x the index vector. 
w 
Weights vector of length n. Defaults to all 1. 
df 
Equivalent degrees of freedom (trace of the smoother matrix). Must be in [m,nx], where nx is the number of unique x values, see below. 
spar 
Smoothing parameter. Typically (but not always) in the range (0,1]. If specified 
lambda 
Computational smoothing parameter. This value is weighted by n to form the penalty coefficient (see Details). Ignored if 
method 
Method for selecting the smoothing parameter. Ignored if 
m 
Penalty order (integer). The penalty functional is the integrated squared mth derivative of the function. Defaults to m = 2, which is a cubic smoothing spline. Set m = 1 for a linear smoothing spline or m = 3 for a quintic smoothing spline. 
periodic 
Logical. If 
all.knots 
If 
nknots 
Positive integer or function specifying the number of knots. Ignored if either 
knots 
Vector of knot values for the spline. Should be unique and within the range of the x values (to avoid a warning). 
keep.data 
Logical. If 
df.offset 
Allows the degrees of freedom to be increased by 
penalty 
The coefficient of the penalty for degrees of freedom in the GCV criterion. 
control.spar 
Optional list with named components controlling the root finding when the smoothing parameter spar is computed, i.e., missing or NULL, see below. Note that spar is only searched for in the interval [lower, upper].

tol 
Tolerance for sameness or uniqueness of the x values. The values are binned into bins of size tol and values which fall into the same bin are regarded as the same. Must be strictly positive (and finite). 
bernoulli 
If 
Inspired by the smooth.spline
function in R's stats package.
Neither x
nor y
are allowed to containing missing or infinite values.
The x
vector should contain at least 2m distinct values. 'Distinct' here is controlled by tol
: values which are regarded as the same are replaced by the first of their values and the corresponding y
and w
are pooled accordingly.
Unless lambda
has been specified instead of spar
, the computational λ used (as a function of spar
) is λ = 256^(3*(spar  1)).
If spar
and lambda
are missing or NULL
, the value of df
is used to determine the degree of smoothing. If df
is missing as well, the specified method
is used to determine λ.
Letting f_i = f(x_i), the function is represented as
f = X β + Z γ
where the basis functions in X span the null space (i.e., functions with mth derivative of zero), and Z contains the reproducing kernel function of the contrast space evaluated at all combinations of observed data points and knots, i.e., Z[i,j] = ρ(x_i, k_j) where ρ is the kernel function and k_j is the jth knot. The vectors β and γ contain unknown basis function coefficients. Letting M = (X, Z) and θ = (β', γ')', the penalized least squares problem has the form
(y  M θ)' W (y  M θ) + n λ γ' Q γ
where W is a diagonal matrix containg the weights, and Q is the penalty matrix. Note that Q[i,j] = ρ(k_i, k_j) contains the reproducing kernel function evaluated at all combinations of knots. The optimal coefficients are the solution to
(M' W M + n λ P) θ = M' W y
where P is the penalty matrix Q augmented with zeros corresponding to the β in θ.
An object of class "ss" with components:
x 
the distinct 
y 
the fitted values corresponding to 
w 
the weights used at the unique values of 
yin 
the 
tol 
the 
data 
only if keep.data = TRUE: itself a list with components 
lev 
leverages, the diagonal values of the smoother matrix. 
cv.crit 
crossvalidation score. 
pen.crit 
the penalized criterion, a nonnegative number; simply the (weighted) residual sum of squares (RSS). 
crit 
the criterion value minimized in the underlying 
df 
equivalent degrees of freedom used. 
spar 
the value of 
lambda 
the value of λ corresponding to 
fit 
list for use by

call 
the matched call. 
sigma 
estimated error standard deviation. 
logLik 
loglikelihood (if 
aic 
Akaike's Information Criterion (if 
bic 
Bayesian Information Criterion (if 
penalty 
smoothness penalty γ' Q γ, which is the integrated squared mth derivative of the estimated function f(x). 
method 
smoothing parameter selection method. Will be 
The smoothing parameter can be selected using one of eight methods:
Generalized CrossValidation (GCV)
Ordinary CrossValidation (OCV)
Generalized Approximate CrossValidation (GACV)
Approximate CrossValidation (ACV)
Restricted Maximum Likelihood (REML)
Maximum Likelihood (ML)
Akaike's Information Criterion (AIC)
Bayesian Information Criterion (BIC)
The number of unique x values, nx, are determined by the tol argument, equivalently to
nx < sum(!duplicated( round((x  mean(x)) / tol) ))
In this case where not all unique x values are used as knots, the result is not a smoothing spline in the strict sense, but very close unless a small smoothing parameter (or large df
) is used.
Nathaniel E. Helwig <helwig@umn.edu>
https://stat.ethz.ch/Rmanual/Rdevel/library/stats/html/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 crossvalidation. Numerische Mathematik, 31, 377403. doi: 10.1007/BF01404567
Gu, C. (2013). Smoothing spline ANOVA models, 2nd edition. New York: Springer. doi: 10.1007/9781461453697
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
Helwig, N. E. (2020+). Spectrally sparse nonparametric regression via elastic net regularized smoothers. Journal of Computational and Graphical Statistics. doi: 10.1080/10618600.2020.1806855
Wahba, G. (1985). A comparison of GCV and GML for choosing the smoothing parameters in the generalized spline smoothing problem. The Annals of Statistics, 4, 13781402. doi: 10.1214/aos/1176349743
summary.ss
for summarizing ss
objects.
predict.ss
for predicting from ss
objects.
sm
for fitting smooth models with multiple predictors of mixed types (Gaussian response).
gsm
for fitting generalized smooth models with multiple predictors of mixed types (nonGaussian response).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56  # 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)
ss.GCV
# OCV selection
ss.OCV < ss(x, y, method = "OCV", nknots = 10)
ss.OCV
# GACV selection
ss.GACV < ss(x, y, method = "GACV", nknots = 10)
ss.GACV
# ACV selection
ss.ACV < ss(x, y, method = "ACV", nknots = 10)
ss.ACV
# ML selection
ss.ML < ss(x, y, method = "ML", nknots = 10)
ss.ML
# REML selection
ss.REML < ss(x, y, method = "REML", nknots = 10)
ss.REML
# AIC selection
ss.AIC < ss(x, y, method = "AIC", nknots = 10)
ss.AIC
# BIC selection
ss.BIC < ss(x, y, method = "BIC", nknots = 10)
ss.BIC
# compare results
mean( ( fx  ss.GCV$y )^2 )
mean( ( fx  ss.OCV$y )^2 )
mean( ( fx  ss.GACV$y )^2 )
mean( ( fx  ss.ACV$y )^2 )
mean( ( fx  ss.ML$y )^2 )
mean( ( fx  ss.REML$y )^2 )
mean( ( fx  ss.AIC$y )^2 )
mean( ( fx  ss.BIC$y )^2 )
# plot results
plot(x, y)
rlist < list(ss.GCV, ss.OCV, ss.GACV, ss.ACV,
ss.REML, ss.ML, ss.AIC, ss.BIC)
for(j in 1:length(rlist)){
lines(rlist[[j]], lwd = 2, col = j)
}

Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.