Carlos N
Carlos N

Reputation: 11

Understanding the time() and cycle() functions in R

I have time series of the monthly international airplane passengers for many years, what does the time function applied to my data set tell me? What does the cycle function do to my data set? What are these functions useful for?

Upvotes: 1

Views: 4418

Answers (2)

Szilard
Szilard

Reputation: 1

An old question, but perhaps someone is googling this, so an illuminating example could still help some. When trying to make sense Cowpertwait's R book... Try this to see a visual example of what is going on:

AP
cycle(AP)
layout(matrix(c(1,2,3, 4), 2, 2, byrow = TRUE),widths=c(1,1), heights=c(1,1))
plot(AP)
plot(aggregate(AP))
boxplot(AP)
boxplot(AP ~ cycle(AP))

Upvotes: 0

H Dave
H Dave

Reputation: 306

The syntax of the time statement would be as follows:-

library(tseries)
library(forecast)
data(AirPassengers)
AP <- AirPassengers
time(AP, offset(0))

The offset of 0 indicates that the sampling of this dataset took place at the start of the time series and the time function would create a vector of times, starting the first unit or the first month in this case.

The cycle function on the other hand, will just show the position of the datapoint or the observation in the entire cycle. The syntax would be

cycle(AP)

If you run this in R, you would see that the position assigned to Jan is 1, Feb is 2, March is 3 and so on for all the 12 months.

Use of these functions would be to get an overview of the data before starting to model it.

Here is an additional link for you to browse.

Upvotes: 1

Related Questions