Intro

This vignette presents an example of using the onlineforecasting package for fitting an error model and calculating forecasts as carried out by Bacher et al. (2013).

See the Building heat load forecasting for more details on the model.

Fit the load forecast model:

library(onlineforecast)
D <- Dbuilding
# Don't bother with test period here
D$scoreperiod <- in_range("2010-12-20", D$t)
D$tday <- make_tday(D$t, 1:36)
# The heat load forecast model
model <- forecastmodel$new()
model$output = "heatload"
model$add_inputs(Ta = "lp(Ta, a1=0.9)", 
                 I = "lp(I, a1=0.7)", 
                 mu_tday = "fs(tday/24, nharmonics=10)",
                 mu = "one()")
model$add_regprm("rls_prm(lambda=0.9)")
model$add_prmbounds(Ta__a1 = c(0.8, 0.9, 0.9999),
                    I__a1 =  c(0.4, 0.8, 0.9999),
                    lambda = c(0.9, 0.99, 0.9999))
rls_optim(model, D, kseq=c(1,18))
##     $par
##     Ta__a1  I__a1 lambda 
##      0.938  0.808  0.995 
##     
##     $value
##     [1] 1.48
##     
##     $counts
##     function gradient 
##           22       22 
##     
##     $convergence
##     [1] 0
##     
##     $message
##     [1] "CONVERGENCE: REL_REDUCTION_OF_F <= FACTR*EPSMCH"
model$kseq <- 1
val <- rls_fit(model$prm, model, D, returnanalysis = TRUE)
D$heatloadHat <- val$Yhat

Error model

Analyse the one-step prediction residuals

Take one-step forecast, lag and calculate residuals:

# Generate the one-step residuals
residualsk1 <- D$heatload - lagvec(D$heatloadHat$k1, 1)
# or the residual function give the same
tmp <- residuals(D$D$heatloadHat, D$heatload)
unique(tmp$k1 - residualsk1)
##     numeric(0)

# Plot to see 
plot(residualsk1)

acf(residualsk1, na.action = na.pass)