r - Decompose xts hourly time series -


i want decompose hourly time series decompose, ets, or stl or whatever function. here example code , output:

require(xts) require(forecast) time_index1 <- seq(from = as.posixct("2012-05-15 07:00"),                    = as.posixct("2012-05-17 18:00"), by="hour") head(time_index1 <- format(time_index1, format="%y-%m-%d %h:%m:%s",                            tz="utc", usetz=true) # [1] "2012-05-15 05:00:00 utc" "2012-05-15 06:00:00 utc" # [3] "2012-05-15 07:00:00 utc" "2012-05-15 08:00:00 utc" # [5] "2012-05-15 09:00:00 utc" "2012-05-15 10:00:00 utc" head(time_index <- as.posixct(time_index1)) # [1] "2012-05-15 05:00:00 cest" "2012-05-15 06:00:00 cest" # [3] "2012-05-15 07:00:00 cest" "2012-05-15 08:00:00 cest" # [5] "2012-05-15 09:00:00 cest" "2012-05-15 10:00:00 cest" 

why timezone time_index change cest?

set.seed(1) value <- rnorm(n = length(time_index1)) eventdata1 <- xts(value, order.by = time_index) tzone(eventdata1) # [1] "" head(index(eventdata1)) # [1] "2012-05-15 05:00:00 cest" "2012-05-15 06:00:00 cest" # [3] "2012-05-15 07:00:00 cest" "2012-05-15 08:00:00 cest" # [5] "2012-05-15 09:00:00 cest" "2012-05-15 10:00:00 cest" ets(eventdata1) # ets(a,n,n)  #  # call: #  ets(y = eventdata1)  #  #   smoothing parameters: #     alpha = 1e-04  #  #   initial states: #     l = 0.1077  #  #   sigma:  0.8481 #  #      aic     aicc      bic  # 229.8835 230.0940 234.0722 decompose(eventdata1) # error in decompose(eventdata1) :  #   time series has no or less 2 periods stl(eventdata1) # error in stl(eventdata1) :  #   series not periodic or has less 2 periods 

when call tzone or indextz there no timezone index show times defined timezone.

also, why ets work? can used decompose time series?

why timezone time_index change cest?

because didn't specify tz= in call as.posixct. pick timezone string if it's specified offset utc (e.g. -0800). see ?strptime.

r> head(time_index <- as.posixct(time_index1, "utc")) [1] "2012-05-15 12:00:00 utc" "2012-05-15 13:00:00 utc" [3] "2012-05-15 14:00:00 utc" "2012-05-15 15:00:00 utc" [5] "2012-05-15 16:00:00 utc" "2012-05-15 17:00:00 utc" 

when call tzone or indextz there no timezone index show times defined timezone.

all posixct objects have timezone. timezone of "" means r wasn't able determine specific timezone, using timezone specified operating system. see ?timezone.

only ets function works because xts object doesn't have defined frequency attribute. known limitation of xts objects, , have plans address them on next several months. can work around current issues explicitly specifying frequency attribute after calling xts constructor.

r> set.seed(1) r> value <- rnorm(n = length(time_index1)) r> eventdata1 <- xts(value, order.by = time_index) r> attr(eventdata1, 'frequency') <- 24  # set frequency attribute r> decompose(as.ts(eventdata1))  # decompose expects 'ts' object 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

Nuget pack csproj using nuspec -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -