[R] Regression of a time series on its Quarters
Achim Zeileis
Achim.Zeileis at uibk.ac.at
Thu Mar 18 18:11:26 CET 2010
On Thu, 18 Mar 2010, Gabor Grothendieck wrote:
> Try this:
>
> lm(a.ts ~ factor(cycle(a.ts)) - 1)
An equivalent but somewhat more convenient interface is available in
"dynlm" where you can say dynlm(a.ts ~ season(a.ts)) or
dynlm(a.ts ~ season(a.ts) - 1):
R> dynlm(a.ts ~ season(a.ts))
Time series regression with "ts" data:
Start = 1947(2), End = 2000(4)
Call:
dynlm(formula = a.ts ~ season(a.ts))
Coefficients:
(Intercept) season(a.ts)Q2 season(a.ts)Q3 season(a.ts)Q4
0.03069 0.01310 -0.19455 0.09481
Best,
Z
>
> On Thu, Mar 18, 2010 at 12:30 PM, Len Vir <lenvir at gmail.com> wrote:
>> # Dear List,
>>
>> # I want to characterize a time series according to its Quarter components.
>>
>> # My data ("a.ts":
>> http://docs.google.com/View?id=dfvvwzr2_478cr9k4cdb) look like:
>>
>> # Qtr1 Qtr2 Qtr3 Qtr4
>> # 1948 -0.0714961837 0.0101747827 0.0654816569 -0.0227830729
>> # 1949 -0.1175517556 0.1151378692 0.1015777858 -0.1971535900
>> # 1950 0.0716002123 0.2551020416 0.0977574743 -0.0739337411
>> # ...
>>
>>
>> # The time series is 216 long
>>
>> # The easiest way I could figure out, is to create
>> # Quarter dummies:
>>
>> Q1 <- rep(c(1,0,0,0),54)
>> Q2 <- rep(c(0,1,0,0),54)
>> Q3 <- rep(c(0,0,1,0),54)
>> Q4 <- rep(c(0,0,0,1),54)
>>
>> qtr <- cbind(Q1,Q2,Q3,Q4)
>>
>> # and then regress my data on the dummies.
>>
>> summary(lm(a.ts ~ qtr - 1))
>>
>> # The regression on 'Quarters' works fine.
>> # It does exactly what I want it to do.
>>
>> # But! Surely there must be a more elegant way
>> # to accomplish the same thing ?!
>>
>> # I have looked at the following packages (amongst others):
>> # tseries, timeSeries, TSA, AER, fSeries, vars, FinTS, xts, fArma,
>> # fRegression, tsfa, uroot, urca, ...
>>
>> # without finding anything more convenient (simpler, nicer!).
>>
>> # Any suggestion?
>>
>> # Thank you.
>>
>> # Len Vir
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
More information about the R-help
mailing list