Description Usage Arguments Details Value Warnings Note Author(s) References Examples
Given a real-valued response vector \mathbf{y}=\{y_{i}\}_{n\times1} and an ordinal predictor vector \mathbf{x}=\{x_{i}\}_{n\times 1} with x_{i} \in \{1,…,K\} \ \forall i, an ordinal smoothing spline model has the form
y_{i}=η(x_{i})+e_{i}
where y_{i} is the i-th observation's respone, x_{i} is the i-th observation's predictor, η is an unknown function relating the response and predictor, and e_{i}\sim\mathrm{N}(0,σ^{2}) is iid Gaussian error.
1 |
x |
Predictor vector. |
y |
Response vector. Must be same length as |
knots |
Either a scalar giving the number of equidistant knots to use, or a vector of values to use as the spline knots. If left blank, the number of knots is |
weights |
Weights vector (for weighted penalized least squares). Must be same length as |
lambda |
Smoothing parameter. If left blank, |
monotone |
If |
To estimate η I minimize the penalized least-squares functional
\frac{1}{n}∑_{i=1}^{n}(y_{i}-η(x_{i}))^{2}+λ ∑_{x=2}^K [η(x)-η(x-1)]^2 dx
where λ≥q0 is a smoothing parameter that controls the trade-off between fitting and smoothing the data.
Default use of the function estimates λ by minimizing the GCV score:
\mbox{GCV}(λ) = \frac{n\|(\mathbf{I}_{n}-\mathbf{S}_{λ})\mathbf{y}\|^{2}}{[n-\mathrm{tr}(\mathbf{S}_{λ})]^2}
where \mathbf{I}_{n} is the identity matrix and \mathbf{S}_{λ} is the smoothing matrix.
fitted.values |
Vector of fitted values. |
se.fit |
Vector of standard errors of |
sigma |
Estimated error standard deviation, i.e., \hat{σ}. |
lambda |
Chosen smoothing parameter. |
info |
Model fit information: vector containing the GCV, R-squared, AIC, and BIC of fit model (assuming Gaussian error). |
coef |
Spline basis function coefficients. |
coef.csqrt |
Matrix square-root of covariace matrix of |
n |
Number of data points, i.e., |
df |
Effective degrees of freedom (trace of smoothing matrix). |
xunique |
Unique elements of |
x |
Predictor vector (same as input). |
y |
Response vector (same as input). |
residuals |
Residual vector, i.e., |
knots |
Spline knots used for fit. |
monotone |
Logical (same as input). |
When inputting user-specified knots
, all values in knots
must match a corresponding value in x
.
The spline is estimated using penalized least-squares, which does not require the Gaussian error assumption. However, the spline inference information (e.g., standard errors and fit information) requires the Gaussian error assumption.
Nathaniel E. Helwig <helwig@umn.edu>
Gu, C. (2013). Smoothing spline ANOVA models, 2nd edition. New York: Springer.
Helwig, N. E. (2013). Fast and stable smoothing spline analysis of variance models for large samples with applications to electroencephalography data analysis. Unpublished doctoral dissertation. University of Illinois at Urbana-Champaign.
Helwig, N. E. and Ma, P. (2015). Fast and stable multiple smoothing parameter selection in smoothing spline analysis of variance models with large samples. Journal of Computational and Graphical Statistics, 24, 715-732.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | ########## EXAMPLE ##########
# generate some data
n <- 100
nk <- 50
x <- seq(-3,3,length.out=n)
eta <- (sin(2*x/pi) + 0.25*x^3 + 0.05*x^5)/15
set.seed(1)
y <- eta + rnorm(n, sd=0.5)
# plot data and true eta
plot(x, y)
lines(x, eta, col="blue", lwd=2)
# fit ordinal smoothing spline
ossmod <- ordspline(x, y, knots=nk)
lines(ossmod$x, ossmod$fit, col="red", lwd=2)
# fit monotonic smoothing spline
mssmod <- ordspline(x, y, knots=nk, monotone=TRUE)
lines(mssmod$x, mssmod$fit, col="purple", lwd=2)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.