문제

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)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top