rnorberg
rnorberg

Reputation: 482

How to deal with a time series with multiple points at each time (in R)?

I have a time series with a few different observations at each time step (measurements of the same phenomenon, but from different locations) and it looks like it might have a weak cyclical pattern, but I'm not sure. How would I implement the acf function in R to get a better idea of what's going on? Can I call it on the whole time series as is? Do I need to separate the time series by location so that there is just one observation at each date? Do I need to fit a model first and look at the residuals?

Upvotes: 3

Views: 3690

Answers (2)

rnorberg
rnorberg

Reputation: 482

I found a neat trick for solving this issue. I divided the data by location, and then concatenated them as one long time series. The problem with this though is that I don't want to take into account the lag from the end of one series to the beginning of the next, so I inserted a bunch of NAs in between the series and used the argument na.action=na.pass and set lag.max to the number of NAs I inserted. In this case my data spanned a year with one observation every two weeks (26 time increments long), so I inserted 26 NAs between each series.

new.time.series<- c(Loc1Series, rep(NA,26), Loc2Series, rep(NA,26), Loc3Series,     rep(NA,26))
acf(new.time.series, na.action=na.pass, lag.max=30)

This allowed me to utilize all of my data to find a pattern, whereas if I had tried this analysis one location at a time I would have found little of significance due to sparse data.

Upvotes: 2

Dirk is no longer here
Dirk is no longer here

Reputation: 368251

It depends on how you want to store them. I generally live and die by xts and zoo and they (strongly) prefer distinct and (strictly) monotonically increasing index values -- aka timestamps for xts.

So in one case where I "relatively few" collisions relative to the data size, and with the smallest increment "still small" to the median increment, I fudged by making the time stamps unique. In fact, I did that so often and mailed so frequently with the authors that xts ended up with make.time.unique() ...

Upvotes: 1

Related Questions