Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Hands-On Time Series Analysis with R
Hands-On Time Series Analysis with R

Hands-On Time Series Analysis with R: Perform time series analysis and forecasting using R

eBook
€15.99 €23.99
Paperback
€29.99
Subscription
Free Trial
Renews at €18.99p/m

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing
Table of content icon View table of contents Preview book icon Preview Book

Hands-On Time Series Analysis with R

Working with Date and Time Objects

The main attribute of time series data is its timestamp, which could be a date object, time object, or other index format depending on the series frequency. Typically while loading raw data, it is not trivial to have the date or time object formatted and ready to use. Therefore, it is most likely that the raw data may require some reformatting before you are able to transform your data into time series format. The ability to work with time and date objects is an essential part of the data preparation process. In this chapter, we will introduce a set of tools and applications for dealing with those objects, starting with R's built-in tools and classes from the base package and moving to the advanced applications of the lubridate package.

In this chapter, we will cover the following topics:

  • The date and time formats
  • Date and time objects...

Technical requirements

The date and time formats

One of the main challenges of working with date and time objects is the variety of formats that can be used for representing date and time. For example, most of the common calendar systems use an alphabetical form to represent the three date components:

  • Y: Refers to the year, which can display either using the yy (two-digits year, for example, 18) or yyyy (four-digit year, for example, 2018) formats.
  • M: Refers to the month. Here there are four methods to display the month:
    • m: One-digit month (the first 9 months represented by a single digit, for example, 1 for January, 2 for February, and so on)
    • mm: Two-digit month (the first 9 months represented by two digits, for example, 01 for January, 02 for February, and so on)
    • mmm: Three-letter abbreviation for a month (for example, Jan for January, Feb for February, and so on)
    • mmmm: Full month name (for example...

Date and time objects in R

The base package, one of R's core packages, provides two types of date and time classes:

  1. Date: This is a simple representation of a calendar date following the ISO 8601 international standard format (or the Gregorian calendar format) using the YYYY-m-d date format. Each date object has a numeric value of the number of days since the origin point (the default setting is 1970-01-01). In the Handling numeric date objects section in this chapter, we will discuss the usage of the origin in the reformatting process of date objects in more detail. It will make sense to use this format when the frequency of the data is daily or lower (for example, monthly, quarterly, and so on) and the time of the day doesn't matter.
  2. POSIXct/POSIXlt: Also known as the DateTime classes (that is, they represent both date and time), these are two POSIX date/time classes...

Creating a date or time index

So far, our focus in this chapter was mainly on the attributes of the date and time classes. Let's now connect the dots and see some useful applications of time series data. As introduced in Chapter 1, Introduction to Time Series Analysis and R, the main characteristic of time series data is its time index (or timestamp), an equally spaced time interval. The base package provides two pairs of functions, seq.Date and seq.POSIXt, to create a time index vector with Date or POSIX objects respectively. The main difference between the two functions (besides the class of the output) is the units of the time interval. It will make sense to use the seq.Date function to generate a time sequence with daily frequency or lower (for example, weekly, monthly, and so on) and as.POSIXt in other instances (for higher frequencies than daily, such as hourly, half...

Manipulation of date and time with the lubridate package

The title of the lubridate package documentation in CRAN is Make Dealing with Dates a Little Easier. In my mind, this is a very modest title for a package that makes work with date and time objects more effective, simple, and time efficient. This section introduces alternative tools and applications with the lubridate package for reformatting, converting, and handling date and time objects.

Reformatting date and time objects – the lubridate way

To understand how simple it is to reformat date and time objects with the lubridate package, let's go back to the complex time object (Monday, December 31, 2018 11:59:59 PM) we converted earlier to a POSIXct class...

Summary

Date and time objects are one of the foundations of the time series data. Thus, the ability to import, reformat, and convert this type of object in R seamlessly is an essential part of the time series analysis process. In this chapter, we introduced the primary date and time objects in R, the Date and POSIXct/POSIXlt classes, and their main attributes. Furthermore, we introduced two main approaches in R to handle and process those objects, with the base and lubridate packages. While the work with the base functions is more technical (or hardcore coding), the work with the lubridate package is based on common English language communication with the objects and therefore is much simpler to use. I personally found that deep understanding of the base package approach makes working with the lubridate package much smoother and more straightforward, as date and time objects play...

Left arrow icon Right arrow icon
Download code icon Download Code

Key benefits

  • Perform time-series analysis and forecasting using R packages such as forecast and h2o
  • Develop models and find patterns to create visualizations using the TSstudio and plotly packages
  • Learn statistics and implement time-series methods with the help of examples

Description

Time-series analysis is the art of extracting meaningful insights from, and revealing patterns in, time-series data using statistical and data visualization approaches. These insights and patterns can then be utilized to explore past events and forecast future values in the series. This book explores the basics of time-series analysis with R and lays the foundation you need to build forecasting models. You will learn how to preprocess raw time-series data and clean and manipulate data with packages such as stats, lubridate, xts, and zoo. You will analyze data using both descriptive statistics and rich data visualization tools in R including the TSstudio, plotly, and ggplot2 packages. The book then delves into traditional forecasting models such as time-series linear regression, exponential smoothing (Holt, Holt-Winter, and more) and Auto-Regressive Integrated Moving Average (ARIMA) models with the stats and forecast packages. You'll also work on advanced time-series regression models with machine learning algorithms such as random forest and Gradient Boosting Machine using the h2o package. By the end of this book, you will have developed the skills necessary for exploring your data, identifying patterns, and building a forecasting model using various traditional and machine learning methods.

Who is this book for?

Hands-On Time Series Analysis with R is ideal for data analysts, data scientists, and R developers looking to perform time-series analysis to predict outcomes effectively. Basic knowledge of statistics is required to understand the concepts covered in this book. Also, some experience in R will be helpful.

What you will learn

  • Visualize time-series data and derive useful insights
  • Study auto-correlation and understand statistical techniques
  • Use time-series analysis tools from the stats, TSstudio, and forecast packages
  • Explore and identify seasonal and correlation patterns
  • Work with different time-series formats in R
  • Discover time-series models such as ARIMA, Holt-Winters, and more
  • Evaluate high-performance forecasting solutions

Product Details

Country selected
Publication date, Length, Edition, Language, ISBN-13
Publication date : May 31, 2019
Length: 448 pages
Edition : 1st
Language : English
ISBN-13 : 9781788629157
Category :
Languages :
Concepts :
Tools :

What do you get with a Packt Subscription?

Free for first 7 days. $19.99 p/m after that. Cancel any time!
Product feature icon Unlimited ad-free access to the largest independent learning library in tech. Access this title and thousands more!
Product feature icon 50+ new titles added per month, including many first-to-market concepts and exclusive early access to books as they are being written.
Product feature icon Innovative learning tools, including AI book assistants, code context explainers, and text-to-speech.
Product feature icon Thousands of reference materials covering every tech concept you need to stay up to date.
Subscribe now
View plans & pricing

Product Details

Publication date : May 31, 2019
Length: 448 pages
Edition : 1st
Language : English
ISBN-13 : 9781788629157
Category :
Languages :
Concepts :
Tools :

Packt Subscriptions

See our plans and pricing
Modal Close icon
€18.99 billed monthly
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Simple pricing, no contract
€189.99 billed annually
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts
€264.99 billed in 18 months
Feature tick icon Unlimited access to Packt's library of 7,000+ practical books and videos
Feature tick icon Constantly refreshed with 50+ new titles a month
Feature tick icon Exclusive Early access to books as they're written
Feature tick icon Solve problems while you work with advanced search and reference features
Feature tick icon Offline reading on the mobile app
Feature tick icon Choose a DRM-free eBook or Video every month to keep
Feature tick icon PLUS own as many other DRM-free eBooks or Videos as you like for just €5 each
Feature tick icon Exclusive print discounts

Frequently bought together


Stars icon
Total 95.97
Machine Learning with R
€44.99
R Statistics Cookbook
€20.99
Hands-On Time Series Analysis with R
€29.99
Total 95.97 Stars icon

Table of Contents

13 Chapters
Introduction to Time Series Analysis and R Chevron down icon Chevron up icon
Working with Date and Time Objects Chevron down icon Chevron up icon
The Time Series Object Chevron down icon Chevron up icon
Working with zoo and xts Objects Chevron down icon Chevron up icon
Decomposition of Time Series Data Chevron down icon Chevron up icon
Seasonality Analysis Chevron down icon Chevron up icon
Correlation Analysis Chevron down icon Chevron up icon
Forecasting Strategies Chevron down icon Chevron up icon
Forecasting with Linear Regression Chevron down icon Chevron up icon
Forecasting with Exponential Smoothing Models Chevron down icon Chevron up icon
Forecasting with ARIMA Models Chevron down icon Chevron up icon
Forecasting with Machine Learning Models Chevron down icon Chevron up icon
Other Books You May Enjoy Chevron down icon Chevron up icon

Customer reviews

Top Reviews
Rating distribution
Full star icon Full star icon Full star icon Half star icon Empty star icon 3.8
(11 Ratings)
5 star 54.5%
4 star 9.1%
3 star 18.2%
2 star 0%
1 star 18.2%
Filter icon Filter
Top Reviews

Filter reviews by




Naftali Jun 20, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I enjoyed reading the book and learned a lot. Very practical with down-to-earth examples.
Amazon Verified review Amazon
Suarez Mar 01, 2023
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I have been through the book, despite some challenges with code, it was a great experience learning it and useful for my work. Great.
Amazon Verified review Amazon
alla Jul 30, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
I've spend a great part of my bachelor's and master's specializing in modeling and predicting time series.Same with my first years of work experience.Doing general data science work over the past several years I found my prior TS experience relevant and advantageous.To a similar extant, I am confident that this book can too provide a significant advantage to any data scientist.If you read it, experiment with the methods and get an intuition for the models and algorithms, you'll be a force multiplier to your organization.The book is simple, concise, quickly relates a method to its task, and leaves you with all the tools you need to perform industry grade time series modeling and prediction.Thanks and good luck,Lior.
Amazon Verified review Amazon
Blaise F Egan Apr 02, 2021
Full star icon Full star icon Full star icon Full star icon Full star icon 5
Practical, hands-on guide to forecasting using R. Easy to use, as all the Packt books are.
Amazon Verified review Amazon
Raquel Dourado Sep 13, 2019
Full star icon Full star icon Full star icon Full star icon Full star icon 5
This book is very didactic and it has valuable explanations.Organized and elegant.A must-read!
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

What is included in a Packt subscription? Chevron down icon Chevron up icon

A subscription provides you with full access to view all Packt and licnesed content online, this includes exclusive access to Early Access titles. Depending on the tier chosen you can also earn credits and discounts to use for owning content

How can I cancel my subscription? Chevron down icon Chevron up icon

To cancel your subscription with us simply go to the account page - found in the top right of the page or at https://subscription.packtpub.com/my-account/subscription - From here you will see the ‘cancel subscription’ button in the grey box with your subscription information in.

What are credits? Chevron down icon Chevron up icon

Credits can be earned from reading 40 section of any title within the payment cycle - a month starting from the day of subscription payment. You also earn a Credit every month if you subscribe to our annual or 18 month plans. Credits can be used to buy books DRM free, the same way that you would pay for a book. Your credits can be found in the subscription homepage - subscription.packtpub.com - clicking on ‘the my’ library dropdown and selecting ‘credits’.

What happens if an Early Access Course is cancelled? Chevron down icon Chevron up icon

Projects are rarely cancelled, but sometimes it's unavoidable. If an Early Access course is cancelled or excessively delayed, you can exchange your purchase for another course. For further details, please contact us here.

Where can I send feedback about an Early Access title? Chevron down icon Chevron up icon

If you have any feedback about the product you're reading, or Early Access in general, then please fill out a contact form here and we'll make sure the feedback gets to the right team. 

Can I download the code files for Early Access titles? Chevron down icon Chevron up icon

We try to ensure that all books in Early Access have code available to use, download, and fork on GitHub. This helps us be more agile in the development of the book, and helps keep the often changing code base of new versions and new technologies as up to date as possible. Unfortunately, however, there will be rare cases when it is not possible for us to have downloadable code samples available until publication.

When we publish the book, the code files will also be available to download from the Packt website.

How accurate is the publication date? Chevron down icon Chevron up icon

The publication date is as accurate as we can be at any point in the project. Unfortunately, delays can happen. Often those delays are out of our control, such as changes to the technology code base or delays in the tech release. We do our best to give you an accurate estimate of the publication date at any given time, and as more chapters are delivered, the more accurate the delivery date will become.

How will I know when new chapters are ready? Chevron down icon Chevron up icon

We'll let you know every time there has been an update to a course that you've bought in Early Access. You'll get an email to let you know there has been a new chapter, or a change to a previous chapter. The new chapters are automatically added to your account, so you can also check back there any time you're ready and download or read them online.

I am a Packt subscriber, do I get Early Access? Chevron down icon Chevron up icon

Yes, all Early Access content is fully available through your subscription. You will need to have a paid for or active trial subscription in order to access all titles.

How is Early Access delivered? Chevron down icon Chevron up icon

Early Access is currently only available as a PDF or through our online reader. As we make changes or add new chapters, the files in your Packt account will be updated so you can download them again or view them online immediately.

How do I buy Early Access content? Chevron down icon Chevron up icon

Early Access is a way of us getting our content to you quicker, but the method of buying the Early Access course is still the same. Just find the course you want to buy, go through the check-out steps, and you’ll get a confirmation email from us with information and a link to the relevant Early Access courses.

What is Early Access? Chevron down icon Chevron up icon

Keeping up to date with the latest technology is difficult; new versions, new frameworks, new techniques. This feature gives you a head-start to our content, as it's being created. With Early Access you'll receive each chapter as it's written, and get regular updates throughout the product's development, as well as the final course as soon as it's ready.We created Early Access as a means of giving you the information you need, as soon as it's available. As we go through the process of developing a course, 99% of it can be ready but we can't publish until that last 1% falls in to place. Early Access helps to unlock the potential of our content early, to help you start your learning when you need it most. You not only get access to every chapter as it's delivered, edited, and updated, but you'll also get the finalized, DRM-free product to download in any format you want when it's published. As a member of Packt, you'll also be eligible for our exclusive offers, including a free course every day, and discounts on new and popular titles.