Greymodels
Greymodels
December 5, 2022
Type Package
Title Shiny App for Grey Forecasting Model
Version 2.0.1
Maintainer Jahajeeah Havisha <[email protected]>
Description The 'Greymodels' Shiny app is an interactive interface for statistical modelling and fore-
casting using grey-based models. It covers several state-of-the-art univariate and multivari-
ate grey models. A user friendly interface allows users to easily compare the performance of dif-
ferent models for prediction and among others, visualize graphical plots of predicted val-
ues within user chosen confidence inter-
vals. Chang, C. (2019) <doi:10.24818/18423264/53.1.19.11>, Li, K., Zhang, T. (2019) <doi:10.1007/s12667-
019-00344-
0>, Ou, S. (2012) <doi:10.1016/j.compag.2012.03.007>, Li, S., Zhou, M., Meng, W., Zhou, W. (2019) <doi:10.1080/233077
gil, H. (2020) <doi:10.3934/math.2021091>, Li, D., Chang, C., Chen, W., Chen, C. (2011) <doi:10.1016/j.apm.2011.04.006>
019-04248-
0>, Xiao, X., Duan, H. (2020) <doi:10.1016/j.engappai.2019.103350>, Xu, N., Dang, Y. (2015) <doi:10.1155/2015/606707>
020-04765-
3>, Zhou, P., Ang, B., Poh, K. (2006) <doi:10.1016/j.energy.2005.12.002>, Cheng, M., Li, J., Liu, Y., Liu, B. (2020) <doi:10.
License GPL-3
URL https://github.com/havishaJ/Greymodels
Encoding UTF-8
Depends R (>= 4.0.0), dplyr, Metrics, cmna, plotly
Imports shiny, shinydashboard, shinyWidgets, ggplot2, readxl,
particle.swarm.optimisation, scales, expm
NeedsCompilation no
Author Jahajeeah Havisha [aut, cre],
Saib Aslam Aly [aut]
Repository CRAN
Date/Publication 2022-12-05 12:42:35 UTC
1
2 app_server
R topics documented:
app_server . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
BackgroundValues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CombinedModels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
ConfidenceInterval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
ExtendedForms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
IntervalMultivariable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
Multivariable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
ParametersEstimation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
ResidualModification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Index 30
Description
Runs the greymodels Shiny app
Usage
ui()
server(input, output)
run_app()
Arguments
ui Controls the layout and appearance of the greymodels shiny app
input Stores the current values of all of the widgets in the app
output Contains all of the code needed to update the R objects in the app
server Contains the instructions to build the greymodels shiny app
Value
No return value, runs the app
Examples
if (interactive()) {
library("shiny")
BackgroundValues 3
library("shinydashboard")
library("shinyWidgets")
library("readxl")
library("Metrics")
library("particle.swarm.optimisation")
library("cmna")
library("expm")
library("plotly")
library("ggplot2")
library("scales")
library("dplyr")
Description
A collection of grey forecasting models with improvements to the underlying background value z.
Usage
gm11(x0)
epgm11(x0)
tbgm11(x0)
igm11(x0)
gm114(x0)
Arguments
x0 Raw data
gm11 Basic grey model
epgm11 Extrapolation-based grey model
tbgm11 Data transformation-based grey model
igm11 Improved grey model
gm114 Grey model with single variable, one first-order variable, four background val-
ues
Value
fitted and predicted values
4 BackgroundValues
References
Chang C (2019). Extrapolation-based Grey Model for Small-Dataset Forecasting. Economic Com-
putation and Economic Cybernetics Studies and Research, 53(1), 171-182. DOI:10.24818/18423264/53.1.19.11.
Li K, Zhang T (2019). A Novel Grey Forecasting Model and its Application in Forecasting the
Energy Consumption in Shanghai. Energy Systems, pp. 1-16. DOI:10.1007/s12667-019-00344-0.
Ou S (2012). Forecasting Agricultural Output with an Improved Grey Forecasting Model based on
the Genetic Algorithm. Computers and Electronics in Agriculture, 85, 33-39. DOI:10.1016/j.compag.2012.03.007.
Li S, Zhou M, Meng W, Zhou W (2019). A new Prediction Model for Forecasting the Automobiles
Ownership in China. Journal of Control and Decision, 8(2), 155-164. DOI:10.1080/23307706.2019.1666310.
Examples
# GM(1,1) model
# Calculate AGO
x1 <- cumsum(x0)
# Determine length of x0
n <- length(x0)
for (i in 1:n){
b[i] <- -(0.5*x1[i + 1] + 0.5*x1[i])
}
b1 <- b[1:n-1]
# Create a matrix B
B <- matrix(1,nrow=n-1,ncol=2)
B[,1] <- t(t(b1[1:n-1]))
# Create matrix yn
yn <- matrix(c(x0),ncol=1)
yn <- t(t(x0[2:n]))
# Predicted values
x0cap4 <- scale_with(1 : n+A-1)
x0cap5 <- tail(x0cap4,A)
x0cap5
Description
A collection of hybrid grey forecasting models.
Usage
ngbm11(x0)
ggvm11(x0)
tfdgm11(x0)
Arguments
x0 Raw data
ngbm11 Non-linear grey Bernoulli model
ggvm11 Grey generalized Verhulst model
tfdgm11 Traffic flow mechanics grey model
Value
fitted and predicted values
References
Chen C (2008). Application of the Novel Nonlinear Grey Bernoulli Model for Forecasting Unem-
ployment Rate. Chaos, Solitons and Fractals, 37(1), 278-287. DOI:10.1016/j.chaos.2006.08.024.
6 CombinedModels
Zhou W, Pei L (2020). The Grey Generalized Verhulst model and its Application for Forecast-
ing Chinese Pig Price Index. Soft Computing, 24, 4977-4990. DOI:10.1007/s00500-019-04248-0.
Xiao X, Duan H (2020). A New Grey Model for Traffic Fow Mechanisms. Engineering Appli-
cations of Artificial Intelligence, 88(2020), 103350. DOI:10.1016/j.engappai.2019.103350.
Examples
# Input data x0
x0 <- c(129,151,132,144,119,125,127,132)
# AGO
x1 <- cumsum(x0)
n <- length(x0)
z <- numeric(n)
for (i in 1:n){
z[i] <- 0.5*(x1[i+1] + x1[i])
}
z1 <- z[1:n-1]
for (i in 1:n){
z[i] <- (0.5*(x1[i+1] + x1[i]))^2
}
z2 <- z[1:n-1]
y <- matrix(c(x0),ncol=1)
y <- t(t(x0[2:n]))
p <- b/(2*a)
q <- ((b^2)/(4*(a^2))) - (lambda/a)
A <- 4
t4 <- length(x1cap4)
# Predicted values
x0cap5 <- tail(x0cap4,A)
x0cap5
Description
The CIvalue, CI_rm and CI_mdbgm functions calculate the confidence interval of the predicted
values.
Usage
CIvalue(fp1,actual1,x,ci)
CI_rm(fp1,actual1,x,ci)
CI_nhmgmp(fp1,x01,x02,x,ci)
CI_igndgm(fp1,actual1,x,ci)
CI_mdbgm(fp1,actual1,x,ci)
Arguments
fp1 Fitted and predicted values
actual1 Raw data
x01 Raw data of variable 1
x02 Raw data of variable 2
x Number of forecasts chosen by the user
ci The confidence level chosen by the user. Values range between 90%, 95% and
99%.
Value
confidence interval of predicted values
Examples
# Confidence interval of predicted values for EPGM (1, 1) model
fp1<-c(560,541.4,517.8,495.3,473.7,453.1,433.4,414.5,396.5)
actual1<-c(560,540,523,500,475)
w <- length(fp2)
n <- length(actual2)
x <- 4
t <- length(predicted)
require("Metrics")
ci <- 95
u <- numeric(t)
l <- numeric(t)
for (i in 1:t) {
u[i] = predicted[i] + (t.val * (sqrt(mse) * sqrt(i)))
l[i] = predicted[i] - (t.val * (sqrt(mse) * sqrt(i)))
}
Description
A collection of extended grey forecasting models.
10 ExtendedForms
Usage
dgm11(x0)
dgm21(x0)
odgm21(x0)
ndgm11(x0)
vssgm11(x0)
gom11(x0)
gomia11(x0)
ungom11(x0)
exgm11(x0)
egm11(k,x0,k_A,x0_A)
Arguments
x0 Raw data
k Data index of raw data
x0_A Raw data (testing set)
k_A Data index (testing set)
dgm11 Discrete grey model with single variable, first order differential equation
dgm21 Discrete grey model with single variable, second order differential equation
model
odgm21 Optimized discrete grey model with single variable, second order differential
equation
ndgm11 Non-homogeneous discrete grey model
vssgm11 Variable speed and adaptive structure-based grey model
gom11 Grey opposite-direction model based on inverse accumulation and traditional
interpolation method
gomia11 Grey opposite-direction model based on inverse accumulation
ungom11 Unbiased grey opposite-direction model based on inverse accumulation
exgm11 Exponential grey model
egm11 Extended grey model
Value
fitted and predicted values
References
Xie N, Liu S (2009). Discrete Grey Forecasting Model and its Application. Applied Mathematical
Modelling, 33(2), 1173-1186. DOI:10.1016/j.apm.2008.01.011.
Shao Y, Su H (2012). On Approximating Grey Model DGM (2, 1). 2012 AASRI Conference
on Computational Intelligence and Bioinformatics, 1, 8-13. DOI:10.1016/j.aasri.2012.06.003.
Xie N, Liu S, Yang Y, Yuan C (2013). On Novel Grey Forecasting Model based on Non-homogeneous
ExtendedForms 11
Li S, Miao Y, Li G, Ikram M (2020). A Novel Varistructure Grey Forecasting Model with Speed
Adaptation and its Application. Mathematical and Computers in Simulation, 172, 45-70. DOI:10.1016/j.matcom.2019.12.020
Che X, Luo Y, He Z (2013). Grey New Information GOM (1, 1) Model based Opposite-Direction
Accumulated Generating and its Application. Applied Mechanics and Materials, 364, 207-210.
DOI:10.4028/www.scientific.net/AMM.364.207.
Power Load Forecasting based on GOM (1, 1) Model under the Condition of Missing Data. 2016
IEEEPES Asia-Pacific Power and Energy Engineering Conference (APPEEC), pp. 2461-2464.
DOI:10.1109/appeec.2016.7779929.
Luo Y, Liao D (2012). Grey New Information Unbiased GOM (1, 1) Model based on Opposite-
Direction Accumulated Generating and its Application. Advanced Materials Research, 507, 265-
268. DOI:10.4028/www.scientific.net/AMR.507.265.
Bilgil H (2020). New Grey Forecasting Model with its Application and Computer Code. AIMS
Mathematics, 6(2), 1497-1514. DOI: 10.3934/math.2021091.
An Extended Grey Forecasting Model for Omnidirectional Forecasting considering Data Gap Dif-
ference. Applied Mathematical Modeling, 35, 5051-5058. DOI:10.1016/j.apm.2011.04.006.
Examples
# EXGM (1, 1): Exponential grey model
# Input data x0
x0 <- c(2028,2066,2080,2112,2170,2275,2356,2428)
# Create matrix y
y <- matrix(c(x0),ncol=1)
y <- t(t(x0[2:n]))
b <- numeric(n)
for (i in 1:n){
b[i] <- -0.5*(x1[i+1] + x1[i])
}
b1 <- b[1:n-1]
# Create matrix B2
mat1 <- matrix(c(b1),ncol=1)
mat2 <- matrix(1,nrow=n-1,ncol=1)
f <- numeric(n)
for (i in 1:n){
12 IntervalMultivariable
Description
A collection of multivariate grey forecasting models based on interval number sequences.
IntervalMultivariable 13
Usage
igndgm12(LB,UB)
mdbgm12(x01L,x01U,x02L,x02U,x01La,x01Ua,x02La,x02Ua)
Arguments
LB, UB Lower and upper bound of interval sequence
x01L,x01U Lower and upper bound of first interval sequence (training set)
x02L,x02U Lower and upper bound of second interval sequence (training set)
x01La,x01Ua Lower and upper bound of first interval sequence (testing set)
x02La,x02Ua Lower and upper bound of second interval sequence (testing set)
igndgm12 Interval grey number sequence based on non-homogeneous discrete grey model
mdbgm12 Multivariate grey model based on dynamic background algorithm
Value
fitted and predicted values
References
Xie N, Liu S (2015). Interval Grey Number Sequence Prediction by using Nonhomogeneous Expo-
nential Discrete Grey Forecasting Model. Journal of Systems Engineering and Electronics, 26(1),
96-102. DOI:10.1109/JSEE.2015.00013.
Zeng X, Yan S, He F, Shi Y (2019). Multivariable Grey Model based on Dynamic Background Al-
gorithm for Forecasting the Interval Sequence. Applied Mathematical Modelling, 80(23). DOI:10.1016/j.apm.2019.11.032.
Examples
#MDBGM (1, 2) model: Multivariate grey model based on dynamic background algorithm.
# Input data
#x01 Lower and upper bound of sequence 1
#x02 Lower and upper bound of sequence 2
# AGO
x11L <- cumsum(x01L)
x11U <- cumsum(x01U)
# Length of sequence
n <- length(x01L)
# Background values
b <- numeric(n)
for (i in 1:n){
b[i] <- (0.5*x11L[i + 1] + 0.5*x11L[i])
b1 <- b[1:n-1]
}
z1L <- matrix(c(b1),ncol=1)
n <- length(x01L)
d <- numeric(n)
for (i in 1:n){
d[i] <- (0.5*x11U[i + 1] + 0.5*x11U[i])
d1 <- d[1:n-1]
}
z1U <- matrix(c(d1),ncol=1)
# Create matrix Y
YL <- matrix(c(x01L[2:n]),ncol=1)
YU <- matrix(c(x01U[2:n]),ncol=1)
# Create matrix X
mat1 <- matrix(c(x12L[2:n]),ncol=1)
mat2 <- matrix(c(x12U[2:n]),ncol=1)
mat3 <- matrix(c(x11L[1:n-1]),ncol=1)
mat4 <- matrix(c(x11U[1:n-1]),ncol=1)
mat5 <- matrix(2:n,nrow=n-1,ncol=1)
mat6 <- matrix(1,nrow=n-1,ncol=1)
X <- cbind(mat1,mat2,mat3,mat4,mat5,mat6)
Description
Usage
gm13(x1,x2,x3)
igm13(x1,x2,x3)
nhmgm1(x01,x02)
nhmgm2(x01,x02)
gmcg12(x01,x02,dat_a)
gmc12(x01,x02,dat_a)
dbgm12(x01,x02,dat_a)
16 Multivariable
Arguments
x1,x2,x3 Raw data of 3 variables (training set)
x01,x02 Raw data of 2 variables (training set)
dat_a Raw data of x02 (testing set)
gm13 Grey multivariate model with first order differential equation and 3 variables
igm13 Improved grey multivariate model with first order differential equation and 3
variables
nhmgm1 Non-homogeneous multivariate grey model with first order differential equation
and 2 variables with p = 1
nhmgm2 Non-homogeneous multivariate grey model with first order differential equation
and 2 variables with p = 2
gmcg12 Multivariate grey convolution model with first order differential equation and 2
variables using the Gaussian rule
gmc12 Multivariate grey convolution model with first order differential equation and 2
variables using the trapezoidal rule
dbgm12 Multivariate grey model with dynamic background value, first order differential
equation and 2 variables using the Gaussian rule
Value
fitted and predicted values
References
Cheng M, Li J, Liu Y, Liu B (2020). Forecasting Clean Energy Consumption in China by 2025:
Using Improved Grey Model GM (1, N). Sustainability, 12(2), 1-20. DOI:10.3390/su12020698.
Ding S, Li R (2020). A New Multivariable Grey Convolution model based on Simpson’s rule
and its Application. Complexity, pp. 1-14. DOI:10.1155/2020/4564653.
Zeng B, Li C (2018). Improved Multivariable Grey Forecasting Model and with a Dynamic Back-
ground Value Coefficient and its Application. Computers and Industrial Engineering, 118, 278-290.
DOI:10.1016/j.cie.2018.02.042.
Examples
# GMC_g (1, 2) model
# AGO
x11 <- cumsum(x01)
x12 <- cumsum(x02)
n <- length(x01)
for (i in 1:n){
b11[i] <- -(0.5*x11[i + 1] + 0.5*x11[i])
b12[i] <- (0.5*x12[i + 1] + 0.5*x12[i])
}
b11a <- b11[1:n-1]
b12a <- b12[1:n-1]
yn <- matrix(c(x01),ncol=1)
yn <- t(t(x01[2:n]))
fe <- numeric(n)
for (i in 1:n){
fe[i] <- beta2 * x12[i] + u
}
E <- matrix(c(fe[1:n]),ncol =1)
xrG <- replicate(n,0)
for (t in 2:n){
sm <- 0
for (e in 2:t){
sm <- sm + ( (exp(-beta1*(t - e + 0.5)))) * ( 0.5 * (E[e]+ E[e-1]) )
}
xrG[t] <- ( x01[1]*exp(-beta1*(t-1)) ) + sm
}
xcap1G <- c(x01[1],xrG[2:n])
fG <- numeric(n-1)
for (i in 1:n-1){
fG[i] <- (xcap1G[i+1] - xcap1G[i])
}
f1G <- fG[1:n-1]
x0cap <- matrix(c(x01[1],f1G[1:n-1]),ncol=1)
# Fitted values
x0cap
18 Optimization
A <- 4
Description
A collection of grey forecasting models using optimization techniques to find optimal parameters
of grey models.
Usage
optim_psogm(x0)
psogm11(x0)
Optimization 19
optim_andgm(x0)
andgm11(x0)
optim_egm11r(x0)
egm11r(x0)
Arguments
x0 Raw data
optim_psogm Parameters optimization (a and b) by particle swarm optimization(PSO)
psogm11 Particle swarm optimization-based grey model
optim_andgm Parameters optimization (r) by PSO
andgm11 Adjacent non-homogeneous discrete grey model
optim_egm11r Parameters optimization (r) by PSO
egm11r Even form of grey model with one variable and one first order equation with
accumulating generation of order r
Value
fitted and predicted values
References
Zeng B, Li S, Meng W, Zhang D (2019). An Improved Grey Prediction Model for China’s Beef
Comsumption Forecasting. PLOS ONE, 14(9), 1-18. DOI:10.1371/journal.pone.0221333.
Liu L, Wu L (2021). Forecasting the Renewable Energy Consumption of the European Countries
by an Adjacent Non-homogeneous Grey Model. Applied Mathematical Modelling, 89, 1932-1948.
DOI:10.1016/j.apm.2020.08.080.
Examples
# Input raw data
x0 <- c(2.8,3.8,4.6,5.2,5.7,6.0,6.2,6.92,7.77,8.92,10.06)
# Parameter optimization
library(particle.swarm.optimisation)
n <- length(x0)
for (i in 1:n){
xr1[i] <- ( (r-1)/r ) * sum(x0[1:i]) + (1/r)*x0[i+1]
20 Optimization
}
xr <- c(x0[1],xr1[1:n-1])
y <- t(t(xr[2:n]))
for (i in 2:length(matrix2+1)) {
matrix2[i] <- r*xrcap[i] - (r-1)*sum(matrix2[1:i-1])
}
particule_result <- matrix2
fitness <- -(1/n)*sum(abs((x0-particule_result)/x0)*100, na.rm=TRUE)
return(fitness)
}
values_ranges <- list(c(0.001,5))
swarm <- ParticleSwarm$new(pop_size = 100,
values_names = list("r"),
fitness_function = fitness_function,
max_it = 100,
acceleration_coefficient_range = list(c(0.5,1.5),c(0.5,1.5)),
inertia = 0.7,
ranges_of_values = values_ranges)
swarm$run(plot = FALSE,verbose = FALSE,save_file = FALSE)
swarm$swarm_best_values
n <- length(x0)
yr <- t(t(xoptr[2:n]))
for (i in 2:length(matrix2r+1)) {
matrix2r[i] <- opt_r*xrcapr[i] - (opt_r-1)*sum(matrix2r[1:i-1])
}
x0cap <- c(matrix2r)
# Fitted values
x0cap
A <- 4
# Predicted values
n <- length(x0)
nn <- n + A
scale_with <- function(k)
{
( beta1r^k * x0[1] ) + ( ( 1 - beta1r^k )/( 1 - beta1r ) ) * (beta2r*k + beta3r)
}
forecast1ra <- scale_with(1:nn)
for (i in 2:length(matrix2ra+1)) {
matrix2ra[i] <- opt_r*xrcapra[i] - (opt_r-1)*sum(matrix2ra[1:i-1])
}
x0cap4 <- c(matrix2ra)
x0cap5 <- tail(x0cap4,A)
# Predicted values
x0cap5
Description
A collection of grey forecasting models based on parameters estimation.
Usage
sogm21(x0)
ngm11k(x0)
ngm11kc(x0)
ongm11kc(x0)
Arguments
x0 Raw data
sogm21 Structured optimized grey model with single variable and second order differ-
ential equation
ngm11k Nonlinear grey model
ngm11kc Nonlinear grey model
ongm11kc Optimized nonlinear grey model
Value
fitted and predicted values
References
Xu N, Dang Y (2015). An Optimized Grey GM (2, 1) Model and Forecasting of Highway Subgrade
Settlement. Mathematical Problems in Engineering, 2015(1), 1-6. DOI:10.1155/2015/606707.
Chen P, Yu H (2014). Foundation Settlement Prediction based on a Novel NGM Model. Math-
ematical Problems in Engineering 2014, 242809. DOI:10.1155/2014/242809.
ParametersEstimation 23
Examples
# Input data x0
x0 <- c(23.36,43.19,58.73,70.87,83.71,92.91,99.73,105.08,109.73,112.19,113.45)
# AGO
x1 <- cumsum(x0)
tm <- length(x0)
# Create matrix y
y <- matrix(c(x0),ncol=1)
y <- t(t(x0[2:tm]))
b <- numeric(tm)
for (i in 1:tm){
b[i] <- -0.5*(x1[i+1] + x1[i])
}
b1 <- b[1:tm-1]
# Create matrix B2
mat1 <- matrix(c(b1),ncol=1)
mat2 <-matrix(2:tm, nrow=tm-1,ncol=1)
mat3 <- matrix(1,nrow=tm-1,ncol=1)
A <- 4
Plots plots
Description
The plots function gives an interactive plot of the model.
Usage
plots(x0,x0cap2,ci,model)
plotrm(x0,x0cap2,ci,model)
plotsmv1(actual1,fp1,ci,model)
plotsmv2(actual1,fitted,ci,model)
plotsigndgm(actual,pred,ci,model)
plots_mdbgm12(actual,pred,ci,model)
Arguments
x0 Raw data
x0cap2 Fitted and predicted data
actual Raw data of interval sequences
actual1 Raw data of multi-variate sequences
fp1 Fitted and predicted data of first variable
fitted Fitted data of multi-variate sequences
pred Fitted and predicted data of interval sequences
ci The confidence level chosen by the user. Values range between 90%, 95% and
99%.
model The model under considration
Value
plots
Plots 25
Examples
x0cap2<-c(560,541.4,517.8,495.3,473.7,453.1,433.4,414.5,396.5)
x0<-c(560,540,523,500,475)
# length of x0
n <- length(x0)
w <- length(x0cap2)
t <- length(x0cap5)
# Performance errors
# Root mean square error
s <- rmse(x0, x0cap)
u <- numeric(t)
l <- numeric(t)
for (i in 1:t) {
u[i] = x0cap5[i] + (t.val * (sqrt(mse) * sqrt(i)))
l[i] = x0cap5[i] - (t.val * (sqrt(mse) * sqrt(i)))
}
UB <- c(u[1:t])
LB <- c(l[1:t])
l1 <- length(LB1)
d3 <- seq(1, l1, 1)
26 ResidualModification
u1 <- length(UB2)
d4 <- seq(1, u1, 1)
d0 <- seq(1, n, 1)
xy1 <- data.frame(x=d0, y=x0)
d1 <- seq(1, w, 1)
xy2 <- data.frame(x=d1, y=x0cap2)
# Plots
colors <- c("Raw Data"="red","Fitted&Forecasts"="blue","LowerBound"="green","UpperBound"="yellow")
CI <- c(n:w)
x=y=NULL
p <- ggplot(df) +
theme_bw() +
labs(title = 'EPGM (1, 1) model',x = 'Number of observation',y = 'Data Forecast & Prediction') +
scale_x_continuous(breaks=1:w) +
scale_y_continuous(labels = scales::comma) +
geom_point(data = xy1, aes(x = x, y = y), shape = 24, color = "black") +
geom_point(data = xy2, aes(x = x, y = y), shape = 21, color = "black") +
geom_point(data = set3, aes(x = CI, y = y), shape = 23, color = "black") +
geom_point(data = set4, aes(x = CI, y = y), shape = 23, color = "black") +
geom_line(data = xy1, aes(x = x, y = y,color = "Raw Data")) +
geom_line(data = xy2, aes(x = x, y = y,color = "Fitted&Forecasts")) +
geom_line(data = set3, aes(x = CI, y = y,color = "LowerBound"), linetype=2) +
geom_line(data = set4, aes(x = CI, y = y,color = "UpperBound"), linetype=2) +
scale_color_manual(name = "Label",values = colors)
r <- ggplotly(p)
r
Description
A collection of grey forecasting models based on residual grey models.
Usage
remnantgm11(x0,x0_A)
tgm11(x0,x0_A)
ResidualModification 27
Arguments
x0 Raw data (training set)
x0_A Raw data (testing set)
remnantgm11 Residual-based grey model
tgm11 Trigonometric grey model
Value
fitted and predicted values
References
Hu Y (2020). Energy Demand Forecasting using a Novel Remnant GM (1, 1) Model. Soft Com-
puting, pp. 13903-13912. DOI:10.1007/s00500-020-04765-3.
Zhou P, Ang B, Poh K (2006). A Trigonometric Grey Prediction Approach to Forecasting Elec-
tricity Demand. Energy, 31(14), 2839-2847. DOI:10.1016/j.energy.2005.12.002.
Examples
# TGM (1, 1) model: Trigonometric grey model
x0 <- c(2350,2465,2557,2577,2689,2739,2797,2885,2937,2996)
x0_A <- c(3042,3120,3132,3237)
x1 <- cumsum(x0)
n <- length(x0)
b <- numeric(n)
for (i in 1:n){
b[i] <- -(0.5*x1[i + 1] + 0.5*x1[i])
}
b1 <- b[1:n-1]
B <- matrix(1,nrow=n-1,ncol=2)
B[,1] <- t(t(b1[1:n-1]))
yn <- matrix(c(x0),ncol=1)
yn <- t(t(x0[2:n]))
n <- length(x0)
r0 <- numeric(n)
for (i in 1:n){
r0[i] <-x0[i] - x0cap_GM[i]
}
R <- r0[2:n]
rn <- matrix(c(R),ncol=1)
m <- length(rn)
L <- 23
s <- replicate(n,0)
for (i in 1:n){
s[i] <- sin( (2*(i-1)*pi)/L )
}
mat3 <- matrix(c(s[2:n]),ncol=1)
c <- replicate(n,0)
for (i in 1:n){
c[i] <- cos( (2*(i-1)*pi)/L )
}
mat4 <- matrix(c(c[2:n]),ncol=1)
B <- cbind(mat1,mat2,mat3,mat4)
A <- 4
scale_with <- function(k)
{
(x0[1] - (b/a)) * exp(-a*k) * (1 - exp(a))
}
fitted_a <- scale_with(1 : n+A-1)
ndgm11 (ExtendedForms), 9
30