# generate data
set.seed(1)
n <- 100
x <- seq(0, 1, length.out = n)
fx <- 2 + 3 * x + sin(2 * pi * x)
y <- fx + rnorm(n, sd = 0.5)
# GCV selection (default)
ss.GCV <- ss(x, y, nknots = 10)
# get predictions and SEs (at design points)
fit <- predict(ss.GCV, x = x)
head(fit)
# compare to original fit
mean((fit$y - ss.GCV$y)^2)
# plot result (with default 95% CI)
plotci(fit)
# estimate first derivative
d1 <- 3 + 2 * pi * cos(2 * pi * x)
fit <- predict(ss.GCV, x = x, deriv = 1)
head(fit)
# plot result (with default 95% CI)
plotci(fit)
lines(x, d1, lty = 2) # truth
Run the code above in your browser using DataLab