I have a repeating time series with a seasonal (weekly) pattern, and I'd like to return the same time series with no week-over-week trend, taking the first value as a starting point.
To be specific, the 1st value will still be 39.8, but the 8th value will also be 39.8 rather than 17.1. If the first seven values were just repeated then there would be a week-long negative trend repeated and I'd like to have no trend at all (so the 7th value of 6.2 would also be higher).
Is there an elegant way to do this, especially one that is robust to zero-valued entries in a time-series (I have a lot of them)?
We can assume the time series trend is linear and constant (i.e. not just piecewise linear).
demand <- ts(
c(39.8, 33.5, 40.6, 23.6, 11.9, 12.3, 6.2, 17.1, 10.8, 18, 1, -10.7,
-10.4, -16.5, -5.6, -11.9, -4.7, -21.7, -33.4, -33.1, -39.2, -28.2,
-34.6, -27.4, -44.4, -56.1, -55.7, -61.8, -50.9, -57.2, -50.1),
frequency = 7
)
plot(demand)