# NOT RUN {
# cycling dataset
library(fda)
# creation of ordinal variable from HR variable
zoneHR=rep(0,216)
zoneHR[which(rowMeans(cycling$HR[,1:60])<107)]=1
zoneHR[which((rowMeans(cycling$HR[,1:60])<125)&(rowMeans(cycling$HR[,1:60])>107))]=2
zoneHR[which((rowMeans(cycling$HR[,1:60])<142)&(rowMeans(cycling$HR[,1:60])>125))]=3
zoneHR[which((rowMeans(cycling$HR[,1:60])<160)&(rowMeans(cycling$HR[,1:60])>142))]=4
zoneHR[which((rowMeans(cycling$HR[,1:60])>160))]=5
# first functional variable - power (WATTS)
watts = t(cycling$WATTS[,1:60])
# set up a fourier basis system due to its cycling pattern
xbasis = create.fourier.basis(c(1,60),5) # 5 basis functions for example
watts.fd = smooth.basis(c(1:60),watts,xbasis)$fd
zoneHR = as.factor(zoneHR)
formula = zoneHR ~ watts.fd
olfreg.model = olfreg(formula = formula)
# additional functional variable - cadence (CAD)
cad = t(cycling$CAD[,1:60])
# set up a functional variable for cad
xbasis2 = create.bspline.basis(c(1,60), nbasis = 5, norder = 4)
cad.fd = smooth.basis(c(1:60),cad,xbasis2)$fd
formula = zoneHR ~ watts.fd + cad.fd
olfreg.model = olfreg(formula = formula)
# }
Run the code above in your browser using DataLab