Project Status: Active ? The project has reached a stable, usable state and is being actively developed. Build Status

Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/README-",
  out.width = "100%"
)

fformpp

Installation

The linked packages flutils and movingknots should be installed prior to the installation of fformpp.

# install.packages("devtools")
devtools::install_github("thiyangt/fformpp")
library(fformpp)

Usage

Following example illustrates how package functionalities work

Load packages

library(methods)
library(MASS)
library(Matrix)
library(mvtnorm)
library(flutils)
library(fformpp)
library(seer)
library(parallel) #getDefaultCluster

Load example dataset

data(features.df)
data(forecast.error)
features_mat <- as.matrix(features.df)
forecast.error <- as.matrix(forecast.error)

Fit surface regression model

## This will take time. This model is saved in the package. The fitted model is  saved into the package for easy references.
n <- dim(forecast.error)[1]
p <- dim(forecast.error)[2]

fformpp.model <- fit_fformpp(feamat=features_mat, accmat=forecast.error, 
                             sknots=2, aknots=2,
                            fix.s=0, fix.a=0, fix.shrinkage=1:p,            fix.covariance=0,
                            fix.coefficients=0, n.iter=100,
                            knot.moving.algorithm="Random-Walk",
                            ptype=c("identity", "identity", "identity"),
                            prior.knots=n)

Predict forecast error on new data

data("fformpp.model")
data("forecast.error.m1")
data("features.df.m1")
predict.m1 <- predict_fformpp(fformpp.model, features.df.m1, c("ets", "arima", "rw", "rwd", "wn", "theta", "nn"), log=FALSE, final.estimate=median)
head(predict.m1)

Generate forecast from the model with minimum forecast error

library(Mcomp)
yearlym1 <- subset(M1, "yearly")
data("fcast_m1")
min.fcasterror <- individual_forecast(predicted=predict.m1, 
                                      accmat=cal_MASE, 
                                      real.error=forecast.error.m1, 
                                      tslist=yearlym1, 
                                      forecast_list = fcast_m1,
                                      h=6)
min.fcasterror

Generate combination forecasts

library(Mcomp)
yearlym1 <- subset(M1, "yearly")
data("fcast_m1")
min.fcasterror.comb <- combination_forecast(predicted=predict.m1[1:2,], 
                                      ncomp=2,
                                      accmat=cal_MASE, 
                                      real.error=forecast.error.m1, 
                                      tslist=yearlym1, 
                                      forecast_list = fcast_m1,
                                      h=6, weights=FALSE, measure="mean")
min.fcasterror.comb


thiyangt/fformpp documentation built on Jan. 5, 2024, 5:44 a.m.