[R] Time unit in ts() and arima() functions

Gabor Grothendieck ggrothendieck at gmail.com
Sat Feb 12 15:29:22 CET 2011


On Sat, Feb 12, 2011 at 7:48 AM, Jose-Marcio Martins da Cruz
<Jose-Marcio.Martins at mines-paristech.fr> wrote:
>
> This question is surely trivial, sorry. I'm afraid I'm misunterpreting the
> information I got with the documentation, and I'm a little bit confused. I'm
> just an engineer with some little skills in statistics.
>
> Well, I have a time series - 600 days long - with some weekly periodicity
> inside. So far, so good.
>
> Well, if I define the time series with, say :
>
>   a <- ts(b, frequency = 7)
>
> and I do "plot(a)", each unit of time seems to be a week, not a day, which
> is coherent with help(ts) which says "frequency: the number of observations
> per unit of time." but this isn't what I want. I'd like to retrieve seasonal
> information but, as I'd like to retrieve also day to day information, the
> time unit should remain one "day".
>
> Also, when I use the "arima(...)" function to fit a model (almost the same
> kind of algorithm which appeared here some days ago), and I specify in the
> "seas=" parameter, "frequency = 7", or "frequency = frequency(a)" (a is the
> time series), I can get arN, maN, sarN, smaN... coefficients. What unit
> shall be applied to these coefficients ? One day or one week ? Logically
> (and ideally), for me, one day for arN and maN and one week for sarX and
> smaX coefficients, but I'm not sure.
>
> I have the same kind of doubt about lag units when I apply the acf()
> function to the time series (a) or the residuals returned by the arima()
> function.
>

Functions which work with ts typically assume that a full cycle is
represented by 1 unit so if a full cycle is a week then a week must be
one unit and a day must be 1/7th of a unit; however, you can later
convert your series to a non-ts representation which supports dates.
For example,

> b <- 101:121
> a <- ts(b, frequency = 7); a
Time Series:
Start = c(1, 1)
End = c(3, 7)
Frequency = 7
 [1] 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119
[20] 120 121
>
> time(a)
Time Series:
Start = c(1, 1)
End = c(3, 7)
Frequency = 7
 [1] 1.000000 1.142857 1.285714 1.428571 1.571429 1.714286 1.857143 2.000000
 [9] 2.142857 2.285714 2.428571 2.571429 2.714286 2.857143 3.000000 3.142857
[17] 3.285714 3.428571 3.571429 3.714286 3.857143
>
> # suppose start date is today
> library(zoo)
> z <- zooreg(coredata(a), start = Sys.Date()); z
2011-02-12 2011-02-13 2011-02-14 2011-02-15 2011-02-16 2011-02-17 2011-02-18
       101        102        103        104        105        106        107
2011-02-19 2011-02-20 2011-02-21 2011-02-22 2011-02-23 2011-02-24 2011-02-25
       108        109        110        111        112        113        114
2011-02-26 2011-02-27 2011-02-28 2011-03-01 2011-03-02 2011-03-03 2011-03-04
       115        116        117        118        119        120        121


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list