DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations

Trending

  • Building A Log Analytics Solution 10 Times More Cost-Effective Than Elasticsearch
  • Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices
  • Boosting Application Performance With MicroStream and Redis Integration
  • What Is mTLS? How To Implement It With Istio
  1. DZone
  2. Coding
  3. Languages
  4. R: Seasonal Periods

R: Seasonal Periods

Rob J Hyndman user avatar by
Rob J Hyndman
·
Jan. 22, 15 · Interview
Like (0)
Save
Tweet
Share
18.76K Views

Join the DZone community and get the full member experience.

Join For Free

I get ques­tions about this almost every week. Here is an exam­ple from a recent com­ment on this blog:

I have two large time series data. One is sep­a­rated by sec­onds inter­vals and the other by min­utes. The length of each time series is 180 days. I’m using R (3.1.1) for fore­cast­ing the data. I’d like to know the value of the “fre­quency” argu­ment in the ts() func­tion in R, for each data set. Since most of the exam­ples and cases I’ve seen so far are for months or days at the most, it is quite con­fus­ing for me when deal­ing with equally sep­a­rated sec­onds or min­utes. Accord­ing to my under­stand­ing, the “fre­quency” argu­ment is the num­ber of obser­va­tions per sea­son. So what is the “sea­son” in the case of seconds/​minutes? My guess is that since there are 86,400 sec­onds and 1440 min­utes a day, these should be the val­ues for the “freq” argu­ment. Is that correct?


The same ques­tion was asked on cross​val​i​dated​.com.

Yes, the “fre­quency” is the num­ber of obser­va­tions per sea­son. This is the oppo­site of the def­i­n­i­tion of fre­quency in physics, or in Fourier analy­sis, where “period” is the length of the cycle, and “fre­quency” is the inverse of period. When using the ts() func­tion in R, the fol­low­ing choices should be used.

Data frequency
Annual 1
Quar­terly 4
Monthly 12
Weekly 52

Actu­ally, there are not 52 weeks in a year, but 365.25÷7 = 52.18 on aver­age. But most func­tions which use ts objects require inte­ger frequency.

Once the fre­quency of obser­va­tions is smaller than a week, then there is usu­ally more than one way of han­dling the fre­quency. For exam­ple, hourly data might have a daily sea­son­al­ity (frequency=24), a weekly sea­son­al­ity (frequency=24x7=168) and an annual sea­son­al­ity (frequency=24x365.25=8766). If you want to use a ts object, then you need to decide which of these is the most important.

An alter­na­tive is to use a msts object (defined in the forecast pack­age) which han­dles mul­ti­ple sea­son­al­ity time series. Then you can spec­ify all the fre­quen­cies that might be rel­e­vant. It is also flex­i­ble enough to han­dle non-​​integer frequencies.

Data fre­quen­cies

minute hour day week year
Daily


7 365.25
Hourly

24 168 8766
Half-​​​​hourly

48 336 17532
Min­utes
60 1440 10080 525960
Sec­onds 60 3600 86400 604800 31557600

You won’t nec­es­sar­ily want to include all of these fre­quen­cies — just the ones that are likely to be present in the data. For exam­ple, any nat­ural phe­nom­ena (e.g., sun­shine hours) is unlikely to have a weekly period, and if your data are mea­sured in one-​​minute inter­vals over a 3 month period, there is no point includ­ing an annual frequency.

For exam­ple, the taylor data set from the forecast pack­age con­tains half-​​hourly elec­tric­ity demand data from Eng­land and Wales over about 3 months in 2000. It was defined as

taylor <- msts(x, seasonal.periods=c(48,336)

One con­ve­nient model for mul­ti­ple sea­sonal time series is a TBATS model:

taylor.fit <- tbats(taylor)
plot(forecast(taylor.fit))

(Warn­ing: this takes a few minutes.)

If an msts object is used with a func­tion designed for ts objects, the largest sea­sonal period is used as the “fre­quency” attribute.


Related Posts:

  • Fore­cast­ing with long sea­sonal periods
  • Cyclic and sea­sonal time series
  • Detect­ing seasonality
  • fore­cast pack­age v4.0
  • ABS sea­sonal adjust­ment update
R (programming language)

Published at DZone with permission of Rob J Hyndman, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Trending

  • Building A Log Analytics Solution 10 Times More Cost-Effective Than Elasticsearch
  • Cypress Tutorial: A Comprehensive Guide With Examples and Best Practices
  • Boosting Application Performance With MicroStream and Redis Integration
  • What Is mTLS? How To Implement It With Istio

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com

Let's be friends: