#zoo time series
xy <- zoo_simulate(
cols = 1,
rows = 30
)
#optimize splines model
m <- utils_optimize_spline(
x = as.numeric(zoo::index(xy)), #predictor
y = xy[, 1] #response
)
print(m)
#plot observation
plot(
x = zoo::index(xy),
y = xy[, 1],
col = "forestgreen",
type = "l",
lwd = 2
)
#plot prediction
points(
x = zoo::index(xy),
y = stats::predict(
object = m,
x = as.numeric(zoo::index(xy))
)$y,
col = "red"
)
Run the code above in your browser using DataLab