[R] how to decompose a daily time series

Berend Hasselman bhh at xs4all.nl
Wed Jun 18 11:08:34 CEST 2014


On 18-06-2014, at 10:50, Charles Thuo <tcmuigai at gmail.com> wrote:

> # I have a daily  series of  count of transactions data i want to decompose
> and forecast.
> d<-c(723, 772, 967, 897, 621, 684, 722, 764, 856, 819,
> 678, 708, 698, 832, 928, 834, 649, 676, 635, 729, 778, 817, 616,
> 598, 605, 851, 822, 791, 678, 703, 716, 834, 872, 831, 641, 610,
> 699, 840, 901, 789, 620, 744, 644, 816, 805, 726, 565, 613, 733,
> 802, 744, 791, 624, 671, 729, 756, 828, 782, 545, 640, 691, 786,
> 818, 795, 622, 661, 644, 748, 805, 793, 615, 597, 584, 634, 655,
> 497, 330, 789, 668, 659, 779, 678, 524, 623, 592, 710, 703, 660,
> 586, 721, 1509, 925, 962, 690, 610, 772, 752, 609, 572, 926,
> 843, 737, 672, 617, 535, 611, 629, 781, 617, 534, 527, 552, 723,
> 777, 640, 592, 540, 584, 756, 801, 676, 618, 509, 530, 746, 739)
> 
> # I convert it into a time series as follows'
> 
> d.ts<-ts(d,start=c(2014,as.POSIXlt("2014-01-02")$yday+1),frequency=365)
> 
> decompose(d.ts)
> Error in decompose(d.ts) : time series has no or less than 2 periods
> 

If you had done d.ts in R you would have seen that the result was not what you expected.

Search in Google for "R daily timeseries”
The second hit is http://stat.ethz.ch/R-manual/R-devel/library/stats/html/ts.html
which is the manual page for ts.

So in R issue a ?ts command.

Look in Details and you should see that frequency must be set to 7 in your case.


> # How do i fix the period issue if i want to fix the period as weekly to
> coincide with  6 days operation in a week where the data was extracted.
> 

That will have to be answered by someone else.

Berend

> Charles.
> 
> 	[[alternative HTML version deleted]]
> 
> ______________________________________________
> 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