2017-08-09 5 views
0

こんにちはと感謝にARIMAモデルデータを保存しようと、私は私の最初の機能ARIMAモデルのグラフを生成するために管理しているR - 事前にテキストファイル

だから私が持っているコードです。

ここで私が目指しているのは、arimaモデルの予測データをtxtファイルに保存することですが、私は運がまだありません。ここで

は私のコードです:

library(forecast) 
library(ggplot2) 
library(reshape2) 

#TEST DATA AND TEST CODE# 
Quantity <- c(5,3,8,4,0,5,2,7,4,2,6,8,4,7,8,9,4,6) 
Time <- c("2010-01-01", "2010-07-02", "2010-08-03", "2011-02-04", "2011-11-05", "2011-12-06", "2012-06-07", "2012-08-30", "2013-04-16", "2013-03-18", "2014-02-22", "2014-01-27", "2015-12-15", "2015-09-28", "2016-05-04", "2017-11-07", "2017-09-22", "2017-04-04") 
QuantityFrame <- data.frame(Time,Quantity) 
write.table(QuantityFrame,file="C:/....path..../QuantityFrame.txt",quote=F) 

#THE FUNCTION# 
Frame <- read.table("C:/....path..../QuantityFrame.txt", stringsAsFactors=FALSE, header=TRUE) 
Frame$Time <- as.Date(Frame$Time, format= "%Y-%m-%d") 
Frame <- ts(Frame$Quantity, start = 1, end=NROW(Frame), frequency=1) 

TheForecast <- arima(Frame, order = c(10,1,0),method="ML") 
write.table(TheForecast,file="C:/....path..../TheForecast.txt",quote=F) 

#CODE TO PROVIDE AN EXAMPLE GRAPH AND EXAMPLE FORECAST DATA# 
MyForecast <- plot(forecast(TheForecast,h=10)) 
print(TheForecast) 

ので修正しようとしているラインイムがゆえである:

write.table(TheForecast,file="C:/....path..../TheForecast.txt",quote=F) 

私はそれを実行しようとすると、それはグラフを生成しませんがします予測データをtxtファイルに保存します。このエラーが発生します:

Error in as.data.frame.default(x[[i]], optional = TRUE, stringsAsFactors = stringsAsFactors) : 
    cannot coerce class ""Arima"" to a data.frame 

ありがとうございました。

答えて

0

あなただけのxlsxパッケージを使用して予測を保存したい場合:

library(xlsx) 
my_arima <- arima(my_timeseries, order = c(10, 1, 0), method = "ML") 
my_forecast <- forecast(my_arima)  

write.xlsx(my_forecast, "my_forecast.xlsx") 
#remember to setwd() before. 

あなたは有馬結果をエクスポートする場合は、この試してください:で

sink("My_ARIMA.txt") 
    my_arima #since you created it before 
sink() 

または

sink("My_ARIMA.txt") 
    arima(Y, order = c(10, 1, 0), method = "ML") 
sink() 

をauto.arima funcionを見てください。 AR(10)が完全に必要でない可能性があります

関連する問題