Вы находитесь на странице: 1из 13

PABF-Forecasting Model for USA

Gas Retail Prices


By Abhishek Upadhyay
1914071, EPGP,
IIM Bangalore
Co2020
Time Series Plots:
Whole Series:
 Trend Exists
 Seasonality is also evident

Model Period:
Test Period:

Summary of the Series:


Trend:
Seasonality:

Dividing in two equal parts:


Initial Half:
Later Half:
Classical Method:
Box Cox Transformed Model-
The Trend Line:
The Seasonality Index:

Model Period

Box Cox Transformation inversed-


ERROR PLOT for Model Period:

X-squared = 2460.6, df = 12, p-value < 2.2e-16, very small P


value leads to rejection of the hypothesis
Prediction For The Hold Out Period:
Error In Prediction In The Hold-Out Period:

X-squared = 36.507, df = 12, p-value = 0.0002684, very small


P value leads to rejection of the hypothesis
R CODES

##Setting up directory and reading the file


setwd('D:/IIM Bangalore/Term 3/PABF/Assignment')
Gasdata<-read.csv("USAGasPrice.csv")
summary(Gasdata)

##Time Series and Summary

Gasts <‐ ts(Gasdata$Price, start=c(1976,1), frequency=12)


plot(Gasts)
decom.gasts <‐ decompose(Gasts)
plot(decom.gasts$trend)
plot(decom.gasts$seasonal)

##Dividing in two halves and CFs

gts.h1 <‐ window(Gasts, end=c(1991, 12))


gts.h2 <‐ window(Gasts, start=c(1992, 01))
Acf(gts.h1)
Pacf(gts.h1)
Acf(gts.h2)
Pacf(gts.h2)

##Model Period and Hold-Out Period

model.gts <‐ window(Gasts, end=c(2004, 12))


val.gts <‐ window(Gasts, start=c(2005, 01))

##Box Cox Transformation

> y<-BoxCox(model.gts,0.5)
> m1 <- tslm(y ~ trend)
> m1

Call:
tslm(formula = y ~ trend)

Coefficients:
(Intercept) trend
16.30603 0.01745

####Average Percentage Seasonal Index

data <- matrix(y, nrow = 29, byrow = T)


> data <- data.frame(data)
> colnames(data) <- c('Jan','Feb','Mar','Apr','May','Jun','Jul',
+ 'Aug','Sep','Oct','Nov','Dec')
> avgYearData <- apply(data, MARGIN = 1, FUN = mean)
> apData <- data/avgYearData
> apSeasonalIndex <- apply(apData, MARGIN = 2, FUN = mean)

##Model Fitting

> model.fit<-m1$fitted*apSeasonalIndex

##Inverse Box Cox


> inv.model.fit<-InvBoxCox(model.fit,0.5)

> error.model<-model.gts-inv.model.fit
> plot(error.model)

##White Noise Test

> Box.test(error.model, lag = 12, type = "Ljung-Box")


Box-Ljung test

data: error.model
X-squared = 2460.6, df = 12, p-value < 2.2e-16

> acf(error.model)
> pacf(error.model)
> acf(error.model)
> MSE <- round(mean(error.model^2), 2)
> MSE
[1] 425.55
> MAD <- round(mean(abs(error.model)), 2)
> MAD
[1] 17.32
>MAPE <- round(mean(abs(error.model/model.gts)) * 100, 3)
> MAPE
[1] 15.859
> RMSE<-MSE^0.5
> RMSE
[1] 20.62886

Prediction on Hold Out Period:


> Prd<-predict(inv.model.fit, 29)
> error.pred<-val.gts-Prd$mean
> plot(error.pred)

## White Noise Test

> Box.test(error.pred, lag = 12, type = "Ljung-Box")

Box-Ljung test

data: error.pred
X-squared = 36.507, df = 12, p-value = 0.0002684
MAD <- round(mean(abs(error.pred)), 2)
> MAD
[1] 96.26
MSE <- round(mean(error.pred^2), 2)
> MSE
[1] 10261.55
MAPE <- round(mean(abs(error.pred/val.gts)) * 100, 3)
> MAPE
[1] 37.901
RMSE<-MSE^0.5
> RMSE
[1] 101.2993

Вам также может понравиться