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)