2

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
SiKiHe
  • 439
  • 6
  • 16
  • I tried it with `deltat = 1/2`, seems to work. `semi <- c(1:12)` `semi_ts <- ts(semi, start = 2000, deltat = 1/2)`. .... Sorry I just compared to `frequency = 2`, same result: `> semi_ts Time Series: Start = c(2000, 1) End = c(2005, 2) Frequency = 2 [1] 1 2 3 4 5 6 7 8 9 10 11 12` – wolf_wue Sep 25 '17 at 13:18
  • Did you supply the correct `start=` ? This could cause `ts` to shift the time in unexpected ways. – acylam Sep 25 '17 at 13:24
  • @wolf_wue your example also works just fine (and gives the same answer) if you set `frequency = 2`: `semi_ts <- ts(semi, start = 2000, frequency = 2)` results in `START = c(2000,1)` and `END = c(2005,2)` – Eumenedies Sep 25 '17 at 13:25
  • @Eumenedies, I receive in both cases the same result – wolf_wue Sep 25 '17 at 13:29
  • Please, give us a [reproducible example](https://stackoverflow.com/help/mcve) of your problem. Real data is not required. – Andrey Kolyadin Sep 25 '17 at 14:00
  • I have now added a reproducible example – SiKiHe Sep 26 '17 at 08:47

1 Answers1

2

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.

Eddyvonb
  • 93
  • 8
  • Thank you! It makes sense that the start should be 2 (for second half-year) instead of 12 for December. – SiKiHe Sep 26 '17 at 12:31