1. Modeling
# #建立灰色模型GM (1,1) corresponds to the function
# #x表示原始数据数列, K indicates the number of data
Gm11<-function (x,k)
{
n<-length (x)
x1<-numeric (n);
For (i in 1:n) # #一次累加
{
x1[i]<-sum (x[1:i]);
B<-numeric (n)
m<-n-1 for
(j in 1:m)
{
b[j+1]<-(0.5*x1[j+1]+0.5*x1[j)) # #紧邻均值生成
}
Yn=t (t (X[2:n])) # #构造Yn矩阵
B<-matrix (1,nrow=n-1,ncol=2)
b[,1]<-t (t (-b[2:n)) # #构造B矩阵
A<-solve (t (b)%*%b)%*%t (b)%*%yn; # #使用最小二乘法求得灰参数a, u
a<-a[1];
u<-a[2];
X2<-numeric (k);
x2[1]<-x[1];
For (i in 1:k-1)
{
x2[1+i]= (x[1]-u/a) *exp (-a*i) +u/a;
}
X2=c (0,X2);
Y=diff (x2); # #累减生成, get the forecast data series
y
}
# #x1原始数据数列, X2 is the forecast data series
X1<-x
X2<-GM11 (X,length (x))
# #检验模型精度
Acc<-function (x1,x2)
{
n<-length (x1);
sum1=0;
For (k in 2:n-1)
{
sum1<-sum1+ (x1[k]-x1[1]);
}
s1<-sum1+0.5* (x1[n]-x1[1]);
sum2=0;
For (k in 2:n-1)
{
sum2<-sum2+ (x2[k]-x2[1]);
}
s2<-sum2+0.5* (x2[n]-x2[1]);
Abs1<-abs (S1) abs2<-abs (S2) abs12<-abs (S1-S2) ee<-(1+ABS1+ABS2)
/(1+ABS1+ABS2+ABS12)
ee
}
2, Application: Forecast 2013 and 2014 national scale above express enterprise income
# #x数列是2008年-2012 National-scale Express Enterprise income data (Source: National Post Office, Unit: billion)
> x<-c (408.40,479.00,574.60,758.00,1055.30)
> Gm11 (x,7)
[1] 408.4000 443.1355 585.3243 773.1370 1021.2131 1348.8894 1781.7069
> X1<-x
> X2<-gm11 (x,length (x))
> ACC (X1,X2)
[1] 0.9851449
forecast Result: 2013, 2014 national scale above express enterprise income is 134.9 billion yuan, 178.2 billion yuan respectively
The grey absolute correlation degree is 0.9851449, that is, the correlation degree is the first level, and the prediction precision is excellent.