Repository navigation
Expand file tree
/
Copy path01.Rmd
More file actions
207 lines (124 loc) · 6.23 KB
/
Copy path01.Rmd
File metadata and controls
207 lines (124 loc) · 6.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
---
title: "Introductory Time Series"
subtitle: ""
author: "Richard M. Smith"
date: "2018/01/04"
output:
xaringan::moon_reader:
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
---
# Class Goals
- Introduction to Time Series Analysis
- Time Series Principles
- Tools and techniques for working with Time Series in R
- Methods of delivery and communication
- Balance of theory and practical applications
- Including discussion of data science / time series forecasting within organizations
---
# Tools
- [R](https://cran.r-project.org/) + [R Studio](https://www.rstudio.com/)
- [git](https://git-scm.com/) + [github](https://github.com/)
--
# Texts
- [Introductory Time Series with R](https://goo.gl/iDSDxh)
- 2009 Edition; ISBN 978-0-387-88697-8
- [Forecasting Principles & Practice](http://otexts.org/fpp2/)
- [Time Series Analysis and Its Applications](http://evalenzu.mat.utfsm.cl/Docencia/2016/Segundo%20semestre/Series%20de%20Tiempo%20II/Apunte%201.pdf)
- Third Edition; ISBN 978-1-4419-7864-6
---
# Expectations
- Bring your computer to class
- Pay attention & participate!
- Read assigned chapters
- Provide feedback
---
# About Me
- Manager, Sales Analysis & Forecasting LG&E-KU
- Prior roles in Accounting, Finance, Regulatory functions
- BS Business Admin, BS Finance & Accounting, MBA, CPA, CFA
- Almost no exposure to modern analytics tools from these
- Started using R through JHU Data Science Specialization on Coursera
---
# Class Philisophy
.pull-left[

Image credit: [David Robinson](https://twitter.com/drob) / [Amelia McNamara](https://twitter.com/AmeliaMN)
]
.pull-right[
[10 rules for students & teachers](https://www.brainpickings.org/2012/08/10/10-rules-for-students-and-teachers-john-cage-corita-kent/)
4. Consider everything an experiment.
6. Nothing is a mistake. There’s no win and no fail, there’s only make.
7. The only rule is work. If you work it will lead to something. It’s the people who do all of the work all of the time who eventually catch on to things.
8. Don’t try to create and analyze at the same time. They’re different processes.
]
---
# Why care about time series?

---
# Forecasting, Planning and Goals
**Forecasting** is about predicting the future as accurately as possible, given all of the information available, including historical data and knowledge of any future events that might impact the forecasts.
**Goals** are what you would like to have happen. Goals should be linked to forecasts and plans, but this does not always occur. Too often, goals are set without any plan for how to achieve them, and no forecasts for whether they are realistic.
**Planning** is a response to forecasts and goals. Planning involves determining the appropriate actions that are required to make your forecasts match your goals.
---
# Basic forecasting tasks
1. Problem Definition
2. Gathering Information
3. Preliminary (exploratory) analysis
4. Choosing and fitting models
5. Using and evaluating a forecasting model
---
# Time Series Basics
- Correlation introduced by the sampling of adjacent points in time can severely restrict the applicability of the many conventional statistical methods traditionally dependent on the assumption that these adjacent observations are independent and identically distributed.
- Primary objective of time series analysis is to develop mathematical models that provide plausible descriptions for sample data
--
## Examples
- Economics: daily stock market figures and monthly unemployment statistics
- Social Science: birth rates, school enrollments
- Medical: influenza cases, blood pressure, brain-wave reactions to stimuli
- Environmental Science: global temperatures, pollution impact on mortality
- Other: speech recognition, seismic recordings
---
# Time Domain & Frequency Domain
- Time: correlation between adjacent points in time is best explained in terms of a dependence of the current value on past values
- ARIMA models
- State-space models - sums of series each with specified time series structure
- Frequency: primary characteristics relate to periodic or systematic variations found in most data
- Often caused by biological, physical, or environmental phenomona
- Wind, sea surface temperature, seasonal unemployment
---
# Notation
- Assume a time series can be defined as a collection of random variables indexed according to the order they are obtained in time. $x_1, x_2, x_3, ...$
- A collection of random variables, $\{x_t\}$, indexed by $t$ is referred to as a stochastic process.
---
# Getting Book data from github
[Github Repo](https://github.com/Smudgerville/IntroTimeSeriesWithR)
```{r}
base_url <- "https://raw.githubusercontent.com/Smudgerville/IntroTimeSeriesWithR/master/"
in_data <- read.table(paste0(base_url, "USunemp.dat"), header = T)
knitr::kable(head(in_data), format = "html")
```
---
# Exercises
1. Get the current system time and store as a variable. Is this a POSIXct or POSIXlt object?
2. Retrieve the year from this variable
3. Create a monthly vector of date objects for 2018
4. Create an hourly vector of POSIXct values for today
5. Create a 4 year, quarterly time series dataset of random normal variables beginning in January 1990
6. Load and plot the `sunspots` dataset with a horizontal red line showing the mean of the whole dataset
7. Do a seasonal plot of the Australian Wine data (requires `forecast` package)
8. Using Base R graphics, plot a logistic distribution of monthly values over a 3-year period beginning January 2018. Add a blue line showing the trailing 3-period moving average and a red line showing the 2-sided 5 period moving average.
---
# Homework
- Install R v3.4 or greater
- Install R Studio version 1.0 or greater
- Download and install git on your machine
- Sign up for a github account
- Download course R packages