This is an example of my timeseries data:
df<-tibble::tribble(
~ID, ~Month1, ~Month2, ~Month3, ~Month4, ~Month5, ~Month6, ~Month7, ~Month7,
1L, 1L, 1L, 1L, 0L, 0L, 1L, 1L, 1L,
2L, 1L, 1L, 0L, 1L, 0L, 0L, 0L, 1L,
3L, 1L, 1L, 1L, 1L, 0L, 1L, 0L, 0L,
4L, 1L, 0L, 0L, 0L, 1L, 0L, 1L, 1L,
5L, 1L, 0L, 1L, 0L, 1L, 1L, 0L, 0L,
6L, 0L, 0L, 0L, 0L, 1L, 0L, 1L, 1L
)
or in long format
df %>%
pivot_longer(-ID,names_to = "Months",values_to = "Sales")
Where ID is a customer, and 1 in month 1 means that the client bought in that month, 0 if not, 1 in month2 mean that the customer bought in that month.. and so on.
I need to create a logit where the dependent variable (y) is 1 if the client bought in the month t (0 if not), and the independent variable (x) is 1 if the client bought in the month t-1, and 0 if not.
Like this: glm(y~x,data=df),family="binomial")
It doesnt depend on the ID, only on past behavior.
After that, also I have to try this but with month t-2 and t-3.
Does anyone know how to solve it? Thanks!