I observed that the results for both methods are different. Why is this? I know what is going on on lm
, but can't figure out what happens under the hood at tslm
.
> library(forecast)
> set.seed(2)
> tts <- ts(100*runif(1200)+seq(1:1200)*0.1, frequency=12, start=c(2000,1))
> lm(tts~time(tts))
Call:
lm(formula = tts ~ time(tts))
Coefficients:
(Intercept) time(tts)
-2400.365 1.225
> tslm(tts~trend)
Call:
tslm(formula = tts ~ trend)
Coefficients:
(Intercept) trend
48.9350 0.1021
Run the following three commands:
predict(lm(tts~time(tts)))
predict(tslm(tts~time(tts)))
all.equal(predict(lm(tts~time(tts))), predict(tslm(tts~trend)))
You will convince yourself that they are identical. if the outputs are identical, then the X variable of the lm regression, i.e.
time(tts)
must be a linear transformation of
trend
The easiest guess:
tmp <- time(tts)*12
lm(tts~tmp)
Has the same coefficient as the tslm coefficient. So trend is just
12*time(tts)
I.e. trend is the (integer) count of the time passed since year 0, in months. time(tts) is the count of the time passed since year 0, in years.