## Show data
# Load data
data("ontario")
# Plot
old_par <- par(mfrow = c(1, 2))
plot(ontario$temp)
plot(ontario$elec)
par(old_par)
# Observe the 3-day windows for each observation
plot(ontario$temp$argvals, ontario$temp$data[2, ], type = "o",
xlim = c(-48, 72), ylim = c(7, 13), xlab = "Hours",
ylab = "Electricity consumption", pch = 16)
points(ontario$temp$argvals - 24, ontario$temp$data[1, ], col = 3, pch = 2)
points(ontario$temp$argvals + 24, ontario$temp$data[3, ], col = 2, cex = 1.5)
abline(v = 24 * -2:3, lty = 2)
legend("top", legend = c("Curve 1", "Curve 2", "Curve 3"), col = c(3, 1, 2),
pt.cex = c(1, 1, 1.5), pch = c(2, 16, 1))
# If the days are not consecutive, then the electricity consumptions at the
# end of one day and the beginning of the next do not match
head(abs(ontario$elec$data[-368, 25] - ontario$elec$data[-1, 1]))
head(diff(ontario$df$date))
# \donttest{
## Test the linear model with functional response and predictor
(comp_flmfr <- flm_test(X = ontario$temp, Y = ontario$elec,
est_method = "fpcr_l1s"))
(simp_flmfr <- flm_test(X = ontario$temp, Y = ontario$elec,
beta0 = 0, est_method = "fpcr_l1s"))
# Visualize estimation
filled.contour(x = ontario$temp$argvals, y = ontario$elec$argvals,
z = comp_flmfr$fit_flm$Beta_hat,
color.palette = viridisLite::viridis, nlevels = 20)
# }
Run the code above in your browser using DataLab