简体   繁体   中英

decompose() multivariate time series in R

I have multivariate time series data that I'm trying to decompose. The data were sampled hourly, at irregular intervals, six times each day ( freq = 6 ), from 2011 to 2017 .

After transforming my data from xts() to ts() and plotting, I get this graph:

分解的附加ts数据

Where is the error with my seasonality? And how can I keep my timestamp/index from xts() , format="%Y/%m/%d %H:%M" , on the x axis after decomposing?

My data:

subset4 <- structure(list(DATE.AND.TIME.GMT = structure(c(1293873660, 1293888060, 
1293902400, 1293916860, 1293931260, 1293945600, 1293960060, 1293974460, 
1293988800, 1294003260, 1294017660, 1294032000, 1294046460, 1294060860, 
1294075200, 1294089660, 1294104060, 1294118460, 1294132860, 1294147260
), class = c("POSIXct", "POSIXt"), tzone = ""), EMP = c(62.4, 
61.5, 60.6, 59.5, 59.4, 59, 61, 64, 64.4, 64.4, 64.4, 64.4, 64.4, 
64.4, 64.4, 64.4, 64.4, 64.4, 64.4, 64.4)), .Names = c("DATE.AND.TIME.GMT", 
"EMP"), na.action = structure(c(606L, 9510L, 33942L, 33943L, 
51414L, 51415L, 68885L, 68886L, 86356L, 86357L, 104163L, 104164L, 
121633L, 121634L), .Names = c("606", "9510", "33942", "33943", 
"51414", "51415", "68885", "68886", "86356", "86357", "104163", 
"104164", "121633", "121634"), class = "omit"), row.names = 28584:28603, class = "data.frame")

Code:

subset4 = xts(subset4[,-1], as.POSIXct(subset4[,1], format="%Y/%m/%d %H:%M", tz="GMT")) 
class(subset4)
subset4 = ts(subset4, frequency = 6)
plot(decompose(subset4))

frequency seems to be a complex variable. Depending on its value, some assumptions are made. In instance 4, 7 and 12 are supposed to be quarters, days of the week and months.

frequency: the number of observations per unit of time.

The value of argument frequency is used when the series is sampled an integral number of times in each unit time interval. For example, one could use a value of 7 for frequency when the data are sampled daily, and the natural time period is a week, or 12 when the data are sampled monthly and the natural time period is a year. Values of 4 and 12 are assumed in (eg) print methods to imply a quarterly and monthly series respectively.

Then, as the unit of time for other values seems to be one year, you have to define frequency as the number of samples for one year: 6 samples a day, and 365 days a year.

And you can select the first daye in a vector with year and number of samples (600 = 100 days).

start: the time of the first observation. Either a single number or a vector of two integers, which specify a natural time unit and a (1-based) number of samples into the time unit. See the examples for the use of the second form.

subset4 <- ts(subset4, frequency = 365 * 6, start = c(2011, 600))

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM