如何使用Plotmo打印arima对象
我想使用plotmo软件包中的plotmo指令来绘制arima对象,我用解释变量X(传递函数)矩阵估计arima模型 arima.model 不是真的适用于时间序列模型,比如arima模型 不支持他们 但是,如果您只想绘制已安装的模型和一些未来 值,以下函数将执行此操作(可能有更简单的 使用如何使用Plotmo打印arima对象,plot,arima,sql-server-mars,Plot,Arima,Sql Server Mars,我想使用plotmo软件包中的plotmo指令来绘制arima对象,我用解释变量X(传递函数)矩阵估计arima模型 arima.model 不是真的适用于时间序列模型,比如arima模型 不支持他们 但是,如果您只想绘制已安装的模型和一些未来 值,以下函数将执行此操作(可能有更简单的 使用ts.plot功能的方式: 给出了以下曲线图 (我假设您使用的是来自 标准统计数据包。我认为预测数据包 具有arima函数。) plarima <- function(ts, ..., n.ahead
ts.plot
功能的方式:
给出了以下曲线图
(我假设您使用的是来自
标准统计数据包。我认为预测数据包
具有arima函数。)
plarima <- function(ts, ..., n.ahead=1, main=deparse(substitute(ts)))
{
model <- arima(ts, ...)
if(!inherits(model, "Arima"))
stop("this function requires 'arima' from the standard stats package")
# calculations so we can extend the x axis
n <- length(ts)
x <- xy.coords(ts)$x
if(any(is.na(x)))
stop("NA in time")
xdelta <- (x[n] - x[1]) / n
plot(ts + model$residuals, # plot the fit in gray
xlim=c(x[1], x[n] + xdelta * n.ahead),
main=main, col="gray", lwd=3)
lines(ts) # plot the data
# predict n.ahead values and plot them in red
forecast <- predict(model, n.ahead=n.ahead)
lines(x=x[n] + xdelta * (0:n.ahead), y=c(ts[n], forecast$pred), col=2)
legend("topleft", legend=c("data", "fitted", "forecast"),
col=c(1, "gray", 2), lwd=c(1,3,1), lty=1, bg="white")
model # return the arima model
}
plarima(lh, order=c(3,0,0), n.ahead=10)
plarima(USAccDeaths, order=c(0,1,1), seas=list(order=c(0,1,1)), n.ahead=10)