#### Overview of this book

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.
Preface
Free Chapter
Introduction to Time Series Analysis and R
Working with Date and Time Objects
The Time Series Object
Working with zoo and xts Objects
Decomposition of Time Series Data
Seasonality Analysis
Correlation Analysis
Forecasting Strategies
Forecasting with Linear Regression
Forecasting with Exponential Smoothing Models
Forecasting with ARIMA Models
Forecasting with Machine Learning Models
Other Books You May Enjoy

# The autocorrelation function

The autocorrelation function (ACF) is the main method in time series analysis for quantifying the level of correlation between a series and its lags. This method is fairly similar (both mathematically and logically) to the Pearson correlation coefficient, which we saw earlier, and can be formalized with the following expression:

Here, represents the ACF correlation coefficient of the series with its k lag; and n, , and denote the number of observations of the series, the t observation of the series, and the mean, respectively. The acf function from the stats package is R's built-in ACF, which, by default, visualizes the results using a bar plot. Let's use this function to plot the correlation of the USgas series and its first 60 lags (by setting the lag.max argument to 60):

`acf(USgas, lag.max = 60)`

We will get the following plot:

Each...