Build efficient forecasting models using traditional time series models and machine learning algorithms. Key Features 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 Master statistics and implement time-series methods using examples mentioned Book 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 foundations 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 and extract meaningful information from it using both descriptive statistics and rich data visualization tools in R such as the TSstudio, plotly, and ggplot2 packages. The later section of the book 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 cover 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 the skills needed to explore your data, identify patterns, and build a forecasting model using various traditional and machine learning methods. What you will learn Visualize time series data and derive better insights Explore auto-correlation and master 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 Explore time series models such as ARIMA, Holt-Winters, and more Evaluate high-performance forecasting solutions Who this book is for Hands-On Time Series Analysis with R is ideal for data analysts, data scientists, and all R developers who are looking to perform time series analysis to predict outcomes effectively. A basic knowledge of statistics is required; some knowledge in R is expected, but not mandatory.
Author(s): Rami Krispin
Publisher: Packt Publishing
Year: 2019
Language: English
Commentary: Code Repository - https://github.com/PacktPublishing/Hands-On-Time-Series-Analysis-with-R
Pages: 438
Tags: Time-Series Analysis: Data Processing, R (Computer Program Language), Time-series analysis
Cover......Page 1
Title Page......Page 2
Copyright and Credits......Page 3
Dedication......Page 4
About Packt......Page 5
Contributors......Page 6
Table of Contents......Page 9
Preface......Page 15
Technical requirements......Page 21
Time series data......Page 22
Historical background of time series analysis......Page 24
Time series analysis......Page 25
Learning with real-life examples......Page 26
Getting started with R......Page 28
Installing R......Page 29
Assignment operators......Page 30
Arithmetic operators......Page 31
Logical operators......Page 32
Relational operators......Page 33
The R package......Page 34
Installation and maintenance of a package......Page 35
Loading a package in the R working environment......Page 36
The key packages......Page 37
Variables......Page 38
Importing and loading data to R......Page 39
Flat files......Page 40
Web API......Page 41
R datasets......Page 42
Working and manipulating data......Page 43
Querying the data......Page 45
Help and additional resources......Page 48
Summary......Page 49
Technical requirements......Page 50
The date and time formats......Page 51
Date and time objects in R......Page 53
Creating date and time objects......Page 56
Reformatting and converting date objects......Page 57
Handling numeric date objects......Page 61
Reformatting and conversion of time objects......Page 63
Time zone setting......Page 66
Creating a date or time index......Page 67
Manipulation of date and time with the lubridate package......Page 68
Reformatting date and time objects – the lubridate way......Page 69
Utility functions for date and time objects......Page 72
Summary......Page 74
Chapter 3: The Time Series Object......Page 75
The Natural Gas Consumption dataset......Page 76
The attributes of the ts class......Page 77
Multivariate time series objects......Page 80
Creating a ts object......Page 82
Creating an mts object......Page 87
Setting the series frequency......Page 88
The window function......Page 92
Aggregating ts objects......Page 94
Creating lags and leads for ts objects......Page 95
Visualizing ts and mts objects......Page 96
The plot.ts function......Page 97
The dygraphs package......Page 99
The TSstudio package......Page 102
Summary......Page 104
Technical requirement......Page 105
The zoo class......Page 106
The zoo class attributes......Page 107
The index of the zoo object......Page 108
Working with date and time objects......Page 109
Creating a zoo object......Page 111
Working with multiple time series objects......Page 115
The xts class......Page 116
The xts functionality......Page 117
Manipulating the object index......Page 118
Subsetting an xts object based on the index properties......Page 119
Manipulating the zoo and xts objects......Page 120
Merging time series objects......Page 121
Rolling windows......Page 123
Aggregating the zoo and xts objects......Page 125
Plotting zoo and xts objects......Page 126
The plot.zoo function......Page 127
The plot.xts function......Page 128
xts, zoo, or ts – which one to use?......Page 134
Summary......Page 135
Technical requirement......Page 136
The rolling window structure......Page 137
The average method ......Page 139
The MA attributes......Page 140
The simple moving average......Page 143
Two-sided MA......Page 148
A simple MA versus a two-sided MA......Page 151
The time series components......Page 153
The cycle component......Page 154
The trend component......Page 156
The seasonal component......Page 158
The seasonal component versus the cycle component......Page 161
White noise......Page 163
The additive versus the multiplicative model......Page 167
Handling multiplicative series......Page 169
The decomposition of time series......Page 171
Classical seasonal decomposition......Page 172
Seasonal adjustment......Page 176
Summary......Page 177
Technical requirement......Page 178
Seasonality types......Page 179
Summary statistics tables......Page 182
Seasonal analysis with density plots......Page 191
Seasonal analysis with the forecast package......Page 196
Seasonal analysis with the TSstudio package......Page 198
Summary......Page 206
Technical requirement......Page 207
Correlation between two variables......Page 208
Lags analysis......Page 210
The autocorrelation function......Page 212
The partial autocorrelation function......Page 215
Lag plots......Page 216
Causality versus correlation......Page 221
The cross-correlation function......Page 223
Summary......Page 228
Technical requirement......Page 229
The forecasting workflow......Page 230
Training with single training and testing partitions......Page 232
Forecasting with backtesting......Page 235
Residual analysis......Page 239
Scoring the forecast......Page 242
Forecast benchmark......Page 245
Finalizing the forecast......Page 248
Confidence interval......Page 250
Simulation......Page 251
Horse race approach......Page 253
Summary......Page 255
Technical requirement......Page 256
The linear regression......Page 257
Coefficients estimation with the OLS method......Page 259
The OLS assumptions......Page 261
Forecasting the trend and seasonal components......Page 262
Features engineering of the series components......Page 264
Modeling the series trend and seasonal components......Page 268
The tslm function......Page 279
Modeling single events and non-seasonal events......Page 280
Forecasting a series with multiseasonality components – a case study......Page 282
The UKgrid series......Page 283
Preprocessing and feature engineering of the UKdaily series......Page 285
Training and testing the forecasting model ......Page 289
Model selection ......Page 293
Residuals analysis......Page 295
Finalizing the forecast ......Page 296
Summary......Page 298
Technical requirement......Page 299
The simple moving average......Page 300
Weighted moving average......Page 307
Simple exponential smoothing model......Page 309
Forecasting with the ses function......Page 314
Model optimization with grid search......Page 317
Holt method......Page 319
Forecasting with the holt function ......Page 321
Holt-Winters model......Page 326
Summary......Page 336
Chapter 11: Forecasting with ARIMA Models......Page 337
The stationary process......Page 338
Transforming a non-stationary series into a stationary series......Page 342
Differencing time series......Page 343
Log transformation......Page 345
The random walk process......Page 346
The AR process......Page 349
Identifying the AR process and its characteristics......Page 352
The moving average process......Page 354
Identifying the MA process and its characteristics......Page 356
The ARMA model......Page 357
Identifying an ARMA process ......Page 360
Manual tuning of the ARMA model......Page 361
Forecasting AR, MA, and ARMA models......Page 365
The ARIMA model......Page 366
Identifying the model degree of differencing......Page 367
The seasonal ARIMA model......Page 372
Tuning the seasonal parameters ......Page 373
Forecasting US monthly natural gas consumption with the SARIMA model – a case study......Page 374
The auto.arima function......Page 385
Violation of white noise assumption......Page 387
Modeling the residuals with the ARIMA model......Page 390
Summary......Page 395
Technical requirement......Page 396
Why and when should we use machine learning?......Page 397
Why h2o?......Page 398
The series structure......Page 399
The series components......Page 401
Seasonal analysis......Page 402
Correlation analysis......Page 403
Exploratory analysis – key findings......Page 404
Feature engineering ......Page 406
Training, testing, and model evaluation......Page 408
Model benchmark......Page 409
Starting a h2o cluster......Page 410
Training an ML model ......Page 412
Forecasting with the Random Forest model......Page 413
Forecasting with the GBM model......Page 420
Forecasting with the AutoML model......Page 423
Selecting the final model......Page 426
Summary......Page 428
Other Books You May Enjoy......Page 429
Index......Page 432