[R] ts or xts with high-frequency data within a year
bgunter.4567 at gmail.com
Thu Mar 31 18:47:50 CEST 2016
"The trouble with having an open mind is that people keep coming along
and sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Wed, Mar 30, 2016 at 5:37 PM, Ryan Utz <utz.ryan at gmail.com> wrote:
> Bill, Josh, and Bert,
> Thanks for your responses. I still can't quite get this when I use actual
> dates. Here's an example of what is going wrong:
## TYPO! It should be X[,2].
I am not a time series expert. The remarks below are therefore subject
to confirmation or correction by those who are. Caveat emptor!
Also, you seem to be somewhat confused about how the seasonal
decomposition in decompose() works.
My understanding from what you said is that your unit of time is days
and that you have samples every 15 minutes, but that you wish to
estimate hourly effects. If this is correct, you first need to first
combine (e.g. via by() ) your 4 observations into a single summary
(e.g. average or median, maybe) so that you have an hourly time
series. Run this through ts() with frequency = 24: your period is
daily = 24 hours and you have 24 observations/period.
(Note that you could use the original data to get 96 15 minute
estimates instead of hourly estimates).
When you run this through decompose(), it will give you 24 "seasonal"
effects/period, the hourly effects. The "trend" component will try to
remove longer term effects and trends over time.
Note, however, this is probably **not** what you want. I suspect you
want both hourly effects and daily or monthly effects to reflect
annual seasonalities as well as daily. decompose() cannot do this,
apparently, so you should look for an alternative solution. Better
yet, consult with a local time series expert to help you figure out
what you might want and how to get it in R.
> When I specify an actual date/time (rather than just a number as Bill
> posited), it does not like anything short of a year. This seems like I'm
> overlooking something obvious, but I can't get this for the life of me...
> Thanks for your time,
> On Wed, Mar 30, 2016 at 1:03 PM, William Dunlap <wdunlap at tibco.com> wrote:
>> You said you specified frequency=96 when you constructed the time
>> series, but when I do that the decomposition looks reasonable:
>> > time <- seq(0,9,by=1/96) # 15-minute intervals, assuming time unit is
>> > day
>> > measurement <- sqrt(time) + 1/(1.2+sin(time*2*pi)) +
>> > rnorm(length(time),0,.3)
>> > plot(decompose(ts(measurement, frequency=96)))
>> How is your code different from the above?
>> Bill Dunlap
>> TIBCO Software
>> wdunlap tibco.com
>> On Wed, Mar 30, 2016 at 8:03 AM, Ryan Utz <utz.ryan at gmail.com> wrote:
>>> I have a time series that represents data sampled every 15-minutes. The
>>> data currently run from November through February, 8623 total readings.
>>> There are definitely daily periodic trends and non-stationary long-term
>>> trends. I would love to decompose this using basic time series analysis.
>>> However, every time I attempt decomposition, I get the
>>> Error in decompose( ) : time series has no or less than 2 periods
>>> Is it only possible to do basic time-series analysis if you have a year
>>> more worth of data? That seems absurd to me, since there is definite
>>> periodicity and the data are a time series. I have tried every manner of
>>> specifying frequency= with no luck (96 does not work). All manner of
>>> searching for help has turned up fruitless.
>>> Can I only do this after I wait another year or two?
>>> Ryan Utz, Ph.D.
>>> Assistant professor of water resources
>>> Home/Cell: (724) 272-7769
>>> [[alternative HTML version deleted]]
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> PLEASE do read the posting guide
>>> and provide commented, minimal, self-contained, reproducible code.
> Ryan Utz, Ph.D.
> Assistant professor of water resources
> Home/Cell: (724) 272-7769
More information about the R-help