全部版块 我的主页
论坛 数据科学与人工智能 数据分析与数据科学 R语言论坛
1716 0
2016-09-26
大神们好:
小弟学习R语言不久,现在在看时间序列方面的书,其中有3个问题吧,一直想了好久不知道怎么解决,现在向大神们求助:

1,
electricity.txt
大小:(5.32 KB)

 马上下载




为发电量时间序列,我想对其进行预测分析,现在代码如下:
data("electricity")
plot(log(electricity))
month. <- season(electricity)
trend <- time(electricity)
lm.sol <- lm(log(electricity) ~ month. + trend - 1)
summary(lm.sol)
lines(x = as.vector(time(electricity)), y = fitted(lm.sol),
      col = 'red', lty = 2, type = 'l', lwd = 2)

从图中看模拟结果还算不错,

黑线为实际发电量,红虚线为拟合值。

现在的疑问是不知道怎么进行预测,predict函数不会写。。。

2,针对这个题目,有这样的参考答案:
data(electricity);
month.=season(electricity); trend=time(electricity)
model=arima(log(electricity),order=c(0,0,0),
              xreg=as.matrix(model.matrix(~month.+trend-1))[,-1])
newmonth.=season(ts(rep(1,24),start=c(2006,1),freq=12))
newtrend=time(electricity)[length(electricity)]+(1:24)*deltat(electricity)
result=plot(model,n.ahead=24,n1=c(2001,1),ylab='Electricity',xlab='Year',
              newxreg=as.matrix(model.matrix(~newmonth.+ newtrend-1))[,-1],pch=19,transform=exp)

请问标红的[,-1]是怎么回事?为什么要减掉这一列呢?

3,关于acf函数,为什么有的时间序列就能直接用acf函数,而有的却需要as.vector一下呢?
例arima为时间序列,为什么有的可以直接acf(arima),而有的却需要acf(as.vector(arima))呢?

问的有点乱,请大神解答,谢过。。。
附件列表
拟合图.jpg

原图尺寸 22.73 KB

拟合图.jpg

二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群