Time Series Exercises in R: 40 Practice Problems
Forty practice problems on time series in R: ts objects, decomposition, stationarity, autocorrelation, ARIMA, ETS, forecasting. Hidden solutions.
Section 1. ts objects and basics (8 problems)
Exercise 1.1: Create a ts
Difficulty: Beginner. Monthly series starting Jan 2020.
Show solution
Exercise 1.2: Plot ts
Difficulty: Beginner.
Show solution
Exercise 1.3: Frequency
Difficulty: Beginner.
Show solution
Exercise 1.4: Window subset
Difficulty: Intermediate.
Show solution
Exercise 1.5: Aggregate to yearly
Difficulty: Intermediate.
Show solution
Exercise 1.6: Lag
Difficulty: Intermediate.
Show solution
Exercise 1.7: Difference
Difficulty: Intermediate.
Show solution
Exercise 1.8: Seasonal lag-12 difference
Difficulty: Advanced.
Show solution
Section 2. Decomposition (6 problems)
Exercise 2.1: Classical decomposition
Difficulty: Intermediate.
Show solution
Exercise 2.2: Multiplicative decomposition
Difficulty: Intermediate.
Show solution
Exercise 2.3: STL decomposition
Difficulty: Advanced.
Show solution
Exercise 2.4: Extract trend
Difficulty: Advanced.
Show solution
Exercise 2.5: Seasonally adjusted
Difficulty: Advanced.
Show solution
Exercise 2.6: Strength of seasonality
Difficulty: Advanced.
Show solution
Section 3. Stationarity and autocorrelation (6 problems)
Exercise 3.1: ACF plot
Difficulty: Beginner.
Show solution
Exercise 3.2: PACF plot
Difficulty: Intermediate.
Show solution
Exercise 3.3: ADF test for stationarity
Difficulty: Intermediate.
Show solution
Exercise 3.4: KPSS test
Difficulty: Intermediate.
Show solution
Exercise 3.5: Difference until stationary
Difficulty: Advanced.
Show solution
Exercise 3.6: Seasonal differences needed
Difficulty: Advanced.
Show solution
Section 4. ARIMA (8 problems)
Exercise 4.1: Auto ARIMA
Difficulty: Intermediate.
Show solution
Exercise 4.2: Specific ARIMA(p,d,q)
Difficulty: Intermediate.
Show solution
Exercise 4.3: Seasonal ARIMA
Difficulty: Advanced.
Show solution
Exercise 4.4: Forecast horizon
Difficulty: Intermediate.
Show solution
Exercise 4.5: Plot forecast
Difficulty: Intermediate.
Show solution
Exercise 4.6: Residual diagnostics
Difficulty: Advanced.
Show solution
Exercise 4.7: Ljung-Box test
Difficulty: Advanced.
Show solution
Exercise 4.8: AIC comparison
Difficulty: Advanced.
Show solution
Section 5. ETS and others (6 problems)
Exercise 5.1: Auto ETS
Difficulty: Intermediate.
Show solution
Exercise 5.2: Specific ETS
Difficulty: Advanced. Holt-Winters multiplicative.
Show solution
Exercise 5.3: Holt-Winters
Difficulty: Intermediate.
Show solution
Exercise 5.4: Naive forecast
Difficulty: Beginner.
Show solution
Exercise 5.5: Seasonal naive
Difficulty: Beginner.
Show solution
Exercise 5.6: Mean forecast
Difficulty: Beginner.
Show solution
Section 6. Train-test and accuracy (6 problems)
Exercise 6.1: Train-test split
Difficulty: Intermediate.
Show solution
Exercise 6.2: Forecast accuracy
Difficulty: Intermediate.
Show solution
Exercise 6.3: Compare ARIMA vs ETS
Difficulty: Advanced.
Show solution
Exercise 6.4: Cross-validation rolling origin
Difficulty: Advanced.
Show solution
Exercise 6.5: MAPE
Difficulty: Intermediate.
Show solution
Exercise 6.6: Out-of-sample forecast plot
Difficulty: Intermediate.
Show solution
What to do next
- ARIMA-Exercises (coming), focused ARIMA drilling.
- Linear-Regression-Exercises (shipped), regression on time-features.