# auto.arima doing differencing when stationary (otext example)

This question is based on prof Rob's textbook: https://www.otexts.org/fpp/9/1

regarding dynamic question. In particular, the example on the insurance using lagged predictors for the regression model with arma errors

library(fpp)

data("insurance")

plot(insurance, main=  "Insurance advertising and quotations", xlab="Year")

Quotes <- insurance[,"Quotes"]

# Lagged predictors. Test 0, 1, 2 or 3 lags.
c(NA,insurance[1:39,2]),
c(NA,NA,insurance[1:38,2]),
c(NA,NA,NA,insurance[1:37,2]))

# Choose optimal lag length for advertising based on AIC
# Restrict data so models use same fitting period

# Best model fitted to all data (based on AICc)
# Refit using all data


Notice for all the fitting, d=0 is specified. I did a KPSS test on all the variables ( the y as well as the xreg ) and found that they are in fact stationary.

So if we were to remove the d = 0 for all the fitting

fit1 <- auto.arima(insurance[4:40,1], xreg=Advert[4:40,1])

# Best model fitted to all data (based on AICc)
# Refit using all data


Some of the returned models will be returned with ARIMA errors of (0,1,0)

My question is: Why is auto.arima returning a model that does differencing when all the variables are already stationary. My only conclusion based on comparison is that the AICc as well as BIC is lower with (0,1,0) as opposed to the model returned with d = 0. Hopefully someone can guide me on this.

ndiffs(insurance[4:40,1], test="kpss") [1] 0

As you can see, both the data set that are input into auto.arima are non stationary. So why auto.arima choose to do a d=1?

Question 2: Based on the same link in the textbook:

data(austa)
ndiffs(austa, test="kpss")


we can see that austa is non stationary and requires differencing. However, in Prof Rob's example of linear trends:

auto.arima(austa, xreg = 1:length(austa))


output:

Series: austa Regression with ARIMA(2,0,0) errors

Coefficients: ar1 ar2 intercept 1:length(austa) 1.0371 -0.3379 0.4173 0.1715 s.e. 0.1675 0.1797 0.1866 0.0102

sigma^2 estimated as 0.02854: log likelihood=12.7 AIC=-15.4
AICc=-13 BIC=-8.23

Now why is auto.arima not applying differencing? I am very confused