[R] ts or xts with high-frequency data within a year
Bert Gunter
bgunter.4567 at gmail.com
Thu Mar 31 18:47:50 CEST 2016
Inline.
Bert Gunter
"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:
>
> X=as.data.frame(1:6000)
> X[2]=seq.POSIXt(ISOdate(2015,11,1),by='hour',length.out=6000)
> X[3]=sample(100,size=6000,replace=T)
>
> Y=xts(X[,3],order.by=X[,2])
> decompose(Y)
>
> Z=ts(X[,2],frequency=24*365)
> plot(decompose(Z))
## TYPO! It should be X[,2].
***WARNING***
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.
Cheers,
Bert
>
> 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,
> r
>
>
> 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:
>>>
>>> Hello,
>>>
>>> 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
>>> or
>>> 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?
>>>
>>> Thanks,
>>> Ryan
>>>
>>> --
>>>
>>> Ryan Utz, Ph.D.
>>> Assistant professor of water resources
>>> *chatham**UNIVERSITY*
>>> Home/Cell: (724) 272-7769
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ______________________________________________
>>> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
>>> 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.
>>
>>
>
>
>
> --
>
> Ryan Utz, Ph.D.
> Assistant professor of water resources
> chathamUNIVERSITY
> Home/Cell: (724) 272-7769
>
More information about the R-help
mailing list