Housekeeping

Upcoming Dates

  • HW 9 was due on Wednesday, 4/16.

    • Grace Period ends Thursday (4/17) at midnight.
  • HW 10 is now posted and is due on Monday 4/28.

  • Additional Practice Questions will be posted next week.

  • Lecture 27 (4/22): Come to class with a stock symbol that you are interested in.

  • Lecture 28 (4/24): Course Review and Q&A.

Course Evaluations

  • Evaluations are VERY Important:

    • coursefeedback.syr.edu

    • I will end class a little early next week to give you time to complete evaluations in class.

    • Please complete evaluations for ALL courses.

Today’s plan 📋

  • Review of Time Series Concepts

    • Review and New Terminology
  • Brief Review of Time Series without Seasonality

  • Seasonality in Time Series Data

  • Forecasting Trends with Seasonality in R

    • Example from HW 10: Alaska
  • NEW PACKAGE FOR FORECASTING: forecast

  • HW 10 is now posted and is due on 4/28

    • Part of HW 10 pertains to today’s lecture.

    • Demo videos for HW 10 will be posted this weekend.

In-class Polling (Session ID: bua345s25)

💥 Lecture 26 In-class Exercises - Q1 - Review 💥

Session ID: bua345s25

The AR in ARIMA stands a type of regression when you regress a variable on itself by using previous observations to predict future ones.


This is known as ___-regression.

Cross-Sectional Data

Shows a Snapshot of One Time Period

Time Series Data

Shows Trend over Time

Time Series Terminology

  • auto-correlation: A variable is correlated with itself

  • auto-regression (AR): Using previous observations to predict into the future.

  • R function: auto.arima - ARIMA is an acronym:

    • AR: auto-regressive - p = number of lags to minimize auto-correlation

    • I: integrated - d = order of differencing to achieve stationarity

    • MA: moving average - q = number of terms in moving average

    • All 3 components are optimized to provide a reliable forecast.

      • R software optimizes ARIMA model by varying these components.

More on Stationarity

  • Stationary Time Series:

    • Consistent mean and variance throughout time series

    • Time series with trends, or with seasonality, are not stationary.

    • Separating a time series into different parts is how we analyze it

      • This is called DECOMPOSITION

      • Time Series Modeling decomposes the data into:

        • Trend

        • Seasonality (repeated pattern)

        • Residuals (what’s left over)

Decomposition and SARIMA Models

NEW TERM: SARIMA MODEL

  • Lecture 25: ARIMA models

  • Today: ARIMA models with SEASONAL component.

  • SARIMA: Seasonal Auto-Regressive Integrated Moving Average.

  • SARIMA models:

    • optimize p, d, and q for whole time series

    • Also optimize p, d, and q within season (repeating intervals)

DECOMPOSITION

  • ARIMA models are decomposed into

    • Trend | Residuals
  • SARIMA models are decomposed into

    • Trend | Seasonal patterns | Residuals

Visualization of Decomposition:

  • ARIMA:

  • 2nd Plot looks similar to Population Time Series

  • ARIMA decomposes trend into:

    • Trend (2nd Plot)
    • Residuals (4th Plot)
  • SARIMA:

    • Plot 1: Time Series with a seasonal pattern.

    • SARIMA decomposes trend into:

      • Trend (2nd Plot)
      • Seasonality (3rd Plot)
      • Residuals (4th Plot)

Netflix Stock Prices - Review

Dashed lines show peaks at irregular intervals.

Netflix Stock

  • Forecast Questions:

    • What will be the estimated stock price be in April of 2026?

    • What ARIMA model was chosen (p,d,q)?

  • Model Assessment Questions:

    • How valid is our model?

      • Check residual plots.
    • How are accurate are our estimates?

      • Examine Prediction Intervals and Prediction Bands

      • Check fit statistics

Netflix Stock - Modeling Time Series Data

Stock Trend Forecast

  • Create time series using Netflix Stock data

    • Specify freq = 12 - 12 observations per year

    • Specify start = c(2010, 1) - first obs. in dataset is January 2010

  • Model data using auto.arima function

    • Specify ic = aic - aic is the information criterion used to determine model.

    • Specify seasonality = F - no seasonal (repeating) pattern in the data.

  • This code will create and save the model:

nflx_ts <- ts(nflx$Adjusted, freq=12, start=c(2010,1))   # create time series
nflx_model <- auto.arima(nflx_ts, ic="aic", seasonal=F)  # model data using auto.arima

Netflix Stock - Create and Plot Forecasts

  • Create forecasts (until April 2026)

    • h = 12 indicates we want to forecast 12 months

    • Most recent date in forecast data is April 1, 2025

    • 12 Months until April 1, 2026

  • Forecasts become less accurate the further into the future you specify.

nflx_forecast <- forecast(nflx_model, h=12) # create forecasts (until April 2026)
nflx_pred_plot <- autoplot(nflx_forecast) + labs(y = "Adjusted Closing Price") +
  theme_classic()
  • Darker purple: 80% Prediction Interval Bounds

  • Lighter purple: 95% Prediction Interval Bounds

  • Plot shows:

    • Lags (p = 0), Differencing (d = 1), Moving Average (q = 3)

Netflix Stock - Forecast Plot

💥 Lecture 26 In-class Exercises - Q2 💥

Session ID: bua345s25

Based on the plot on the previous slide, we can tell how many previous periods (q) are included in each moving average in the model created by the auto.arima function in R.


What is q, the number of previous time periods in the moving average?

Netflix Stock - Examine Numerical Forecasts

  • Point Forecast is the forecasted estimate for each future time period
  • Lo 80 and Hi 80 are lower and upper bounds for the 80% prediction interval
  • Lo 95 and Hi 95 are lower and upper bounds for the 95% prediction interval
         Point Forecast    Lo 80     Hi 80    Lo 95     Hi 95
May 2025       931.5097 887.9080  975.1115 864.8266  998.1929
Jun 2025       917.5952 854.4637  980.7266 821.0439 1014.1464
Jul 2025       909.0272 825.7946  992.2599 781.7339 1036.3206
Aug 2025       909.0272 805.4485 1012.6060 750.6172 1067.4372
Sep 2025       909.0272 788.4891 1029.5653 724.6801 1093.3744
Oct 2025       909.0272 773.6377 1044.4167 701.9668 1116.0876
Nov 2025       909.0272 760.2616 1057.7928 681.5099 1136.5446
Dec 2025       909.0272 747.9928 1070.0616 662.7463 1155.3081
Jan 2026       909.0272 736.5947 1081.4597 645.3145 1172.7400
Feb 2026       909.0272 725.9047 1092.1497 628.9655 1189.0889
Mar 2026       909.0272 715.8053 1102.2492 613.5197 1204.5347
Apr 2026       909.0272 706.2081 1111.8464 598.8421 1219.2124

💥 Lecture 26 In-class Exercises - Q3 💥

Session ID: bua345s25

Interpretation of Netflix Prediction Intervals


In February of 2026, the 80% prediction interval width for the Netflix stock price will be $____ wide.

To find this width, subtract the lower bound (Lo 80) from the upper bound (Hi 80) and round to the closest whole dollar.

How to input your answer:

  • Round to closest whole dollar.

  • Don’t include dollar sign.

Netflix Stock - Examine Residuals and Model Fit

  • Top Plot: Spikes get larger over time

  • ACF: auto-correlation function.

    • Ideally, all or most values are with dashed lines
  • Histogram: Distribution of residuals should be approx. normal

  • Assessment: Stock prices are very volatile and this is sufficient.


    Ljung-Box test

data:  Residuals from ARIMA(0,1,3)
Q* = 27.197, df = 21, p-value = 0.1644

Model df: 3.   Total lags used: 24

Netflix Stock - Examine Residuals and Model Fit

                   ME    RMSE      MAE      MPE     MAPE     MASE         ACF1
Training set 3.464136 33.6508 21.59716 1.309471 10.99867 0.213375 -0.006420417
  • For BUA 345: We will use MAPE = Mean Absolute Percent Error

    • 100 – MAPE = Percent accuracy of model.
  • Despite increasing volatility, our stock price model is estimated to be 89% accurate.

  • This doesn’t guarantee that forecasts will be 89% accurate but it does improve our chances of accurate forecasting.

Seasonality - Not Just Seasons

  • Seasonal periods can be days, months, seasons, decades, etc.
  • Seasonality: repeating pattern of highs and lows of approx. equal timespans
  • 2024 Example shows clear up and down pattern

Seasonality - Sometimes Pattern is Subtle

  • Seasonal periods can be days, months, seasons, decades, etc.
  • Seasonality: repeating pattern of highs and lows of approx. equal timespans
  • 2025 seasonal pattern in this week’s data is much more subtle, but still present.

Seasonality - Not Just Seasons

  • Seasonal periods can be days, months, seasons, decades, etc.
  • Seasonality: repeating pattern of highs and lows of approx. equal timespans

Carbon Dioxide Trends - Monthly - 1958 to Present Day

Seasonality - Not Just Seasons

  • Seasonal periods can be days, months, seasons, decades, etc.
  • Seasonality: repeating pattern of highs and lows of approx. equal timespans

Carbon Dioxide - Monthly - 2015 to Present Day

Seasonality and Trend

Data above are decomposed into these components:

  • Plot shows BOTH

    • Upward Trend
    • Seasonal Pattern
  • Forecasting model is specified to account for both components

  • Forecasting decomposes data into

    • Trend

    • Seasonality

    • Residuals

Seasonal Data: Alaska Electricity Revenue

  • Alaska is very far north so there is

    • summer light (day and night)

    • winter darkness (day and night)

  • Alaska Electricity usage has a strong seasonal pattern.

    • Data are quarterly residential revenues:

      • 1st Qtr of 2001 to 4th Qtr of 2024

Rows: 96
Columns: 2
$ Date    <date> 2001-03-31, 2001-06-30, 2001-09-30, 2001-…
$ Revenue <dbl> 542.9275, 424.4111, 394.4869, 529.6425, 57…

Alaska Residential Electricity Time Series

Alaska Residential Time Series

  • Create Time Series and Examine it:
  • Format of Time Series with Quarters:

    • head(ak_res_ts, 20) shows first 20 observations and format.
         Qtr1     Qtr2     Qtr3     Qtr4
2001 542.9275 424.4111 394.4869 529.6425
2002 570.5655 439.6120 408.6286 513.4108
2003 571.3253 440.5069 418.7918 556.3850
2004 612.2230 459.5118 430.6615 559.5087
2005 611.2410 447.8371 436.4646 566.1093

💥 Lecture 26 In-class Exercises - Q4 💥

Session ID: bua345s25

If our time series from Alaska were augmented so that it started in February of 1990 (2nd month) and we had data by month (12 observations per year), how would our ts command change in R?

Hint: Our current data, ak_res are quarterly, and begin in the first quarter of 2001. The command we used to create time series is:

ts(ak_res$Revenue, freq=4, start=c(2001,1))


  1. ts(ak_res$Revenue, freq=1, start=c(1, 1990))

  2. ts(ak_res$Revenue, freq=4, start=c(2, 1990))

  3. ts(ak_res$Revenue, freq=12, start=c(1990, 2))

  4. ts(ak_res$Revenue, freq=12, start=c(2, 1990))

  5. ts(ak_res$Revenue, freq=4, start=c(1, 1990))

Alaska Residential Electricity Time Series

Incorrect Model: Ignores Seasonality (seasonal = F)

  • Notice how wide the prediction intervals are.
  • Model only optimizes p, d, and q for full time series (0,0,4).

Alaska Residential Electricity Time Series

Correct Model: Includes Seasonality (seasonal = T)

  • Prediction intervals are MUCH more narrow
  • Optimizes p, d and q for full time series (1,0,1) and within season (2,1,0).
  • Indicates number of time periods within season, [4]

💥 Lecture 26 In-class Exercises - Q5 💥

Session ID: bua345s25

Our data is quarterly and has four observations per year ending in the 4th quarter of 2024.

If the state of Alaska wants to extend the forecast until the Fall of 2026 (3rd Quarter), how would they change the R command?

Hint: Current forecast extends until the 4th quarter of 2025 and command is written as:

forecast(ak_res_model2, h=4)


  1. forecast(ak_res_model2, h=6)

  2. forecast(ak_res_model2, h=7)

  3. forecast(ak_res_model2, h=8)

  4. forecast(ak_res_model2, h=9)

  5. forecast(ak_res_model2, h=10)

Incorrect Model: Less precise

Year Qtr Pt Lo95 Hi95
2025 1 558.12 480.25 635.99
2025 2 464.34 385.69 542.99
2025 3 508.10 408.97 607.24
2025 4 513.99 413.64 614.35

Q4 Width = Hi - Lo = $201

Correct Model: More precise

Year Qtr Pt Lo95 Hi95
2025 1 612.30 582.64 641.96
2025 2 449.49 417.14 481.85
2025 3 432.75 398.77 466.72
2025 4 561.73 526.75 596.72

Q4 Width = Hi - Lo = $70

Prediction Bands Indicate Model Precision

  • Prediction bands are MUCH narrower when seasonality is accounted for.

Incorrect Model Forecasts and Prediction Bounds

        Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
2025 Q1       558.1209 507.2023 609.0395 480.2476 635.9942
2025 Q2       464.3424 412.9172 515.7677 385.6943 542.9906
2025 Q3       508.1026 443.2806 572.9247 408.9658 607.2394
2025 Q4       513.9923 448.3731 579.6115 413.6364 614.3481

Correct Model Forecasts and Prediction Bounds

        Point Forecast    Lo 80    Hi 80    Lo 95    Hi 95
2025 Q1       612.2996 592.9063 631.6930 582.6401 641.9592
2025 Q2       449.4930 428.3375 470.6485 417.1384 481.8475
2025 Q3       432.7463 410.5294 454.9631 398.7685 466.7240
2025 Q4       561.7324 538.8579 584.6070 526.7488 596.7160
  • Interpretation of 95% Prediction Bounds:

  • We are 95% certain that 4th qtr. revenue in 2025 will fall within:

    • Incorrect model range: $614.35 - $413.63 = $201
    • Correct model range: $596.72 - $526.75 = $70

Comparison of Model Residuals

Incorrect Model:

  • Residuals MUCH larger
  • Are highly correlated
    • See ACF plot

Correct Model:

  • Residuals MUCH smaller
  • Auto-correlation assumption is met
    • ACF plot: lags in range

Incorrect Model Accuracy:

ME RMSE MAE MPE MAPE MASE ACF1
Training set 0.326926 38.68311 31.71156 -0.8681514 6.216107 2.406423 0.0289635
  • The incorrect model’s percent accuracy is 93.8%. - Better than expected.

Correct Model Accuracy:

ME RMSE MAE MPE MAPE MASE ACF1
Training set 0.9936991 14.48846 10.7029 0.1383641 1.989122 0.8121866 -0.0175043
  • The correct model’s percent accuracy is 98%.

  • Always plot data, but if seasonality is difficult to discern, run both models and compare them.

  • Residuals (previous slide) and model accuracy (this slide) of models will indicate which model is correct.