Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
R in Action, Second Edition.pdf
Скачиваний:
540
Добавлен:
26.03.2016
Размер:
20.33 Mб
Скачать

358

CHAPTER 15 Time series

15.3.3The ets() function and automated forecasting

The ets() function has additional capabilities. You can use it to fit exponential models that have multiplicative components, add a dampening component, and perform automated forecasts. Let’s consider each in turn.

In the previous section, you fit an additive exponential model to the log of the AirPassengers time series. Alternatively, you could fit a multiplicative model to the original data. The function call would be either ets(AirPassengers, model="MAM") or the equivalent hw(AirPassengers, seasonal="multiplicative"). The trend remains additive, but the seasonal and irregular components are assumed to be multiplicative. By using a multiplicative model in this case, the accuracy statistics and forecasted values are reported in the original metric (thousands of passengers)—a decided advantage.

The ets() function can also fit a damping component. Time-series predictions often assume that a trend will continue up forever (housing market, anyone?). A damping component forces the trend to a horizontal asymptote over a period of time. In many cases, a damped model makes more realistic predictions.

Finally, you can invoke the ets() function to automatically select a best-fitting model for the data. Let’s fit an automated exponential model to the Johnson & Johnson data described in the introduction to this chapter. The following code allows the software to select a best-fitting model.

Listing 15.6 Automatic exponential forecasting with ets()

>library(forecast)

>fit <- ets(JohnsonJohnson)

>fit

ETS(M,M,M)

Call:

ets(y = JohnsonJohnson)

Smoothing parameters: alpha = 0.2328

beta = 0.0367 gamma = 0.5261

Initial states:

 

 

 

l = 0.625

 

 

 

 

b = 1.0286

 

 

 

s=0.6916

1.2639

0.9724

1.0721

sigma:

0.0863

 

 

 

AIC

 

AICc

 

BIC

 

162.4737

164.3937

181.9203

 

> plot(forecast(fit), main="Johnson & Johnson Forecasts", ylab="Quarterly Earnings (Dollars)", xlab="Time", flty=2)

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]