# Optimal R function for Predicting Time Series Dataset

Im trying to create a model to predict transactions at a shop. I have the date and hour of the transaction with 4 other predictor variables.

I've provided the first 6 rows of the data below:

Date      Hour   Var1  Var2  Var3  Var4   Trans1  Trans2
01/01/18  1am    4     12    1     123    1       4
01/01/18  2am    6     14    0     126    3       6
01/01/18  3am    3     16    0     124    2       3
01/01/18  4am    4     12    1     122    3       7
01/01/18  5am    8     6     1     122    4       2
01/01/18  6am    4     11    1     123    5       8


I'm looking to predict both Trans1 and Trans2 using the Date, Hour, Var1, Var2, Var3 and Var4.

I've tried using the lm function but I'm unsure how to treat the date and hour variables.

I know that I need to account for seasonal and daily change in the model. What is the best modelling function in r to model this accurately?

https://stats.stackexchange.com/search?q=user%3A3382+hourly+data will give you some pointers as to how you should proceed with hourly data. Essentially daily habits can impact hourly responses/values. Oftentimes daily activity can be predicted using daily indicators, monthly indicators holidays etc. All of the examples that I was involved with could easily been expanded to include covariates. The software I used is available in R so that might help .. Hope this advice helps you .

• These do not appear to be "hourly data" in the sense you imply (despite the regular progression of times in the question's example). These are labeled event data. It is possible--at least going from the description in the question--to have multiple records for a given hour and to have many hours missing because no transaction occurred during them. As such, your proposed methods couldn't even be applied without modification and might be misleading if somehow they were applied. – whuber Jan 10 '19 at 17:45
• i would like the OP to review your comments as it appears to me to be equally spaced data (x hours per day ..not necessarily 24 ). It is possible to analyze data that has say k readings per work day (mon-fri) while having less (but fixed) say Ll readings per day on weekends. – IrishStat Jan 11 '19 at 3:50
• Agreed. Perhaps Trans1 or Trans2 are counts of transactions aggregated by hours, for instance. – whuber Jan 11 '19 at 17:16
• That's how I interpreted it . – IrishStat Jan 11 '19 at 17:18