後來有找到可以更直覺看出預測是否準確的作圖方法,畢竟R語言比起其他程式語言我認為更厲害的其中一個就是他的繪圖能力了吧。
library(forecast)
newdata_1 = ts(as.vector(newdata[1:162]),frequency=12,start=c(2005,1))
newdata_t = ts(as.vector(newdata[1:150]),frequency=12,start=c(2005,1))
newdata_test =ts(as.vector(newdata[150:162]),frequency=12,start=c(2017,7))
q = forecast(newdata_t,h = 12)
plot(q)
lines(newdata_1,col="red")
arima1<-auto.arima(newdata_t,trace=T)
#這裡的order=c(2,1,1),seasonal=c(1,0,1))是auto.arima告訴我的
plot(forecast(Arima(newdata_t,order=c(2,1,1),seasonal=c(1,0,1)),h=12))
lines(newdata_1,col="red")
#去除NA值的另外一個想法(整行刪掉的部分)
A = c(1,2,3,4,5)
B = c(1,2,3,4,4)
C = cbind(A,B)
D = (na.omit(C))
for(i in 1:length(D[1,])){
if(i==1){
E<-D[,i]
}else{
E<-cbind(E,D[,i])
}
}