# Logistic Regression on Time Series Data

I would like to forecast the probability of a binary outcome using logistic regression at t+1, using all previous data points. I am new to forecasting so any help would be appreciated.

The raw data is in the form:

Time | Correct
1      0
1      1
2      1
3      0
3      0
3      1
4      1
5      0


I have averaged the data over each day to produce:

Time | AVG. Correct
1      0.5
2      1
3      0.3
4      1
5      0


I know that there is a linear trend in the data, such that as time progresses the average correct value increases.

Using this information would it be possible to use logistic regression to forecast the next time step (t = 6). How would you account for the linear trend in the data for a logistic regression model?.

• Sorry, what is the data actually? And when you say linear trend, what you mean is that the probability of it being a 1 increases as time increases? But you want to ignore that trend? – bibliolytic Oct 5 '17 at 13:02
• – Tim Feb 15 '18 at 16:39

You could fit a simple logistic regression model and include time as a covariate, this would imply a linear time trend.

Note that in the regression, the time trend is negative and insignificant – you simply have too few observations to make any statements regarding the coefficient of a linear time trend.

See this R-code:

# data input
dat <- data.frame(time=c(1,1,2,3,3,3,4,5),
correct=c(0,1,1,0,0,1,1,0))

res <- glm(correct ~ time + 1, data=dat, family=binomial)

summary(res)
# the time trend is negative and insignificant!

# predict 'correct' probability at time t=6
predict(res, newdata=data.frame(time=6), type="response")

# 0.2710599

• Thanks for your response, the data is just a made up example. Could you please explain what you mean as having the time as the covariate? – Sagar Patel Jun 13 '17 at 17:28
• I mean that time should be a right-hand-side variable (regressor, covariate, independent variable, explanatory variable) in a logistic regression model. – mzuba Jun 14 '17 at 12:09
• This is attempting to model correctness as a function of time? But...just...why? – bibliolytic Oct 5 '17 at 13:05
• 'correct' is simply the name of the LHS variable. I do not think that it has a meaningful interpretation in the context of modelling itself. – mzuba Oct 5 '17 at 17:00