Regression with time and date

Hey guys,

as a beginner I need some help with my task.

I need to explain from my marketing data how important the type of TV spot is in relation to placement and time of broadcast.

I already converted the date for example:

2020-12-25 17:31:37

to Weekdays (monday, tuesday etc.)

But now I have difficulties with making a regression with the Spots 1-5 (as a dependent variable) and time and weekdays as a independent variable. How do I "extract" time out of the example above? It always say that Variable lengths are different

Hope you get the point.

Thanks!

Probably using lubridate package which has convenience functions for extracting hours/seconds/minutes from a time vector would help you.
Do more with dates and times in R (r-project.org)

A Reprex from you would be useful in order to provide you specific help
FAQ: How to do a minimal reproducible example ( reprex ) for beginners

1 Like

you don't need dummy variables, lm would make them automatically.

#made up data
(wd <- weekdays(seq(from=Sys.Date()-99,to=Sys.Date(),by=1)))
(someval <- 20*nchar(wd) +rnorm(100,1,1))

#look at it
par(mfrow=c(1,2))
plot(factor(wd))
plot(someval)

#do regression
(lm1 <- lm(someval ~ wd))
par(mfrow=c(2,2))
plot(lm1)
1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.