# Time as an independent variable in multiple regression

Can we chose time (t) as one of the independent variables in multiple (OLS) regression?

• can you share more context about your problem? – gunes Mar 11 '19 at 9:03
• It is possible in principle, but please consider making a time-series model instead if you expect observations that are closer in time to have an effect on each other – David May 28 '19 at 13:05
• You can do it. The trick is making sense of what you are doing. You're saying that there is a trend with time quite separate from how the other predictors are varying. – Nick Cox May 28 '19 at 13:18

This is a very open question as you're not specifying what type of time measurement you want to add to your model, but the answer is always yes.

If you're thinking about a linear relationship with time (e.g. age vs time) then you can always represent a date as a number of milliseconds or days and add it to your model as a regular continuous variable (your age is explained by the number of milliseconds since a date X, and 8.64e7 milliseconds extra will add 1/365 years to your age).

On the other hand, if you're thinking about a not so linear effect of a date (seasonality, e.g. increase in sales in December due to Christmas), then you'd need to transform the part of the date you're interested in into a categorical variable (in this case, a binary feature that will tell you whether or not you're in December).

• It was a very general question. I wanted to know if there was any violation of laws in choosing time as an independent variable in an ols regression – Dom Jo Mar 11 '19 at 9:46
• +1 The trick is that time series have serial correlation, cycles, and tend to saturate. If you can take all of that into account, you're good. But using OLS with just time thrown in as a variable instead of a technique that accounts for such things is skating on thin ice. – Wayne May 28 '19 at 13:04

In my opinion ,,, There is no violation in using time as an independent variable thus Yes "one can include time as an independent/predictor". Auto-regression versus linear regression of x(t)-with-t for modelling time series includes a discussion and a worked example.

The problem comes when one tries to use powers of time like time squared , time cubed etc as predictor variables for purposes of extrapolation (and even interpolation) . See How to extrapolate this simple trend line into the future for the purpose of forecasting in Matlab? @Ben's comments about the dangers of polynomial fitting.

Note that many "EARLIER" textbooks in the BC (BEFORE CORRELATION) era , used examples of fitting time polynomials to data .... seriously flawed in my opinion.

WARNING : BAD APPROACH FOLLOWS !

As an example of what not to do ( always dangerous ! )... Here is quarterly data from an "easy to read popular forecasting text" . Yielding the following not-so-useful equation (user-specified) with an incredibly deficient residual plot here and Actual/Fit/Forecast here .

The answer depends on the underlying process. If the true underlying process is $$y_i=\alpha+v t_i+\beta X_i +\varepsilon_i$$ then yes, you can regress on time. For instance, you are measuring the temperature of an electric kettle when boiling water. Suppose, your $$X$$ variables are weight of a kettle, power rating of a kettle, amount of water, the temperature in the room. You're trying different kettles and filling with various amount of water etc. In other words, you're controlling the experiment.