Series X1 has one, X2 has 4 and X3 has no autocorrelation outside the 95% limit. After observing the picture we can see none of the spikes are larger than the critical value range. This indicates that data are white noise.
Law of large number states that the number of observations increase the number of large outliers from the mean decreases. For white noise, spikes should be in critical value range. The formula for the critical values is +/- 1.96/(sqrt(T - d)) where T is the sample size and d is the amount of differencing used.
data("ibmclose")
ggtsdisplay(ibmclose)
Based on the 1st graph we can observer that there is a downward trend which rules out stationary series. While coming to ACF plot the lags are outside the critical value range and hence the series is not white noise and not stationary. PACF, 1st lag is similar to ACF 1st lag. Here there is a spike in lag 1 which means the series is not stationary.
autoplot(usnetelec)
ggtsdisplay(usnetelec)
usnetelec %>%
diff() %>%
ggtsdisplay()
autoplot(usgdp)
ggtsdisplay(usgdp)
(lambda <- BoxCox.lambda(usgdp))
[1] 0.366352
autoplot(BoxCox(usgdp,lambda=lambda))
usgdp %>%
BoxCox(lambda=lambda) %>%
diff() %>%
ggtsdisplay()
autoplot(mcopper)
ggtsdisplay(mcopper)
(lambda <- BoxCox.lambda(mcopper))
[1] 0.1919047
autoplot(BoxCox(mcopper,lambda=lambda))
mcopper %>%
BoxCox(lambda=lambda) %>%
diff() %>%
ggtsdisplay()
autoplot(enplanements)
ggtsdisplay(enplanements)
(lambda <- BoxCox.lambda(enplanements))
[1] -0.2269461
autoplot(BoxCox(enplanements,lambda=lambda))
enplanements %>%
BoxCox(lambda=lambda) %>%
diff(lag=12) %>%
ggtsdisplay()
enplanements %>%
BoxCox(lambda=lambda) %>%
diff(lag=12) %>%
diff() %>%
ggtsdisplay()
autoplot(visitors)
ggtsdisplay(visitors)
(lambda <- BoxCox.lambda(visitors))
[1] 0.2775249
autoplot(BoxCox(visitors,lambda=lambda))
visitors %>%
BoxCox(lambda=lambda) %>%
diff(lag=12) %>%
diff() %>%
ggtsdisplay()
temp = tempfile(fileext = ".xlsx")
dataURL <- "https://otexts.com/fpp2/extrafiles/retail.xlsx"
download.file(dataURL, destfile=temp, mode='wb')
retaildata <- readxl::read_excel(temp, skip=1)
myts <- ts(retaildata[,"A3349909T"], frequency=12, start=c(1982,4))
autoplot(myts)
ggtsdisplay(myts)
ggseasonplot(myts)
(lambda <- BoxCox.lambda(myts))
[1] 0.452796
autoplot(BoxCox(myts,lambda=lambda))
myts %>%
BoxCox(lambda=lambda) %>%
diff(lag=12) %>%
diff() %>%
ggtsdisplay()
ar1 <- function(phi){
y <- ts(numeric(100))
e <- rnorm(100)
for(i in 2:100)
y[i] <- phi*y[i-1] + e[i]
return(y)
}
autoplot(ar1(0.6))
autoplot(ar1(0.1))
autoplot(ar1(0.4))
autoplot(ar1(0.6))
autoplot(ar1(0.9))
ma1 <- function(theta){
y <- ts(numeric(100))
e <- rnorm(100)
for(i in 2:100)
y[i] <- theta*e[i-1] + e[i]
return(y)
}
autoplot(ma1(0.6))
autoplot(ma1(0.1))
autoplot(ma1(0.4))
autoplot(ma1(0.8))
arma11 <- function(phi, theta, n=100){
y <- ts(numeric(100))
e <- rnorm(100)
for(i in 2:100)
y[i] <- phi*y[i-1] + theta*e[i-1] + e[i]
return(y)
}
autoplot(arma11(0.6, 0.6))
ar2 <- function(phi1, phi2, n=100){
y <- ts(numeric(100))
e <- rnorm(100)
for(i in 3:100)
y[i] <- phi1*y[i-1] + phi2*y[i-2] + e[i]
return(y)
}
autoplot(ar2(-0.8,0.3))
autoplot(wmurders)
ggAcf(diff(wmurders, ndiffs(wmurders)))
ggPacf(diff(wmurders, ndiffs(wmurders)))
Above graphs indicates data is not stationary. We need to difference 2 times to make it stationary. Lag 1 in PACF is outise the range which indicates p value should be 1.
model <- arima(wmurders, order = c(1, 2, 1))
checkresiduals(model)
Ljung-Box test
data: Residuals from ARIMA(1,2,1)
Q* = 12.419, df = 8, p-value = 0.1335
Model df: 2. Total lags used: 10
forecast(model, h=3) %>%
kable() %>%
kable_styling()
Point Forecast | Lo 80 | Hi 80 | Lo 95 | Hi 95 | |
---|---|---|---|---|---|
2005 | 2.470660 | 2.200091 | 2.741229 | 2.056861 | 2.884459 |
2006 | 2.363106 | 1.993529 | 2.732684 | 1.797886 | 2.928327 |
2007 | 2.252833 | 1.774677 | 2.730989 | 1.521557 | 2.984110 |
autoplot(forecast(model, h=3))
auto.arima(wmurders)
Series: wmurders
ARIMA(1,2,1)
Coefficients:
ar1 ma1
-0.2434 -0.8261
s.e. 0.1553 0.1143
sigma^2 estimated as 0.04632: log likelihood=6.44
AIC=-6.88 AICc=-6.39 BIC=-0.97