# NOT RUN {
library(fda)
precipitation_data = CanadianWeather$daily[,,"Precipitation.mm"]
annualprec = apply(precipitation_data,2,sum)
y = ifelse(annualprec<mean(annualprec), 0, 1)
y = as.factor(y)
x = CanadianWeather$daily[,,"Temperature.C"]
xbasis = create.fourier.basis(c(1,365),5) # 5 basis functions
# smoothing of the data and extraction of functional data object
xfd = smooth.basis(c(1:365),x,xbasis)$fd
# bbasis and betalist are optional arguments
bbasis = create.fourier.basis(c(0,365),3) # 3 bf
betalist = list(bbasis)
formula = y ~ xfd
lfreg.model = lfreg(formula, betalist = betalist)
# add scalar variables
latitude = CanadianWeather$coordinates[,1]
longitude = CanadianWeather$coordinates[,2]
# cbasis and betalist are optional arguments
cbasis = create.constant.basis(c(1,365))
betalist = list(bbasis, cbasis, cbasis)
formula = y ~ xfd + latitude + longitude
lfreg.model = lfreg(formula, betalist = betalist)
# }
Run the code above in your browser using DataLab