-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathARIMA_Model_Forecasting.R
91 lines (52 loc) · 3.18 KB
/
ARIMA_Model_Forecasting.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
################### Final parameters (p,d,q) for the prediction ##################
order.arima.fit
#### this can be further improved given more time #####
############################################################################
########################################################################################################################################################
############################### FORECASTING ################################################################################################
########################################################################################################################################################
##################### FORECASTING USING THE MODEL FIT FOR NEXT 18 MONTHS #######################
for(j in 1:20){
print("")
print(paste(" Forecasting of ", city.name[j], " for ", order.arima.fit[j]," and Statistics are shown below:"))
print("------------------------------------------------------------------")
pred.SPIndex.Name<- paste("pred.SPIndex",city.name[j], sep=".")
#assign(pred.SPIndex.Name, predict(eval(parse(text=model.fit.ByName[j])), n.ahead=18, se.fit = TRUE))
assign(pred.SPIndex.Name, forecast(eval(parse(text=model.fit.ByName[j])), h=18))
print(eval(parse(text=pred.SPIndex.Name)))
print("#####################################################################")
}
pred.SPIndex.AZ_Phoenix
##############################################################################
########################### plotting the prediction ##########################
##############################################################################
for(i in 1:20){
plot.dir<- paste(sp.PredictionsPlots, city.name[i],sep="/")
pdf(paste(plot.dir,".pdf",sep=""))
print(city.name[i])
plot(eval(parse(text=paste("pred.SPIndex", city.name[i],sep="."))),
main=paste(city.name[i],": 18 Months Forecasting") , xlab = "Year", ylab = "Index", ylim = c(50,275),
panel.first=grid(nx=4,ny=10, col="red",lty = "dotted"))
dev.off()
}
##############################################################################
########################### Exporting the prediction ##########################
##############################################################################
pred.SPIndex.JustName<-c()
for(i in 1:20){
pred.SPIndex.JustName[i]<- paste("pred.SPIndex",city.name[i], sep=".")
}
#pred.SPIndex.JustName[1]
trial.df00<- as.data.frame(c())
for(i in 1:20){
trial.df0<- as.data.frame(t(tapply(eval(parse(text=pred.SPIndex.JustName[i]))$mean,
list(year = floor(time(eval(parse(text=pred.SPIndex.JustName[i]))$mean)),
month = month.abb[cycle(eval(parse(text=pred.SPIndex.JustName[i]))$mean)]),c)))
trial.df0$Region<- city.name[i]
trial.df00<- rbind(trial.df0,trial.df00)
}
tail(trial.df00)
# saving the dataset in csv format
write.table(trial.df00, file="PredictedValues.csv", sep=",")
###########################################################################################
###########################################################################################