Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Autoregressive (AR) Models | Section
Forecasting With Classical Models

bookAutoregressive (AR) Models

Свайпніть щоб показати меню

Autoregressive models are a foundational class of time series models that forecast future values based on past observations. In an autoregressive model of order pp, denoted as AR(p), the current value of the series is expressed as a linear combination of its previous pp values plus a random error term. The general form of an AR(p) model is:

Xt=c+φ1Xt1+φ2Xt2+...+φpXtp+εtX_t = c + φ₁X_{t-1} + φ₂X_{t-2} + ... + φₚX_{t-p} + ε_t

where:

  • XtX_t is the value at time tt;
  • cc is a constant;
  • φ1,φ2,...,φpφ₁, φ₂, ..., φₚ are parameters (coefficients) to be estimated;
  • εtε_t is white noise (a random error term with zero mean and constant variance).

A key concept in AR models is the use of lagged values. Lags refer to prior time points in the series; for example, Xt1X_{t-1} is the first lag, Xt2X_{t-2} is the second lag, and so on. The order pp determines how many lagged values are used to predict the current value.

For AR models to be valid, several assumptions should be met:

  • The time series should be stationary, meaning its statistical properties like mean and variance do not change over time;
  • The error terms should be uncorrelated and normally distributed;
  • The model parameters should ensure the process does not explode (i.e., the series remains stable over time).
12345678910111213141516171819202122232425262728293031323334
import numpy as np import pandas as pd import matplotlib.pyplot as plt from statsmodels.tsa.ar_model import AutoReg # Generate a synthetic AR(1) time series np.random.seed(42) n = 100 phi = 0.7 c = 2 errors = np.random.normal(0, 1, n) series = [0] for t in range(1, n): series.append(c + phi * series[-1] + errors[t]) series = pd.Series(series) # Fit an AR(1) model model = AutoReg(series, lags=1) model_fit = model.fit() # Predict the next 10 values pred_start = len(series) pred_end = pred_start + 9 predictions = model_fit.predict(start=pred_start, end=pred_end) # Plot the original series and predictions plt.figure(figsize=(10, 5)) plt.plot(series, label="Original Series") plt.plot(range(pred_start, pred_end + 1), predictions, label="AR(1) Predictions", marker='o') plt.legend() plt.title("AR(1) Model Fit and Forecast") plt.xlabel("Time") plt.ylabel("Value") plt.show()
copy
question mark

Which statement best describes the role of lag in an AR(p) model?

Select the correct answer

Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 5

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

Секція 1. Розділ 5
some-alt