predict.bigspline {bigsplines} | R Documentation |
Get fitted values and standard error estimates for cubic smoothing splines.
## S3 method for class 'bigspline' predict(object,newdata=NULL,se.fit=FALSE, effect=c("all","0","lin","non"), design=FALSE,smoothMatrix=FALSE,...)
object |
Object of class "bigspline", which is output from |
newdata |
Vector containing new data points for prediction. See Details and Example. Default of |
se.fit |
Logical indicating whether the standard errors of the fitted values should be estimated. Default is |
effect |
Which effect to estimate: |
design |
Logical indicating whether the design matrix should be returned. |
smoothMatrix |
Logical indicating whether the smoothing matrix should be returned. |
... |
Ignored. |
Uses the coefficient and smoothing parameter estimates from a fit cubic smoothing spline (estimated by bigspline
) to predict for new data.
If se.fit=FALSE
, design=FALSE
, and smoothMatrix=FALSE
, returns vector of fitted values.
Otherwise returns list with elements:
fit |
Vector of fitted values |
se.fit |
Vector of standard errors of fitted values (if |
X |
Design matrix used to create fitted values (if |
ix |
Index vector such that |
S |
Smoothing matrix corresponding to fitted values (if |
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. (2017). Regression with ordered predictors via ordinal smoothing splines. Frontiers in Applied Mathematics and Statistics, 3(15), 1-13.
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.
Helwig, N. E. and Ma, P. (2016). Smoothing spline ANOVA for super-large samples: Scalable computation via rounding parameters. Statistics and Its Interface, 9, 433-444.
########## EXAMPLE 1 ########## # define univariate function and data set.seed(773) myfun <- function(x){ 2 + x + sin(2*pi*x) } x <- runif(10^4) y <- myfun(x) + rnorm(10^4) # fit cubic spline model cubmod <- bigspline(x,y) crossprod( predict(cubmod) - myfun(x) )/10^4 # define new data for prediction newdata <- data.frame(x=seq(0,1,length.out=100)) # get fitted values and standard errors for new data yc <- predict(cubmod,newdata,se.fit=TRUE) # plot results with 95% Bayesian confidence interval plot(newdata$x,yc$fit,type="l") lines(newdata$x,yc$fit+qnorm(.975)*yc$se.fit,lty=3) lines(newdata$x,yc$fit-qnorm(.975)*yc$se.fit,lty=3) # predict constant, linear, and nonlinear effects yc0 <- predict(cubmod,newdata,se.fit=TRUE,effect="0") ycl <- predict(cubmod,newdata,se.fit=TRUE,effect="lin") ycn <- predict(cubmod,newdata,se.fit=TRUE,effect="non") crossprod( yc$fit - (yc0$fit + ycl$fit + ycn$fit) ) # plot results with 95% Bayesian confidence intervals par(mfrow=c(1,2)) plot(newdata$x,ycl$fit,type="l",main="Linear effect") lines(newdata$x,ycl$fit+qnorm(.975)*ycl$se.fit,lty=3) lines(newdata$x,ycl$fit-qnorm(.975)*ycl$se.fit,lty=3) plot(newdata$x,ycn$fit,type="l",main="Nonlinear effect") lines(newdata$x,ycn$fit+qnorm(.975)*ycn$se.fit,lty=3) lines(newdata$x,ycn$fit-qnorm(.975)*ycn$se.fit,lty=3) ########## EXAMPLE 2 ########## # define (same) univariate function and data set.seed(773) myfun <- function(x){ 2 + x + sin(2*pi*x) } x <- runif(10^4) y <- myfun(x) + rnorm(10^4) # fit a different cubic spline model cubamod <- bigspline(x,y,type="cub0") crossprod( predict(cubamod) - myfun(x) )/10^4 # define (same) new data for prediction newdata <- data.frame(x=seq(0,1,length.out=100)) # get fitted values and standard errors for new data ya <- predict(cubamod,newdata,se.fit=TRUE) # plot results with 95% Bayesian confidence interval plot(newdata$x,ya$fit,type="l") lines(newdata$x,ya$fit+qnorm(.975)*ya$se.fit,lty=3) lines(newdata$x,ya$fit-qnorm(.975)*ya$se.fit,lty=3) # predict constant, linear, and nonlinear effects ya0 <- predict(cubamod,newdata,se.fit=TRUE,effect="0") yal <- predict(cubamod,newdata,se.fit=TRUE,effect="lin") yan <- predict(cubamod,newdata,se.fit=TRUE,effect="non") crossprod( ya$fit - (ya0$fit + yal$fit + yan$fit) ) # plot results with 95% Bayesian confidence intervals par(mfrow=c(1,2)) plot(newdata$x,yal$fit,type="l",main="Linear effect") lines(newdata$x,yal$fit+qnorm(.975)*yal$se.fit,lty=3) lines(newdata$x,yal$fit-qnorm(.975)*yal$se.fit,lty=3) plot(newdata$x,yan$fit,type="l",main="Nonlinear effect") lines(newdata$x,yan$fit+qnorm(.975)*yan$se.fit,lty=3) lines(newdata$x,yan$fit-qnorm(.975)*yan$se.fit,lty=3)