您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 管理学资料 > 时间序列分析与R软件
一、1.时序图程序:da-read.table(d:/ss.txt,header=T)dim(da)y=da[,1]m=da[,2]basicStats(m)plot(y,m,type='l')title(main='financialincomeofChina:1978-2010')2.时序图:3.运行结果da-read.table(d:/ss.txt,header=T)dim(da)[1]332y=da[,1]m=da[,2]basicStats(m)mnobs3.300000e+01NAs0.000000e+00Minimum1.132260e+03Maximum8.310151e+041.Quartile2.122010e+033.Quartile1.890364e+04Mean1.558852e+04Median5.218100e+03Sum5.144212e+05SEMean3.764607e+03LCLMean7.920268e+03UCLMean2.325678e+04Variance4.676848e+08Stdev2.162602e+04Skewness1.716219e+00Kurtosis1.927834e+00plot(y,m,type='l')title(main='financialincomeofChina:1978-2010')二、1.取对数:da-read.table(d:/ss.txt,header=T)dim(da)y=da[,1]logm=log(da[,2])basicStats(logm)plot(y,logm,type='l')title(main='financialincomeofChina:1978-2010')2.时序图:3.运行结果da-read.table(d:/ss.txt,header=T)dim(da)[1]332y=da[,1]logm=log(da[,2])basicStats(logm)logmnobs33.000000NAs0.000000Minimum7.031971Maximum11.3278181.Quartile7.6601193.Quartile9.847110Mean8.770055Median8.559889Sum289.411829SEMean0.238490LCLMean8.284268UCLMean9.255843Variance1.876952Stdev1.370019Skewness0.344385Kurtosis-1.253017plot(y,logm,type='l')title(main='financialincomeofChina:1978-2010')三、1.一阶差分:da-read.table(d:/ss.txt,header=T)dim(da)y=da[,1]dy1=diff(log(da[,2]),lag=1)basicStats(dy1)plot(dy1,type='l')title(main='financialincomeofChina:1978-2010')2.时序图:3.运行结果da-read.table(d:/ss.txt,header=T)dim(da)[1]332y=da[,1]dy1=diff(log(da[,2]),lag=1)basicStats(dy1)dy1nobs32.000000NAs0.000000Minimum0.011751Maximum0.2807211.Quartile0.0903963.Quartile0.182613Mean0.134245Median0.145147Sum4.295847SEMean0.012126LCLMean0.109514UCLMean0.158976Variance0.004705Stdev0.068595Skewness-0.275913Kurtosis-0.779477四、对取对数之后的一阶差分序列作ACF、PACF检验:da-read.table(d:/ss.txt,header=T)dim(da)y=da[,1]dy1=diff(log(da[,2]),lag=1)basicStats(dy1)plot(dy1,type='l')title(main='financialincomeofChina:1978-2010')acf(dy1,lag.max=16)x1=acf(dy1,lag.max=16)names(x1)x1$acfx2-pacf(dy1,lag.max=16)names(x2)x2$acfBox.test(dy1,lag=5,type=Ljung)结果:acf(dy1,lag.max=16)x1=acf(dy1,lag.max=16)names(x1)[1]acftypen.usedlagseriessnamesx1$acf,,1[,1][1,]1.00000000[2,]0.61446389[3,]0.26257292[4,]0.15751573[5,]0.09459312[6,]0.09790530[7,]0.16125285[8,]0.16479148[9,]0.20080589[10,]0.18046074[11,]0.15628862[12,]0.16030315[13,]0.05421514[14,]-0.10143694[15,]-0.17761647[16,]-0.19570709[17,]-0.17343596x2-pacf(dy1,lag.max=16)names(x2)[1]acftypen.usedlagseriessnamesx2$acf,,1[,1][1,]0.614463886[2,]-0.184747174[3,]0.132881921[4,]-0.053649679[5,]0.102291537[6,]0.095482705[7,]0.008184179[8,]0.144278515[9,]-0.040743428[10,]0.089343755[11,]0.031788526[12,]-0.145686648[13,]-0.130393558[14,]-0.119797298[15,]-0.075255138[16,]-0.068836650Box.test(dy1,lag=5,type=Ljung)Box-Ljungtestdata:dy1X-squared=17.417,df=5,p-value=0.003774取对数之后一阶差分的时序图显示序列没有显著的非平稳特征,自相关图显示除了延迟1阶的自相关系数在2倍标准差范围之外,其他阶数的自相关系数都在2倍标准差范围内波动。可以判断该序列具有短期相关性,进一步确定序列平稳。且自相关系数和偏自相关系数都显示不截尾的特征,所以考虑建立ARMA(1,1)模型。3.模型定阶ARMA(1,1)、AR(1)、MA(1)(1)ARMA(1,1):m1=arima(dy1,order=c(1,0,1))dy1运行结果:Call:arima(x=dy1,order=c(1,0,1))Coefficients:ar1ma1intercept0.43990.45220.1335s.e.0.21170.19010.0216sigma^2estimatedas0.002378:loglikelihood=50.85,aic=-93.71(2)AR(1)dy2=arima(dy1,order=c(1,0,0))dy2运行结果:Call:arima(x=dy1,order=c(1,0,0))Coefficients:ar1intercept0.67760.1306s.e.0.13580.0263sigma^2estimatedas0.002591:loglikelihood=49.58,aic=-93.15(3)MA(1)dy3=arima(dy1,order=c(0,0,1))dy3运行结果:Call:arima(x=dy1,order=c(0,0,1))Coefficients:ma1intercept0.65160.1342s.e.0.09680.0149sigma^2estimatedas0.002679:loglikelihood=49.08,aic=-92.15AIC最小,所以ARMA(1,1)最优。四、对ARMA(1,1)检查残差序列是否白噪声Box.test(m1$residuals,lag=16,type=Ljung)Box-Ljungtestdata:m1$residualsX-squared=7.3994,df=16,p-value=0.9648P0.05,是白噪声。五、模型预测predict(m1,3)结果:predict(m1,3)$predTimeSeries:Start=33End=35Frequency=1[1]0.19390880.16009550.1452211$seTimeSeries:Start=33End=35Frequency=1[1]0.048764370.065349940.06809450dy1[1]0.012393520.011750510.013580600.030603870.120037850.18385664[7]0.199115660.056809470.035798110.069329580.122675090.09725617[13]0.069814660.100762860.221934220.182198910.179199330.17122646[19]0.155131960.132411400.147370060.157426110.201531080.14292474[25]0.138660280.195215510.181485430.202678230.280721280.17815960[31]0.110826040.19296201预测的未来三年(即2011、2012、2013年)的取对数之后差分的指标为:0.19390880.16009550.1452211。将我们查到的真实数据之间取对数之后差分,0.096899738,0.052617236,0.042169027。两者的数值相比较,可以看出
本文标题:时间序列分析与R软件
链接地址:https://www.777doc.com/doc-2310927 .html