Chapter 9
In Due Time
IN THIS CHAPTER
Understanding time series
Moving averages
Smoothing things out
In many fields (science, medicine, business), it’s often necessary to take measurements over successive intervals of time. When you have this kind of data, you have yourself a time series. This chapter tells you about time series and how to use R to analyze them and use them to make forecasts.
A Time Series and Its Components
Managers often base their decisions on time series — like sales figures — and the numbers in a time series typically show numerous ups and downs.
Let’s look at an example. The (totally fictional) FarDrate Timepiece Corporation markets the beautifully designed MeesKyte watch, and they gather the quarterly national sales figures. Table 9-1 shows these quarterly sales figures from 2016–2020.
TABLE 9-1 Quarterly Sales Figures for the MeesKyte watch
Year |
Quarter |
Sales X 100,000 |
---|---|---|
2016 |
1 |
57 |
2 |
84 | |
3 |
68 | |
4 |
100 | |
2017 |
1 |
63 |
2 |
81 | |
3 |
73 | |
4 |
110 | |
2018 |
1 |
70 |
2 |
87 | |
3 |
75 | |
4 |
112 | |
2019 |
1 |
78 |
2 |
95 | |
3 |
88 | |
4 |
116 | |
2020 |
1 |
82 |
2 |
99 | |
3 |
92 | |
4 |
122 |
To work with R’s time series capabilities, we first put the numbers in the proper format. We begin by creating a vector of the numbers in the ...
Get R All-in-One For Dummies now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.