简体   繁体   中英

R - Analysis of time series with semi-annual data?

I have a time series with semi-annual (half-yearly) data points.

It seems that the ts() function can't handle that as "frequency = 2" returns a very strange time series object that extends far beyond the actual time period.

Is there any way to do time series analysis of this kind of time series object in R?

EDIT: Here's an example:

dat <- seq(1, 17, by = 1)
> semi <- ts(dat, start = c(2008,12), frequency = 2)
> semi
Time Series:
Start = c(2013, 2) 
End = c(2021, 2) 
Frequency = 2 
[1]  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17

I was expecting:

> semi
      s1     s2
2008          1
2009   2      3
2010   4      5
2011   6      7
2012   8      9
2013  10     11
2014  12     13 
2015  14     15
2016  16     17

First let me explain why the first ts element starts at 2013 in stead of 2008. The function start and end work with the periods/frequencies. You selected the 12th period after 2008 which is the second period in 2013 if your frequency is 2.

This should work for the period:

semi <- ts(dat, start = c(2008,2), frequency = 2)

Still semi gives the correct timeseries, however, it does not know the names with a frequency of 2. If you plot the timeseries the correct half yearly graph will be shown.

plot.ts(semi) 

In this problem someone explained about the standard frequencies, which ts() knows.

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