3

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

Oliver
  • 8,169
  • 3
  • 15
  • 37
Prasad Dalvi
  • 55
  • 1
  • 11
  • Welcome to SO. Prior to asking these questions you should read [how to ask](https://stackoverflow.com/help/how-to-ask), in order to make it easier to help you out, and to not waste time for those who spent their free-time answering questions on SO. For starters this question has **nothing** to do with excel, sas or python, as such these tags should not be included. Also you have no question in your question body. – Oliver May 15 '19 at 06:57
  • 1
    Thanks for your feedback. I will keep this in mind the next time I upload a question. – Prasad Dalvi May 24 '19 at 07:44

1 Answers1

4

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.

Oliver
  • 8,169
  • 3
  • 15
  • 37
  • Just wanted to add that including constant features in the xreg argument will throw an error https://github.com/robjhyndman/forecast/issues/699 – KasperGL Sep 07 '22 at 14:27