楼主: NewOccidental
13281 123

[读者文库]Introduction to Time Series Analysis and Forecasting(using R)   [推广有奖]

21
wolfsword(真实交易用户) 发表于 2015-6-20 10:53:45
Example 4.8
The liquor store sales data are in the second column of the array called liqsales.data in which the first column is the month of the year. We will first fit additive and multiplicative seasonal models to the entire data to see the difference in the fits. Then we will use the data up to December 2003 to fit the multiplicative model and make forecasts for the coming year (2004). We will once again use Holt–Winters function given in stats package. In all cases we set all parameters to 0.2.

  1. y.ts<- ts(liqsales.data[,2], start = c(1992,1), freq = 12)
  2. liq.hw.add<-HoltWinters(y.ts,alpha=0.2,beta=0.2,gamma=0.2,
  3. seasonal="additive")
  4. plot(y.ts,type="p", pch=16,cex=.5,xlab='Date',ylab='Sales',
  5. main="Additive Model")
  6. lines(liq.hw.add$fitted[,1])
  7. liq.hw.mult<-HoltWinters(y.ts,alpha=0.2,beta=0.2,gamma=0.2,
  8. seasonal="multiplicative")
  9. plot(y.ts,type="p", pch=16,cex=.5,xlab='Date',ylab='Sales',
  10. main="Multiplicative Model")
  11. lines(liq.hw.mult$fitted[,1])
  12. y1<-liqsales.data[1:144,]
  13. y1.ts<-ts(y1[,2], start = c(1992,1), freq = 12)
  14. liq.hw1<-HoltWinters(y1.ts,alpha=0.2,beta=0.2,gamma=0.2,
  15. seasonal="multiplicative")
  16. y2<-liqsales.data[145:156,]
  17. y2.ts<-ts(y2[,2],start=c(2004,1),freq=12)
  18. y2.forecast<-predict(liq.hw1, n.ahead=12, prediction.interval =
  19. TRUE)
  20. plot(y1.ts,type="p", pch=16,cex=.5,xlab='Date',ylab='Sales',
  21. xlim=c(1992,2005))
  22. points(y2.ts)
  23. lines(y2.forecast[,1])
  24. lines(y2.forecast[,2])
  25. lines(y2.forecast[,3])
复制代码


已有 1 人评分论坛币 收起 理由
Nicolle + 20 精彩帖子

总评分: 论坛币 + 20   查看全部评分

22
ZZQGIS(真实交易用户) 在职认证  发表于 2015-6-20 10:54:59
Example 5.1
The loan applications data are in the second column of the
array called loan.data in which the first column is the number of weeks.
We first plot the data as well as the ACF and PACF.
  1. plot(loan.data[,2],type="o",pch=16,cex=.5,xlab='Week',ylab='Loan
  2. Applications')

  3. par(mfrow=c(1,2),oma=c(0,0,0,0))
  4. acf(loan.data[,2],lag.max=25,type="correlation",main="ACF for the
  5. Number \nof Loan Applications")
  6. acf(loan.data[,2], lag.max=25,type="partial",main="PACF for the
  7. Number \nof Loan Applications")

  8. #Fit an ARIMA(2,0,0) model to the data using arima function in the stats
  9. package.
  10. loan.fit.ar2<-arima(loan.data[,2],order=c(2, 0, 0))
  11. loan.fit.ar2

  12. res.loan.ar2<-as.vector(residuals(loan.fit.ar2))
  13. #to obtain the fitted values we use the function fitted() from
  14. #the forecast package
  15. library(forecast)
  16. fit.loan.ar2<-as.vector(fitted(loan.fit.ar2))
  17. Box.test(res.loan.ar2,lag=48,fitdf=3,type="Ljung")
  18. #ACF and PACF of the Residuals
  19. par(mfrow=c(1,2),oma=c(0,0,0,0))
  20. acf(res.loan.ar2,lag.max=25,type="correlation",main="ACF of the
  21. Residuals \nof AR(2) Model")
  22. acf(res.loan.ar2, lag.max=25,type="partial",main="PACF of the
  23. Residuals \nof AR(2) Model")

  24. #4-in-1 plot of the residuals
  25. par(mfrow=c(2,2),oma=c(0,0,0,0))
  26. qqnorm(res.loan.ar2,datax=TRUE,pch=16,xlab='Residual',main='')
  27. qqline(res.loan.ar2,datax=TRUE)
  28. plot(fit.loan.ar2,res.loan.ar2,pch=16, xlab='Fitted Value',
  29. ylab='Residual')
  30. abline(h=0)
  31. hist(res.loan.ar2,col="gray",xlab='Residual',main='')
  32. plot(res.loan.ar2,type="l",xlab='Observation Order',
  33. ylab='Residual')
  34. points(res.loan.ar2,pch=16,cex=.5)
  35. abline(h=0)

  36. Plot fitted values
  37. plot(loan.data[,2],type="p",pch=16,cex=.5,xlab='Week',ylab='Loan
  38. Applications')
  39. lines(fit.loan.ar2)
  40. legend(95,88,c("y(t)","yhat(t)"), pch=c(16, NA),lwd=c(NA,.5),
  41. cex=.55)
复制代码


已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

23
lzguo568(真实交易用户) 在职认证  发表于 2015-6-20 10:56:06
Example 6.2
The data for this example are in the array called vistemp. data of which the two columns represent the viscosity and the temperature respectively. Below we first start with the prewhitening step.
  1. xt<-vistemp.data[,1]
  2. yt<-vistemp.data[,2]
  3. par(mfrow=c(2,1),oma=c(0,0,0,0))
  4. plot(xt,type="o",pch=16,cex=.5,xlab='Time',ylab=expression
  5. (italic(x[italic(t)])))
  6. plot(yt,type="o",pch=16,cex=.5,xlab='Time',ylab= expression
  7. (italic(y[italic(t)])))
复制代码



已有 1 人评分论坛币 收起 理由
Nicolle + 20 鼓励积极发帖讨论

总评分: 论坛币 + 20   查看全部评分

&amp;amp;lt;img src=&amp;amp;amp;quot;static/image/smiley/comcom/5.gif&amp;amp;amp;quot; class=&amp;amp;amp;quot;vm&amp;amp;amp;qu

24
...CTtian@(未真实交易用户) 学生认证  发表于 2015-6-20 10:56:51
读研究生的时候看过,现在读博一了。

25
xbz(真实交易用户) 在职认证  发表于 2015-6-20 10:57:51

26
ZZQGIS(真实交易用户) 在职认证  发表于 2015-6-20 10:58:10
谢谢分享。。

27
shan599603(真实交易用户) 发表于 2015-6-20 11:04:21
是新書阿 支持一下

28
susilila(未真实交易用户) 在职认证  发表于 2015-6-20 11:05:12
I have been searching this book and surely will read it soon

29
dafen(真实交易用户) 发表于 2015-6-20 11:13:12
好书  谢谢分享!!!

30
cauofhom(真实交易用户) 发表于 2015-6-20 11:18:00
楼猪有情怀

您需要登录后才可以回帖 登录 | 我要注册

本版微信群
加好友,备注jltj
拉您入交流群
GMT+8, 2026-1-22 22:31