简体   繁体   中英

How to get all points for a fitted spline in R?

I am trying to find the MSE of a fitted smooth.spline in R (and compare it with other methods) using a default data set (cars). But using predict function decreases the number of my data points. In other words, I have 50 pairs of data points (x,y) but predict function gives me 35 points (yhatsp). How can I get all 50 points for my spline? Thanks

library(datasets)

x=cars[,2]

y=cars[,1]

yhatsp=predict(smooth.spline(x,y))$y

MSE=mean((y-yhatsp)^2)

Thanks to @Roman Luštrik : adding newdata solved my problem:

library(datasets)

x=cars[,2]

y=cars[,1]

yhatsp=predict(smooth.spline(x,y),x)$y

MSE=mean((y-yhatsp)^2)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM