-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathTime-Series-Analysis-With-R.html
362 lines (326 loc) · 24.5 KB
/
Time-Series-Analysis-With-R.html
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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
<!DOCTYPE html>
<html>
<head>
<title>Time Series Analysis With R</title>
<meta charset="utf-8">
<meta name="Description" content="R Language Tutorials for Advanced Statistics">
<meta name="Keywords" content="R, Tutorial, Machine learning, Statistics, Data Mining, Analytics, Data science, Linear Regression, Logistic Regression, Time series, Forecasting">
<meta name="Distribution" content="Global">
<meta name="Author" content="Selva Prabhakaran">
<meta name="Robots" content="index, follow">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="shortcut icon" href="/screenshots/iconb-64.png" type="image/x-icon" />
<link href="www/bootstrap.min.css" rel="stylesheet">
<link href="www/highlight.css" rel="stylesheet">
<link href='http://fonts.googleapis.com/css?family=Inconsolata:400,700'
rel='stylesheet' type='text/css'>
<!-- Color Script -->
<style type="text/css">
a {
color: #3675C5;
color: rgb(25, 145, 248);
color: #4582ec;
color: #3F73D8;
}
li {
line-height: 1.65;
}
/* reduce spacing around math formula*/
.MathJax_Display {
margin: 0em 0em;
}
</style>
<!-- Add Google search -->
<script language="Javascript" type="text/javascript">
function my_search_google()
{
var query = document.getElementById("my-google-search").value;
window.open("http://google.com/search?q=" + query
+ "%20site:" + "http://r-statistics.co");
}
</script>
</head>
<body>
<div class="container">
<div class="masthead">
<!--
<ul class="nav nav-pills pull-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
Table of contents<b class="caret"></b>
</a>
<ul class="dropdown-menu pull-right" role="menu">
<li class="dropdown-header"></li>
<li class="dropdown-header">Tutorial</li>
<li><a href="R-Tutorial.html">R Tutorial</a></li>
<li class="dropdown-header">ggplot2</li>
<li><a href="ggplot2-Tutorial-With-R.html">ggplot2 Short Tutorial</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html">ggplot2 Tutorial 1 - Intro</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html">ggplot2 Tutorial 2 - Theme</a></li>
<li><a href="Top50-Ggplot2-Visualizations-MasterList-R-Code.html">ggplot2 Tutorial 3 - Masterlist</a></li>
<li><a href="ggplot2-cheatsheet.html">ggplot2 Quickref</a></li>
<li class="dropdown-header">Foundations</li>
<li><a href="Linear-Regression.html">Linear Regression</a></li>
<li><a href="Statistical-Tests-in-R.html">Statistical Tests</a></li>
<li><a href="Missing-Value-Treatment-With-R.html">Missing Value Treatment</a></li>
<li><a href="Outlier-Treatment-With-R.html">Outlier Analysis</a></li>
<li><a href="Variable-Selection-and-Importance-With-R.html">Feature Selection</a></li>
<li><a href="Model-Selection-in-R.html">Model Selection</a></li>
<li><a href="Logistic-Regression-With-R.html">Logistic Regression</a></li>
<li><a href="Environments.html">Advanced Linear Regression</a></li>
<li class="dropdown-header">Advanced Regression Models</li>
<li><a href="adv-regression-models.html">Advanced Regression Models</a></li>
<li class="dropdown-header">Time Series</li>
<li><a href="Time-Series-Analysis-With-R.html">Time Series Analysis</a></li>
<li><a href="Time-Series-Forecasting-With-R.html">Time Series Forecasting </a></li>
<li><a href="Time-Series-Forecasting-With-R-part2.html">More Time Series Forecasting</a></li>
<li class="dropdown-header">High Performance Computing</li>
<li><a href="Parallel-Computing-With-R.html">Parallel computing</a></li>
<li><a href="Strategies-To-Improve-And-Speedup-R-Code.html">Strategies to Speedup R code</a></li>
<li class="dropdown-header">Useful Techniques</li>
<li><a href="Association-Mining-With-R.html">Association Mining</a></li>
<li><a href="Multi-Dimensional-Scaling-With-R.html">Multi Dimensional Scaling</a></li>
<li><a href="Profiling.html">Optimization</a></li>
<li><a href="Information-Value-With-R.html">InformationValue package</a></li>
</ul>
</li>
</ul>
-->
<ul class="nav nav-pills pull-right">
<div class="input-group">
<form onsubmit="my_search_google()">
<input type="text" class="form-control" id="my-google-search" placeholder="Search..">
<form>
</div><!-- /input-group -->
</ul><!-- /.col-lg-6 -->
<h3 class="muted"><a href="/">r-statistics.co</a><small> by Selva Prabhakaran</small></h3>
<hr>
</div>
<div class="row">
<div class="col-xs-12 col-sm-3" id="nav">
<div class="well">
<li>
<ul class="list-unstyled">
<li class="dropdown-header"></li>
<li class="dropdown-header">Tutorial</li>
<li><a href="R-Tutorial.html">R Tutorial</a></li>
<li class="dropdown-header">ggplot2</li>
<li><a href="ggplot2-Tutorial-With-R.html">ggplot2 Short Tutorial</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part1-With-R-Code.html">ggplot2 Tutorial 1 - Intro</a></li>
<li><a href="Complete-Ggplot2-Tutorial-Part2-Customizing-Theme-With-R-Code.html">ggplot2 Tutorial 2 - Theme</a></li>
<li><a href="Top50-Ggplot2-Visualizations-MasterList-R-Code.html">ggplot2 Tutorial 3 - Masterlist</a></li>
<li><a href="ggplot2-cheatsheet.html">ggplot2 Quickref</a></li>
<li class="dropdown-header">Foundations</li>
<li><a href="Linear-Regression.html">Linear Regression</a></li>
<li><a href="Statistical-Tests-in-R.html">Statistical Tests</a></li>
<li><a href="Missing-Value-Treatment-With-R.html">Missing Value Treatment</a></li>
<li><a href="Outlier-Treatment-With-R.html">Outlier Analysis</a></li>
<li><a href="Variable-Selection-and-Importance-With-R.html">Feature Selection</a></li>
<li><a href="Model-Selection-in-R.html">Model Selection</a></li>
<li><a href="Logistic-Regression-With-R.html">Logistic Regression</a></li>
<li><a href="Environments.html">Advanced Linear Regression</a></li>
<li class="dropdown-header">Advanced Regression Models</li>
<li><a href="adv-regression-models.html">Advanced Regression Models</a></li>
<li class="dropdown-header">Time Series</li>
<li><a href="Time-Series-Analysis-With-R.html">Time Series Analysis</a></li>
<li><a href="Time-Series-Forecasting-With-R.html">Time Series Forecasting </a></li>
<li><a href="Time-Series-Forecasting-With-R-part2.html">More Time Series Forecasting</a></li>
<li class="dropdown-header">High Performance Computing</li>
<li><a href="Parallel-Computing-With-R.html">Parallel computing</a></li>
<li><a href="Strategies-To-Improve-And-Speedup-R-Code.html">Strategies to Speedup R code</a></li>
<li class="dropdown-header">Useful Techniques</li>
<li><a href="Association-Mining-With-R.html">Association Mining</a></li>
<li><a href="Multi-Dimensional-Scaling-With-R.html">Multi Dimensional Scaling</a></li>
<li><a href="Profiling.html">Optimization</a></li>
<li><a href="Information-Value-With-R.html">InformationValue package</a></li>
</ul>
</li>
</div>
<div class="well">
<p>Stay up-to-date. <a href="https://docs.google.com/forms/d/1xkMYkLNFU9U39Dd8S_2JC0p8B5t6_Yq6zUQjanQQJpY/viewform">Subscribe!</a></p>
<p><a href="https://docs.google.com/forms/d/13GrkCFcNa-TOIllQghsz2SIEbc-YqY9eJX02B19l5Ow/viewform">Chat!</a></p>
</div>
<h4>Contents</h4>
<ul class="list-unstyled" id="toc"></ul>
<!--
<hr>
<p><a href="/contribute.html">How to contribute</a></p>
<p><a class="btn btn-primary" href="">Edit this page</a></p>
-->
</div>
<div id="content" class="col-xs-12 col-sm-8 pull-right">
<h1>Time Series Analysis</h1>
<blockquote>
<p>Any metric that is measured over regular time intervals forms a time series. Analysis of time series is commercially importance because of industrial need and relevance especially w.r.t forecasting (demand, sales, supply etc).</p>
</blockquote>
<p>A time series can be broken down to its components so as to systematically understand, analyze, model and forecast it. This is a beginners introduction to time series analysis, answering fundamental questions such as:</p>
<ol style="list-style-type: decimal">
<li>What are the components of a time series</li>
<li>What is a stationary time series</li>
<li>How to decompose it</li>
<li>How to de-trend, de-seasonalize a time series</li>
<li>What is auto correlation etc.</li>
</ol>
<h2>What is a Time Series ?</h2>
<p>Any metric that is measured over regular time intervals makes a Time Series. Example: Weather data, Stock prices, Industry forecasts, etc are some of the common ones.</p>
<h2>How to create a Time Series in R ?</h2>
<p>Upon importing your data into R, use ts() function as follows. The inputData used here is ideally a numeric vector of the class ‘numeric’ or ‘integer’.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">ts</span> (inputData, <span class="dt">frequency =</span> <span class="dv">4</span>, <span class="dt">start =</span> <span class="kw">c</span>(<span class="dv">1959</span>, <span class="dv">2</span>)) <span class="co"># frequency 4 => Quarterly Data</span>
<span class="kw">ts</span> (<span class="dv">1</span>:<span class="dv">10</span>, <span class="dt">frequency =</span> <span class="dv">12</span>, <span class="dt">start =</span> <span class="dv">1990</span>) <span class="co"># freq 12 => Monthly data. </span>
<span class="kw">ts</span> (inputData, <span class="dt">start=</span><span class="kw">c</span>(<span class="dv">2009</span>), <span class="dt">end=</span><span class="kw">c</span>(<span class="dv">2014</span>), <span class="dt">frequency=</span><span class="dv">1</span>) <span class="co"># Yearly Data</span></code></pre></div>
<h2>Understanding your Time Series</h2>
<p>Each data point <span class="math inline">(<em>Y</em><em>t</em>)</span> at time <span class="math inline"><em>t</em></span> in a Time Series can be expressed as either a sum or a product of 3 components, namely, <em>Seasonality (St)</em>, <em>Trend (Tt)</em> and <em>Error (et)</em> (a.k.a White Noise).</p>
<h5>For Additive Time Series,</h5>
<p><br /><span class="math display"><em>Y</em><sub><em>t</em></sub> = <em>S</em><sub><em>t</em></sub> + <em>T</em><sub><em>t</em></sub> + <em>ϵ</em><sub><em>t</em></sub></span><br /></p>
<h5>For Multiplicative Time Series,</h5>
<p><br /><span class="math display"><em>Y</em><sub><em>t</em></sub> = <em>S</em><sub><em>t</em></sub> × <em>T</em><sub><em>t</em></sub> × <em>ϵ</em><sub><em>t</em></sub></span><br /></p>
<p>A multiplicative time series can be converted to additive by taking a log of the time series.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">additiveTS <-<span class="st"> </span><span class="kw">log</span> (multiplcativeTS) <span class="co"># often converts multiplicative to additive time series</span></code></pre></div>
<h2>What is a Stationary Time Series ?</h2>
<p>A time series is said to be stationary if it holds the following conditions true.</p>
<ol style="list-style-type: decimal">
<li>The mean value of time-series is constant over time, which implies, the trend component is nullified.</li>
<li>The variance does not increase over time.</li>
<li>Seasonality effect is minimal.</li>
</ol>
<p>This means it is devoid of trend or seasonal patterns, which makes it looks like a random <em>white noise</em> irrespective of the observed time interval.</p>
<h2>How to extract the trend, seasonality and error?</h2>
<p>The <code>decompose()</code> and <code>forecast::stl()</code> splits the time series into <em>seasonality</em>, <em>trend</em> and <em>error</em> components.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">tsData <-<span class="st"> </span>EuStockMarkets[, <span class="dv">1</span>] <span class="co"># ts data</span>
decomposedRes <-<span class="st"> </span><span class="kw">decompose</span>(tsData, <span class="dt">type=</span><span class="st">"mult"</span>) <span class="co"># use type = "additive" for additive components</span>
<span class="kw">plot</span> (decomposedRes) <span class="co"># see plot below</span>
stlRes <-<span class="st"> </span><span class="kw">stl</span>(tsData, <span class="dt">s.window =</span> <span class="st">"periodic"</span>)
<span class="co">#> Few rows of stlRes</span>
<span class="co">#> $time.series</span>
<span class="co">#> Time Series:</span>
<span class="co">#> Start = c(1991, 130) </span>
<span class="co">#> End = c(1998, 169) </span>
<span class="co">#> Frequency = 260 </span>
<span class="co">#> seasonal trend remainder</span>
<span class="co">#> 1991.496 43.1900952 1602.604 -17.0445950</span>
<span class="co">#> 1991.500 55.3795008 1603.064 -44.8134914</span>
<span class="co">#> 1991.504 61.2914064 1603.523 -58.3048878</span>
<span class="co">#> 1991.508 68.4470620 1603.983 -51.3900342</span>
<span class="co">#> 1991.512 68.4527176 1604.442 -54.7351806</span>
<span class="co">#> 1991.515 70.8396232 1604.902 -65.1315770</span></code></pre></div>
<p><img src='screenshots/time-series-analysis/Additive-and-Multiplicative-Decomposition-of-Timeseries.png' width='707' height='436' /></p>
<h2>How to create lags of a time-series ?</h2>
<p>When the time base is shifted by a given number of periods, a Lag of time series is created. Lags of a time series are often used as explanatory variables to model the actual time series itself. The underlying reasoning is that the state of the time series few periods back may still has an influence on the series current state.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">laggedTS <-<span class="st"> </span><span class="kw">lag</span>(tsData, <span class="dv">3</span>) <span class="co"># shifted 3 periods earlier. Use `-3` to shift by 3 periods forward.</span></code></pre></div>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(DataCombine)
myDf <-<span class="st"> </span><span class="kw">as.data.frame</span>(tsData)
myDf <-<span class="st"> </span><span class="kw">slide</span>(myDf, <span class="st">"x"</span>, <span class="dt">NewVar =</span> <span class="st">"xLag1"</span>, <span class="dt">slideBy =</span> -<span class="dv">1</span>) <span class="co"># create lag1 variable</span>
myDf <-<span class="st"> </span><span class="kw">slide</span>(myDf, <span class="st">"x"</span>, <span class="dt">NewVar =</span> <span class="st">"xLead1"</span>, <span class="dt">slideBy =</span> <span class="dv">1</span>) <span class="co"># create lead1 variable</span>
<span class="kw">head</span>(myDf)
<span class="co">#> x xLag1 xLead1</span>
<span class="co">#> 1 1628.75 NA 1613.63</span>
<span class="co">#> 2 1613.63 1628.75 1606.51</span>
<span class="co">#> 3 1606.51 1613.63 1621.04</span>
<span class="co">#> 4 1621.04 1606.51 1618.16</span>
<span class="co">#> 5 1618.16 1621.04 1610.61</span>
<span class="co">#> 6 1610.61 1618.16 1630.75</span></code></pre></div>
<h2>What is Autocorrelation and Partial-Autocorrelation?</h2>
<p><strong>Autocorrelation</strong> is the correlation of a Time Series with lags of itself. This is a significant metric because,</p>
<ol style="list-style-type: decimal">
<li><p>It shows if the previous states (lagged observations) of the time series has an influence on the current state. In the autocorrelation chart, if the autocorrelation crosses the dashed blue line, it means that specific lag is significantly correlated with current series. For example, in autocorrelation chart of <code>AirPassengers</code> - the top-left chart (below), there is significant autocorrelation for all the lags shown on x-axis.</p></li>
<li><p>It is used commonly to determine if the time series is stationary or not. A stationary time series will have the autocorrelation fall to zero fairly quickly but for a non-stationary series it drops gradually.</p></li>
</ol>
<p><strong>Partial Autocorrelation</strong> is the correlation of the time series with a lag of itself, with the linear dependence of all the lags between them removed.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># both acf() and pacf() generates plots by default</span>
acfRes <-<span class="st"> </span><span class="kw">acf</span>(AirPassengers) <span class="co"># autocorrelation</span>
pacfRes <-<span class="st"> </span><span class="kw">pacf</span>(AirPassengers) <span class="co"># partial autocorrelation</span>
ccfRes <-<span class="st"> </span><span class="kw">ccf</span>(mdeaths, fdeaths, <span class="dt">ylab =</span> <span class="st">"cross-correlation"</span>) <span class="co"># computes cross correlation between 2 timeseries.</span>
<span class="kw">head</span>(ccfRes[[<span class="dv">1</span>]])
<span class="co">#> [1] 0.01505498 0.36562603 0.61542712 0.70820629 0.62189580 0.34000545</span></code></pre></div>
<p><img src='screenshots/time-series-analysis/acf-pacf-ccf-plot.png' width='575' height='411' /></p>
<h2>How to de-trend a time series ?</h2>
<p>Use linear regression to model the Time Series data with linear indices (Ex: 1, 2, .. n). The resulting model’s residuals is a representation of the time series devoid of the trend. In case, if some trend is left over to be seen in the residuals (like what it seems to be with ‘JohnsonJohnson’ data below), then you might wish to add few predictors to the <code>lm()</code> call (like a <code>forecast::seasonaldummy</code>, <code>forecast::fourier</code> or may be a lag of the series itself), until the trend is filtered.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r">trModel <-<span class="st"> </span><span class="kw">lm</span>(JohnsonJohnson ~<span class="st"> </span><span class="kw">c</span>(<span class="dv">1</span>:<span class="kw">length</span>(JohnsonJohnson)))
<span class="kw">plot</span>(<span class="kw">resid</span>(trModel), <span class="dt">type=</span><span class="st">"l"</span>) <span class="co"># resid(trModel) contains the de-trended series.</span></code></pre></div>
<p><img src='screenshots/time-series-analysis/JohnsonJohnson-Detrended.png' width='578' height='206' /></p>
<h2>How to de-seasonalize a time series in R?</h2>
<p>De-seasonalizing throws insight about the seasonal pattern in the time series and helps to model the data without the seasonal effects. So how to de-seasonalize? Step 1: De-compose the Time series using <code>forecast::stl()</code> Step 2: use <code>seasadj()</code> from ‘forecast’ package</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(forecast)
ts.stl <-<span class="st"> </span><span class="kw">stl</span>(TS,<span class="st">"periodic"</span>) <span class="co"># decompose the TS</span>
ts.sa <-<span class="st"> </span><span class="kw">seasadj</span>(ts.stl) <span class="co"># de-seasonalize</span>
<span class="kw">plot</span>(AirPassengers, <span class="dt">type=</span><span class="st">"l"</span>) <span class="co"># original series</span>
<span class="kw">plot</span>(ts.sa, <span class="dt">type=</span><span class="st">"l"</span>) <span class="co"># seasonal adjusted</span>
<span class="kw">seasonplot</span>(ts.sa, <span class="dv">12</span>, <span class="dt">col=</span><span class="kw">rainbow</span>(<span class="dv">12</span>), <span class="dt">year.labels=</span><span class="ot">TRUE</span>, <span class="dt">main=</span><span class="st">"Seasonal plot: Airpassengers"</span>) <span class="co"># seasonal frequency set as 12 for monthly data.</span></code></pre></div>
<p><img src='screenshots/time-series-analysis/seasonal-plots.png' width='578' height='371' /></p>
<h2>How to test if a time series is stationary?</h2>
<p>Use <em>Augmented Dickey-Fuller Test</em> (adf test). A p-Value of less than 0.05 in adf.test() indicates that it is stationary.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="kw">library</span>(tseries)
<span class="kw">adf.test</span>(tsData) <span class="co"># p-value < 0.05 indicates the TS is stationary</span>
<span class="kw">kpss.test</span>(tsData)</code></pre></div>
<h2>How to make a time series stationary?</h2>
<p><em>Differencing</em> a time series means, to subtract each data point in the series from its successor. It is commonly used to make a time series <em>stationary</em>. For most time series patterns, 1 or 2 differencing is necessary to make it a stationary series.</p>
<p>But if the time series appears to be seasonal, a better approach is to difference with respective season’s data points to remove seasonal effect. After that, if needed, difference it again with successive data points. But, How to know how many differencing is needed? the <code>nsdiffs</code> and <code>ndiffs</code> from <code>forecast</code> package can help find out how many <em>seasonal differencing</em> and <em>regular differencing</em> respectively is needed to make the series stationary.</p>
<div class="sourceCode"><pre class="sourceCode r"><code class="sourceCode r"><span class="co"># Seasonal Differencing</span>
<span class="kw">nsdiffs</span>(AirPassengers) <span class="co"># number for seasonal differencing needed</span>
<span class="co">#> 1</span>
AirPassengers_seasdiff <-<span class="st"> </span><span class="kw">diff</span>(AirPassengers, <span class="dt">lag=</span><span class="kw">frequency</span>(AirPassengers), <span class="dt">differences=</span><span class="dv">1</span>) <span class="co"># seasonal differencing</span>
<span class="kw">plot</span>(ap_seasdiff, <span class="dt">type=</span><span class="st">"l"</span>, <span class="dt">main=</span><span class="st">"Seasonally Differenced"</span>) <span class="co"># still not stationary!</span>
<span class="co"># Make it stationary</span>
<span class="kw">ndiffs</span>(AirPassengers_seasdiff) <span class="co"># number of differences need to make it stationary</span>
<span class="co">#> 1 </span>
stationaryTS <-<span class="st"> </span><span class="kw">diff</span>(AirPassengers_seasdiff, <span class="dt">differences=</span> <span class="dv">1</span>)
<span class="kw">plot</span>(stationaryTS, <span class="dt">type=</span><span class="st">"l"</span>, <span class="dt">main=</span><span class="st">"Differenced and Stationary"</span>) <span class="co"># appears to be stationary</span></code></pre></div>
<p><img src='screenshots/time-series-analysis/seasonal-differenced-stationary.png' width='527' height='188' /></p>
</div>
</div>
<div class="footer">
<hr>
<p>© 2016-17 Selva Prabhakaran. Powered by <a href="http://jekyllrb.com/">jekyll</a>,
<a href="http://yihui.name/knitr/">knitr</a>, and
<a href="http://johnmacfarlane.net/pandoc/">pandoc</a>.
This work is licensed under the <a href="http://creativecommons.org/licenses/by-nc/3.0/">Creative Commons License.</a>
</p>
</div>
</div> <!-- /container -->
<script src="//code.jquery.com/jquery.js"></script>
<script src="www/bootstrap.min.js"></script>
<script src="www/toc.js"></script>
<!-- MathJax Script -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
});
</script>
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
<!-- Google Analytics Code -->
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-69351797-1', 'auto');
ga('send', 'pageview');
</script>
<style type="text/css">
/* reduce spacing around math formula*/
.MathJax_Display {
margin: 0em 0em;
}
body {
font-family: 'Helvetica Neue', Roboto, Arial, sans-serif;
font-size: 16px;
line-height: 27px;
font-weight: 400;
}
blockquote p {
line-height: 1.75;
color: #717171;
}
.well li{
line-height: 28px;
}
li.dropdown-header {
display: block;
padding: 0px;
font-size: 14px;
}
</style>
</body>
</html>