Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the use of xreg in auto.arima function?

I am working on predicting the number of customer attending an hospital to perform MR scan per day. I have the daily count of the customers attending the hospital for the last 4 years. But I am not able to capture the daily change in the count of customers attending the hospital for different months accurately.

I am working on Rstudio and I have tried arima as suggested by Rob Hyndman.

modelfitsample<- read.csv("data_xreg_train.csv")
modeltest <- read.csv("data_xreg_test.csv")

ts_beverly_train <- ts(modelfitsample$Volume, start = c(2015,1), frequency=365.25)
ts_beverly_test <- ts(modeltest$Volume, start = c(2018,1), frequency=365)

xreg <- cbind(month=model.matrix(~as.factor(modelfitsample$Month)))
xreg1 <- cbind(month=model.matrix(~as.factor(modeltest$Month)))

modArima <- auto.arima(ts_beverly_train, xreg=xreg)
modArima

fit11 <- forecast(modArima, h=485, xreg = xreg1)

plot(fit11)

I need a prediction that can capture the daily change and also consider the monthly seasonality

like image 732
Prasad Dalvi Avatar asked Oct 24 '25 14:10

Prasad Dalvi


1 Answers

I am suprised no one has come up with an answer to this one.

xreg in forecast::auto.arima and forecast::Arima is used for any external regressors. Lets say you want to model income over a time period (or over a series of job changes, or wage interviews). It is likely that your income tomorrow, depends on your income today, but it is also likely to depend on your sex, age and various other factors. These factors may or may not have a time serial part, for example sex is in most cases constant.

These parts can be included via the xreg argument, specifying the level for each observation in your time series.

like image 119
Oliver Avatar answered Oct 27 '25 02:10

Oliver



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!