I have the following preset;
A data frame on the format as follows:
df <- data.frame(prevArrivalTime = c(1676193057, 1676193112, 1676193180, 1676193277, 1676193358, 1676193469, 1676193581, 1676102575, 1676102613),
hours = c(1, 2, 3, 1, 2, 3, 1, 2, 3))
dummy <- model.matrix(~factor(hours) - 1, data = df)
df <- cbind(df[, 1], dummy)
colnames(df) = c("prevArrivalTime", "hour_1", "hour_2", "hour_3")
df <- cbind(df, actualTravelTime = c(55, 68, 97, 81, 111, 112, 126, 38, 73))
The prevArrivalTime
is the recording for when a bus arrived at the previous stop, converted to a unix timestamp format, which measures the seconds which have passed since 1970-01-01. For instance, 1676193057 was "Sunday, February 12, 2023 9:10:57 AM". Dummy variable hour_1, hour_2 & hour_3
are dummy encoded hour recordings for the corresponding hour. The actualTravelTime is the variable that I'm trying to predict, namely how long it took for the bus to travel.
My data stretches over multiple days and weeks, meaning the variable prevArrivalTime will be strictly increasing as time passed by. I want to estimate $\hat{y}$ = estimatedTravelTime, by using linear regression.
The way I envision how I do this is through the formula;
$\hat{y} = b_0 * prevArrivalTime + b_1 * dummy(x) + \epsilon- prevArrivalTime$
Where I'd subtract the prevArrivalTime, which would give me a measurement of how long it took to travel from the previous stop to the next.
Otherwise, I think I end up with something where prevArrivalTime would be constantly increasing;
- prevArrivalTime_1 = 1676193057
- prevArrivalTime_2 = 1676193112
- prevArrivalTime_500 = 1677829121
While actualTravelTime would be fluctuating;
- actualTravelTime_1 = 55
- actualTravelTime_2 = 68
- actualTravelTime_500 = 58
My original question was how to implement the formula above in R, but as the comments suggested, it wasn't possible to interpret what I wanted to achieve. I hope this restructure explains what I wish to achieve in a better way.