Workspace
Gino Sartor/

Course Notes: ARIMA Models in R

0
Beta
Spinner

Course Notes

Use this workspace to take notes, store code snippets, and build your own interactive cheatsheet!

Note that the data from the course is not yet added to this workspace. You will need to navigate to the course overview page, download any data you wish to use, and add it to the file browser.

# Import any packages you want to use here

Stationarity

  • nel trend = la media è costante
# Plot detrended y (trend stationary)
# se c'è un trend, la differenza tra un valore e il precedente dovrebbe essere detrended e quindi stazionaria
par(mfrow = c(2,1))
plot(y) 
plot(diff(y)) # se trend lineare
plot(diff(log(y))) # se il trend è esponenziale

Any stationary ts can be represented as a linear combination of white noise

X(t) = W(t) + aW(t) + bW(t-1)+...

Questo modello si chiama ARMA Il codice successivo lo simula nelle sue 3 componenti: noise, moving average e autoregressive

# Generate and plot white noise
WN <- arima.sim(model = list(order = c(0, 0, 0)), n = 200)
plot(WN)

# Generate and plot an MA(1) with parameter .9 by filtering the noise
MA <- arima.sim(model = list(order = c(0, 0, 1), ma = .9), n = 200)  
plot(MA)

# Generate and plot an AR(1) with parameters 1.5 and -.75
AR <- arima.sim(model = list(order = c(2, 0, 0), ar = c(1.5, -.75)), n = 200) 
plot(AR)

Add your notes here

library(astsa)

# Plot the sample P/ACF pair
acf2(x)

# Fit an AR(1) to the data and examine the t-table
sarima(x, p = 1, d = 0, q = 0)

# Fit an ARMA(2,1) to the data and examine the t-table
sarima(x, p = 2, d = 0, q = 1 )
  • AI Chat
  • Code