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 eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning
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 : 9781788624046
Category :
Languages :
Concepts :

What do you get with eBook?

Product feature icon Instant access to your Digital eBook purchase
Product feature icon Download this book in EPUB and PDF formats
Product feature icon Access this title in our online reader with advanced features
Product feature icon DRM FREE - Read whenever, wherever and however you want
Product feature icon AI Assistant (beta) to help accelerate your learning

Product Details

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

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

Most Recent
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
Most Recent

Filter reviews by




N/A Nov 06, 2024
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
November 5, 2024 Dear Packt Customer Service, Re : October 16, 2024 email Please advise me if a copy of R. Krispin's book, "Hands On Time Series Analysis" is available to purchase, as I never received a copy of this book. Thank you for your consideration. Sincerely, Pamela L. Van Horn (email: plvh2015@outlook.com)
Feefo Verified review Feefo
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
Eliab Luvanda Oct 10, 2021
Full star icon Full star icon Full star icon Full star icon Empty star icon 4
Good book. Reader friendly for a novice, brief, and well organized. It is a good introduction to time series analysis and forecasting using R.
Amazon Verified review Amazon
Big T Jun 04, 2021
Full star icon Full star icon Full star icon Empty star icon Empty star icon 3
This is a good book, but ther are a number of mistakes that the editor should have caught. For example on page 184, the code should show hour=9 which leads to a different graph. Need better quality checking
Amazon Verified review Amazon
Amazon Customer May 03, 2021
Full star icon Empty star icon Empty star icon Empty star icon Empty star icon 1
Can't fault the contents of the book, however, the graphs in the print are all black and white which makes it difficult to read them. And, the graphs were clearly meant to be in colour as the text refers to red and green markings which you cannot see. Makes me think the book is counterfeit but I missed my window to return.
Amazon Verified review Amazon
Get free access to Packt library with over 7500+ books and video courses for 7 days!
Start Free Trial

FAQs

How do I buy and download an eBook? Chevron down icon Chevron up icon

Where there is an eBook version of a title available, you can buy it from the book details for that title. Add either the standalone eBook or the eBook and print book bundle to your shopping cart. Your eBook will show in your cart as a product on its own. After completing checkout and payment in the normal way, you will receive your receipt on the screen containing a link to a personalised PDF download file. This link will remain active for 30 days. You can download backup copies of the file by logging in to your account at any time.

If you already have Adobe reader installed, then clicking on the link will download and open the PDF file directly. If you don't, then save the PDF file on your machine and download the Reader to view it.

Please Note: Packt eBooks are non-returnable and non-refundable.

Packt eBook and Licensing When you buy an eBook from Packt Publishing, completing your purchase means you accept the terms of our licence agreement. Please read the full text of the agreement. In it we have tried to balance the need for the ebook to be usable for you the reader with our needs to protect the rights of us as Publishers and of our authors. In summary, the agreement says:

  • You may make copies of your eBook for your own use onto any machine
  • You may not pass copies of the eBook on to anyone else
How can I make a purchase on your website? Chevron down icon Chevron up icon

If you want to purchase a video course, eBook or Bundle (Print+eBook) please follow below steps:

  1. Register on our website using your email address and the password.
  2. Search for the title by name or ISBN using the search option.
  3. Select the title you want to purchase.
  4. Choose the format you wish to purchase the title in; if you order the Print Book, you get a free eBook copy of the same title. 
  5. Proceed with the checkout process (payment to be made using Credit Card, Debit Cart, or PayPal)
Where can I access support around an eBook? Chevron down icon Chevron up icon
  • If you experience a problem with using or installing Adobe Reader, the contact Adobe directly.
  • To view the errata for the book, see www.packtpub.com/support and view the pages for the title you have.
  • To view your account details or to download a new copy of the book go to www.packtpub.com/account
  • To contact us directly if a problem is not resolved, use www.packtpub.com/contact-us
What eBook formats do Packt support? Chevron down icon Chevron up icon

Our eBooks are currently available in a variety of formats such as PDF and ePubs. In the future, this may well change with trends and development in technology, but please note that our PDFs are not Adobe eBook Reader format, which has greater restrictions on security.

You will need to use Adobe Reader v9 or later in order to read Packt's PDF eBooks.

What are the benefits of eBooks? Chevron down icon Chevron up icon
  • You can get the information you need immediately
  • You can easily take them with you on a laptop
  • You can download them an unlimited number of times
  • You can print them out
  • They are copy-paste enabled
  • They are searchable
  • There is no password protection
  • They are lower price than print
  • They save resources and space
What is an eBook? Chevron down icon Chevron up icon

Packt eBooks are a complete electronic version of the print edition, available in PDF and ePub formats. Every piece of content down to the page numbering is the same. Because we save the costs of printing and shipping the book to you, we are able to offer eBooks at a lower cost than print editions.

When you have purchased an eBook, simply login to your account and click on the link in Your Download Area. We recommend you saving the file to your hard drive before opening it.

For optimal viewing of our eBooks, we recommend you download and install the free Adobe Reader version 9.