R for Grey prediction

Source: Internet
Author: User

1. Introduction

The prediction is based on the exploration of the past to speculate and understand the future. Grey prediction is based on the processing of raw data and the establishment of grey model, discovers and grasps the rule of system development, and makes scientific quantitative forecast for the future state of the system. For a specific problem, what kind of forecasting model should be chosen based on the conclusion of sufficient qualitative analysis. The selection of the model is not immutable. A model has to undergo a variety of tests to determine whether it is appropriate and qualified. Only models that pass the test can be used for prediction. This chapter will briefly introduce the concept of grey number and grey prediction, the construction, test and application of grey Prediction model, and finally the principle of catastrophe prediction.

The generation and development of grey system theory

    • 1982 The first Chinese paper, "Grey control System", was published by Deng Ju-long, marking the birth of the grey system.
    • 1985 Gray System Research Institute was established, the grey system related study develops rapidly.
    • 1989 the publication of the English edition of the Journal of Grey System, published in the same year, the English edition of the International publication "Grey System". At present, the international and domestic more than 200 kinds of periodicals published grey system papers, many international conferences to the grey system as a discussion topic. The international famous search has searched the Chinese scholar's grey system treatise more than 500 times. The application of Grey system theory has been extended to many scientific fields, such as industry, agriculture, society, economy, energy, geology and petroleum, and has successfully solved a large number of practical problems in production, life and scientific research, and achieved remarkable results.

The difference between grey system and fuzzy mathematics and black-box method

    • Mainly lies in the system connotation and the extension treatment attitude is different, the research object connotation and the extension nature is different.
    • The grey system focuses on the object of explicit denotation and ambiguous connotation, and fuzzy mathematics focuses on the object of ambiguous extension and explicit connotation.
    • The "black Box" method focuses on the processing method of the external behavior data of the system, is a causal relationship of two households, so that the extension and abandon the connotation of the treatment method, and the gray system method is the extension of the connotation of the method.
2.GM (2.1) R language implementation of R source code
#灰色预测模型G (1,1) GM11<-function (x0,t) {#x0为输入学列, T is the number of predictions X1<-cumsum (x0) #一次累加生成序列1-AG0 sequence (cumulative sequence) b<-numeric (Length (x0)-1# initialization Length (x0)-1 Integer Part of the numeric type with a value of 0 for the DataSet B N<-length (x0)-1# N is length (x0)-1 length due to the need to generate mean (near mean) generation sequence with a 1 less length for(Iinch 1: N) {#生成x1的紧邻均值生成序列 B[i]<--(x1[i]+x1[i+1])/2B} #得序列b, which is a sequence D for the immediate mean of X1<-numeric (Length (x0)-1) d[]<-1B<-Cbind (b,d) #作B矩阵 BT<-T (B) #B矩阵转置 M<-solve (bt%*%b) #求BT *b to Inverse YN<-numeric (Length (x0)-1) YN<-x0[2: Length (x0)] Alpha<-m%*%bt%*%YN #模型的最小二乘估计参数列满足alpha尖 alpha2<-matrix (alpha,ncol=1# Turns the result into a column # Two coefficients of a given equation<-alpha2[1] U<-alpha2[2] # OUTPUT parameter estimates and analog values for the results are as follows Cat ("GM (max) Parameter estimates:",'\ n',"Development coefficient-a=",-A,"  ","Grey Action Amount u=", U,'\ n','\ n') #利用最小二乘法求得参数估计值a, u y<-numeric (Length (C (1: t))) # T for the given number of predictions y[1]<-x1[1] # The first number is the same for(Winch 1:(T1) {#将a, the estimated value of U substituting the time response sequence function calculates the X1 fitting sequence y y[w+1]<-(x1[1]-u/a) *exp (-a*w) +u/A} cat ("analog value of x (1):",'\ n'Y'\ n') XY<-numeric (length (y)) xy[1]<-y[1]   for(Oinch 2: T) {#运用后减运算还原得模型输入序列x0预测序列 Xy[o]<-y[o]-y[o-1]} cat ("analog value of x (0):",'\ n'Xy'\ n','\ n') # calculation residuals e e<-Numeric (length (x0)) for(linch 1: Length (x0)) {E[l]<-x0[l]-Xy[l] #得残差序列 (absolute value not taken)} cat ("Absolute Residual error:",'\ n'E'\ n') #计算相对误差 E2<-Numeric (length (x0)) for(sinch 1: Length (x0)) {E2[s]<-(ABS (E[s])/x0[s]) #得相对误差} cat ("Relative residuals:",'\ n', E2,'\ n','\ n') Cat ("residual sum of squares =", SUM (e^2),'\ n') Cat ("Average Relative error =", SUM (E2)/(Length (E2)-1)* -,"%",'\ n') Cat ("Relative precision =",(1-(SUM (E2)/(Length (E2)-1)))* -,"%",'\ n','\ n') #后验差比值检验 Avge<-mean (ABS (e)); Esum<-sum ((ABS (e)-avge) ^2); evar=esum/(Length (e)-1); se=sqrt (evar) #计算残差的均方差se avgx0<-mean (x0); X0sum<-sum ((x0-avgx0) ^2); x0var=x0sum/(length (x0)); sx=sqrt (x0var) #计算原序列x0的方差sx CV<-se/SX #得验差比值 (variance ratio) Cat ("test of posterior difference ratio:",'\ n',"c value =", CV,'\ n'#对后验差比值进行检验, compared with the general standard to judge the results of the prediction is good or bad. #计算小残差概率 P<-sum ((ABS (e)-avge) <0.6745*SX)/Length (e) Cat ("The probability of small residual error:",'\ n',"P-value ="P'\ n')    if(CV <0.35&& p>0.95) {Cat ("c<0.35, P>0.95,GM (a) The predictive accuracy rating is: Good",'\ n','\ n')  }Else{    if(cv<0.5&& p>0.80) {Cat ("the C value belongs to [0.35,0.5], and the P>0.80,GM (max) model predicts the accuracy level: qualified",'\ n','\ n')    }Else{      if(cv<0.65&& p>0.70) {Cat ("the C value belongs to [0.5,0.65], and the P>0.70,GM (max) model predicts the accuracy level: barely qualified",'\ n','\ n')      }Else{Cat ("C-Value >=0.65, GM (max) Model Prediction Accuracy class: unqualified",'\ n','\ n')}}} #画出输入序列x0的预测序列及x0的比较图像 plot (Xy,col='Blue', type='b', pch= -, xlab='Time Series', ylab='value') points (X0,col='Red', type='b', pch=4) Legend ("TopLeft"C'Forecast','Original'), title ="Forecast Timing vs. original timing", Pch=c ( -,4), Lty=l,col=c ('Blue','Red'))}
2.2 GM11 Test
> X<-c (2.67,3.13,3.25,3.36,3.56,3.72)> GM11 (x,length (x) +2) GM (1,1) parameter estimate: Development factor-a=0.04396098Grey Action Amount u=2.925617x (1) of the analog values:2.67 5.78087 9.031547 12.42832 15.97774 19.68668 23.56231 27.61211x (0) of the analog values:2.67 3.11087 3.250677 3.396768 3.549424 3.708941 3.875626 4.049803Absolute Residual error:0 0.01913011-0.0006772995-0.03676788 0.010576 0.01105927Relative residuals:0 0.006111858 0.0002083999 0.01094282 0.002970786 0.002972921sum of squares of residual difference=0.001952456Average relative error=0.4641357%Relative accuracy=99.53586%Posterior difference ratio test: C Value=0.0407599probability of small residual error: P-value=1C<0.35, p>0.95, GM (1,1) The predictive accuracy level is: OK

This article link: http://www.cnblogs.com/homewch/p/5783073.html

R for Grey prediction

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.