R Tutorial : Trends, seasonality and cyclicity

DataCamp
DataCamp
18.6 هزار بار بازدید - 4 سال پیش - Want to learn more? Take
Want to learn more? Take the full course at https://learn.datacamp.com/courses/fo... at your own pace. More than a video, you'll learn hands-on coding & quickly apply skills to your daily work.

---

Some time-series patterns occur so frequently that we give them names. A "trend" occurs when there is a long-term increase or decrease in the data. This is deliberately a little vague as a trend is not a well-defined mathematical term. But if I talk about a trend I mean a general tendency for the time series to go up over time, or down over time.

"Seasonality" occurs when there is a regular pattern in the time series related to the calendar. For example, a yearly pattern, or a weekly pattern or a daily pattern. Whenever the behavior of a time series is influenced in a period manner by the calendar, we call it seasonal.

This should be distinguished from cyclic patterns. They occur when there are rises and falls that are not of a fixed period. For example, a business cycle might last 3 or 5 or 8 years between peaks or troughs. But a seasonal pattern is always of the same length.

It is probably easiest to see what I mean with some examples.

This is a monthly Australian electricity production. It is clearly trended, with a change in the slope of the trend around 1990. It is also seasonal. Notice how the seasonal pattern changes a little over time with a little more volatility in the trough at the end of this period than at the beginning. There is no cyclic behavior visible in this graph.

Quarterly Australian clay brick production shows both seasonality and cyclicity. The seasonality is seen by the small bumps, one each year. The cyclicity is seen by the longer ups and downs. For example, there was a recession in 1975, and another one in 1983, and then again in 1991. Between these recessions, the series rises and falls. There is also some trend seen in this graph, particularly in the first half.

The next graphs show US treasury bill contracts over 100 consecutive days. There is no seasonality here. This looks very much like a downward trend, but it is actually part of a much longer cycle. When we have only a short segment of data, and we see only part of a cycle, it can look like a trend. We probably would not want to forecast this series continuing to fall indefinitely.

My last example is a famous time series. This is the number of lynx trapped annually in the Hudson Bay region of Canada from 1821 to 1934. Lynx are medium-sized wild cats that used to be trapped for their fur. Because this is annual data, it cannot be seasonal. The population of lynx rises when there is plenty of food, and when the food supply gets low, they stop breeding causing the population to plummet. The surviving lynx then have plenty of food, start to breed again, and the cycle continues. The length of these cycles varies from between 8 and 11 years.

This is also a good example to show how variable the magnitude of cyclic patterns can be, with the largest peak being more than three times the size of the smallest peak.

We need to distinguish between seasonal and cyclic patterns as very different time series models are used in each case.

To summarize:

Aseasonal patterns have constant length, while cyclic patterns have variable lengths.

If both exist together, then the average length of the cyclic pattern is longer than the length of the seasonal pattern.

The size of the cycles tends to be more variable than the size of the seasonal fluctuations.

As a result, it is much harder to predict cyclic data than seasonal data.

OK, let's get back to looking at data with R.

#DataCamp #RTutorial #ForecastinginR
4 سال پیش در تاریخ 1398/12/24 منتشر شده است.
18,685 بـار بازدید شده
... بیشتر