[R] help with zoo

ravi rv15i at yahoo.se
Mon Mar 1 14:03:55 CET 2010


Hi,
I am interested in decomposing a time series and getting the trend, seasonal and irregular variations, as one can get with the "stl" command. My time series is fairly regular, but it has some breaks. From the zoo manual, I gather that it should be possible to convert it to a regular time series and then fill the NA entries by interpolation. I am not able to proceed beyond a certain point and would like some help. Here's my code :

dput(stoft)
structure(list(datum = structure(c(12060, 12073, 12089, 12101, 
12114, 12128, 12143, 12157, 12170, 12184, 12198, 12213, 12226, 
12284, 12297, 12310, 12324, 12338, 12352, 12368, 12381, 12394, 
12409, 12425, 12436, 12451, 12464, 12478, 12489, 12507, 12535, 
12549, 12562, 12579, 12591, 12639, 12653, 12668, 12681, 12696, 
12710, 12724, 12737, 12751, 12765, 12779, 12793, 12807, 12821, 
12835, 12849, 12863, 12878, 12892, 12906, 12920, 12934, 12948, 
12962, 12976, 12998, 13011, 13025, 13038, 13046, 13063, 13074, 
13088, 13102, 13119, 13130, 13144, 13158, 13172, 13187, 13200, 
13213, 13227, 13241, 13256, 13270, 13283, 13297, 13311, 13325, 
13339, 13360, 13376, 13390, 13404, 13418, 13433, 13445, 13459, 
13472, 13486, 13502, 13515, 13530, 13544, 13558, 13572, 13584, 
13599, 13614, 13627, 13641, 13657, 13669, 13683, 13697, 13712, 
13731, 13740, 13754, 13769, 13782, 13797, 13810, 13825, 13838, 
13852, 13881, 13894, 13908, 13923, 13936, 13950, 13965, 13978, 
13992, 14006, 14020, 14034, 14048, 14062, 14090, 14104, 14118, 
14132, 14146, 14160, 14175, 14189, 14202, 14217, 14231, 14257, 
14271, 14286, 14300, 14315, 14327, 14348, 14362, 14376, 14393, 
14406, 14419, 14433, 14475, 14489, 14503, 14517, 14532, 14545, 
14559, 14573, 14586, 14599, 14622, 14636, 14651, 14664), class = "Date"), 
    stoftm = c(1.803757545, 0.793326848, 1.289156128, 0.795775388, 
    0.844746181, 1.739337633, 2.737467333, 4.174410319, 2.115538261, 
    0.818511827, 1.94396559, 0.585690685, 0.455428376, 1.537438049, 
    0.954930465, 1.469123793, 2.455535482, 1.677949246, 0.491107096, 
    1.432395698, 0.910856751, 1.542579982, 1.470592916, 1.210374365, 
    0.899370874, 0.241915718, 0.062437761, 1.091349103, 6.120236163, 
    2.419157178, 3.60145204, 2.332758708, 2.0531005, 1.685171409, 
    1.018592496, 0.429718709, 0.798049032, 0.896361397, 1.388321984, 
    7.219274317, 1.364186379, 1.364186379, 1.469123793, 0.279658208, 
    1.074296773, 1.418753834, 1.113176085, 1.309618924, 0.682093189, 
    0.90036301, 1.309618924, 1.125453762, 5.793244822, 3.069419352, 
    1.023139784, 1.125453762, 1.227767741, 0.545674552, 1.200484013, 
    1.534709676, 1.969328791, 0.53476106, 2.216802866, 1.542579982, 
    0.596831541, 1.887391978, 4.514216744, 4.092559136, 3.60145204, 
    2.387326163, 2.083484651, 0.777586236, 0.072301878, 0.736660645, 
    0.165521281, 0, 0.587649517, 0.272837276, 2.346400572, 2.54648124, 
    2.018995841, 1.851095979, 0, 1.637023655, 2.387326163, 0.682093189, 
    0.113682198, 1.957607454, 0, 1.568814336, 3.192196126, 1.591550775, 
    0, 0, 0.843277057, 1.091349103, 1.193663081, 0.661105707, 
    1.282335196, 0.341046595, 0.954930465, 0.368330322, 0.350141171, 
    3.75605983, 1.718874837, 1.432395698, 1.568814336, 0.895247311, 
    1.145916558, 0.532032688, 0.341046595, 0.541127264, 0.402075985, 
    1.220188928, 1.023139784, 0.26738053, 0.899838323, 0.604789295, 
    0.954930465, 1.298705433, 0, 0.682093189, 3.001210033, 0, 
    1.637023655, 0.659538641, 2.05677331, 1.637023655, 1.018592496, 
    1.285483318, 3.683303223, 0.954930465, 2.455535482, 1.780263224, 
    1.159558422, 0.852616487, 0.170523297, 1.432395698, 0.668451326, 
    0.518390824, 0.682093189, 0, 0.254648124, 0.255784946, 0, 
    0, 0, 0.443360573, 0.627525734, 1.336902651, 0.184165161, 
    0.725747154, 1.233451851, 3.001210033, 1.364186379, 0.600242007, 
    1.606530077, 0.440737138, 0, 0, 0.318310155, 0, 0.375151254, 
    0.682093189, 0.241915718, 0.514193327, 0.518390824, 0, 0.4260459, 
    0, 0.368330322, 0.354688458, 0, 0)), .Names = c("datum", 
"stoftm"), class = "data.frame", row.names = c(NA, -174L))

stoft$week<-format(stoft$datum,format("%Y%W"))
library(zoo)
z1<-zoo(stoft$stoftm,stoft$week)
is.regular(z1)
z2<-as.ts(z1)

I should like to have some help in going further. I can experiment even more, but it would be nice if I received some help before I resume my trials.
Should I transform the index to a better form? What is the frequency that I should choose (especially if the index has "%Y%W" form)?
What is the best way to go forward to the decomposition of the time series?
Thanking you,
Ravi




More information about the R-help mailing list