forked from thiyangt/fformpp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME.Rmd
116 lines (90 loc) · 3.52 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
---
output: github_document
---
[![Project Status: Active ? The project has reached a stable, usable state and is being actively developed.](http://www.repostatus.org/badges/latest/active.svg)](http://www.repostatus.org/#active) [![Build Status](https://travis-ci.org/thiyangt/fformpp.svg?branch=master)](https://travis-ci.org/thiyangt/fformpp.svg?branch=masterr)
[![Project Status: WIP – Initial development is in progress, but there has not yet been a stable, usable release suitable for the public.](https://www.repostatus.org/badges/latest/wip.svg)](https://www.repostatus.org/#wip)
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "man/figures/README-",
out.width = "100%"
)
```
# fformpp
## Installation
The linked packages [flutils](https://github.com/feng-li/flutils) and [movingknots](https://github.com/feng-li/movingknots) should be installed prior to the installation of fformpp.
```r
# install.packages("devtools")
devtools::install_github("thiyangt/fformpp")
library(fformpp)
```
## Usage
### Following example illustrates how package functionalities work
**Load packages**
```{r}
library(methods)
library(MASS)
library(Matrix)
library(mvtnorm)
library(flutils)
library(fformpp)
library(seer)
library(parallel) #getDefaultCluster
```
**Load example dataset**
```r
data(features.df)
data(forecast.error)
features_mat <- as.matrix(features.df)
forecast.error <- as.matrix(forecast.error)
```
**Fit surface regression model**
```r
## 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**
```{r}
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**
```{r}
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**
```{r}
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
```