Book Image

Mastering Data analysis with R

By : Gergely Daróczi
Book Image

Mastering Data analysis with R

By: Gergely Daróczi

Overview of this book

Table of Contents (19 chapters)
Mastering Data Analysis with R
Credits
www.PacktPub.com
Preface

Outlier detection


Besides forecasting, another time-series related major task is identifying suspicious or abnormal data in a series of observations that might distort the results of our analysis. One way to do so is to build an ARIMA model and analyze the distance between the predicted and actual values. The tsoutliers package provides a very convenient way to do so. Let's build a model on the number of cancelled flights in 2011:

> cts <- ts(daily$Cancelled)
> fit <- auto.arima(cts)
> auto.arima(cts)
Series: ts 
ARIMA(1,1,2)

Coefficients:
          ar1      ma1      ma2
      -0.2601  -0.1787  -0.7752
s.e.   0.0969   0.0746   0.0640

sigma^2 estimated as 539.8:  log likelihood=-1662.95
AIC=3333.9   AICc=3334.01   BIC=3349.49

So now we can use an ARIMA(1,1,2) model and the tso function to highlight (and optionally remove) the outliers from our dataset:

Tip

Please note that the following tso call can run for several minutes with a full load on a CPU core as it may be performing...