# NOT RUN {
library(fda)
y = log10(apply(CanadianWeather$dailyAv[1:334,,2],2,sum))
x = CanadianWeather$dailyAv[1:334,,1] # temperature
xbasis = create.fourier.basis(c(1,334),5)
xfd = smooth.basis(c(1:335),x,xbasis)$fd
bbasis = create.fourier.basis(c(1,334),5)
latitude = CanadianWeather$coordinates[,1]
longitude = CanadianWeather$coordinates[,2]
xfdlist = list(xfd, latitude, longitude)
cbasis = create.constant.basis(c(1,334))
betalist = list(bbasis, cbasis, cbasis)
formula = y ~ xfd + latitude + longitude
freg.model = freg(formula = formula, betalist = betalist)
# Prediction with new data included
newdata = list(CanadianWeather$dailyAv[1:365,,1], latitude, longitude)
# newdata = list(xfd_1, latitude, longitude) #funct. and scalar variable(s)
yhat = predict(freg.model, newdata = newdata)
# }
Run the code above in your browser using DataLab