Autoregressive models: predicting with past data

An autoregressive model predicts each next value from the values before it. How AR models work in time series forecasting and in LLMs like GPT, with examples.

Emily Bowen
Editor: Emily Bowen

Updated November 2026

An autoregressive model is a model that predicts the next value in a sequence from the values that came before it. In time series forecasting, an AR model writes today's value as a weighted sum of past values plus random noise. A large language model works the same way, predicting each next token (a word or piece of a word) from the tokens already written.

If you've heard the word from your forecasting team and your chatbot team, they mean the same loop: feed the past back in, predict the next step, and repeat. One forecasts next month's sales; the other writes a reply.

What is an autoregressive model?

An autoregressive model is a regression of a variable on its own past values. Auto means self: the model's inputs are earlier values of the same series it predicts.

An ordinary regression predicts one variable from others, such as a house's price from its floor area. An autoregression predicts this month's sales from the last three months' sales.

The number of past values the model uses is its order, written p. An AR(1) model uses one previous value, and an AR(p) model uses p of them. (AR here stands for autoregressive, not augmented reality.)

The term has two homes. In statistics and econometrics, it names a family of forecasting models for time series such as temperatures, prices, and sunspot counts.

In machine learning, it names any model that generates a sequence one element at a time, each element predicted from the ones before it. Language models, some speech synthesizers, and some image generators work this way.

Both senses share one constraint: the model only looks backward. That is what lets it forecast, and it is also why it produces output one step at a time.

The two senses differ in machinery, not in idea. A forecasting model's prediction is a weighted sum of a handful of past values. A language model replaces that sum with a neural network that looks back over thousands of tokens.

How autoregressive models work

An autoregressive model forecasts by multiplying each recent value by a learned weight, adding the results to a constant, and treating the gap between the forecast and what really happens as random noise.

Say you have an AR(1) model with a constant of 2 and a weight of 0.8 on the previous value. If the last value was 20, the next forecast is 2 + 0.8 × 20 = 18.

Two steps ahead, you have no real value for the next step yet, so the model feeds its own forecast back in: 2 + 0.8 × 18 = 16.4. The forecasts after that are 15.12, 14.1, 13.28, and 12.62.

Each forecast moves closer to 10, the series' long-run mean. For an AR(1) model, that mean is the constant divided by one minus the weight: 2 / (1 - 0.8) = 10.

That pull toward the mean holds only for a stationary series, one whose mean and variance stay stable over time. An AR(1) model is stationary when its weight is between -1 and 1.

At a weight of exactly 1 and no constant, the AR(1) series becomes a random walk: each value is the last one plus a fresh shock, so the series wanders with no mean to return to and its forecasts never settle.

The noise term is why real data never follows the smooth forecast path. Every step adds a fresh random shock, and the weights decide how long each shock echoes through later values.

Line chart of a first-order autoregressive model with a constant of 2 and a weight of 0.8. The last value, 20, is followed by six forecasts, 18, 16.4, 15.12, 14.1, 13.28, and 12.62, each joined to the one before it by an arrow, because the model feeds its own forecast back in. The points flatten toward a line at 10, the series' long-run mean. A card shows 2 + 0.8 × 20 = 18 and 2 + 0.8 × 18 = 16.4.

Mathematical representation of autoregressive models

An AR(p) model of order p takes this form: xₜ = c + φ₁xₜ₋₁ + φ₂xₜ₋₂ + … + φₚxₜ₋ₚ + εₜ. Each symbol has one job:

  • xₜ is the value at time t, and xₜ₋₁ is the value one step earlier.
  • c is a constant.
  • φ₁ to φₚ are the weights the model learns, one for each past value, or lag.
  • εₜ is white noise: a random shock with a mean of zero and a constant variance, uncorrelated from one step to the next.

The AR(1) model above is the case p = 1, with c = 2 and φ₁ = 0.8. Fitting a model means estimating c and the weights from data, usually by least squares, the method an ordinary linear regression uses.

How to fit an autoregressive model in Python

The statsmodels library fits autoregressive models in Python with its AutoReg class. Its ar_select_order function picks the order from the data.

The example below uses the yearly sunspot numbers that ship with statsmodels, which run from 0 to 190 between 1700 and 2008. It picks the order on the years up to 1988, fits the model, and forecasts 1989 to 2008.

Python
import pandas as pdfrom statsmodels.datasets import sunspotsfrom statsmodels.tsa.ar_model import AutoReg, ar_select_orderdata = sunspots.load_pandas().datay = pd.Series(data["SUNACTIVITY"].values, index=pd.period_range("1700", periods=len(data), freq="Y"))train, test = y[:"1988"], y["1989":]sel = ar_select_order(train, maxlag=15, ic="bic")print("lags chosen:", sel.ar_lags)res = AutoReg(train, lags=sel.ar_lags).fit()print(res.params.round(3))pred = res.predict(start=test.index[0], end=test.index[-1])mae = (pred - test).abs().mean()print(f"mean absolute error, 1989-2008: {mae:.1f}")

When you run it, the order search picks nine lags, which reach back most of the roughly 11-year sunspot cycle. Lag 1 carries the largest weight, 1.191, and four of the nine weights are negative.

A weight above 1 does not break the model. The -1 to 1 rule applies to AR(1) only.

With nine lags, stationarity depends on all the weights together. The model's characteristic roots, which statsmodels reports, all lie outside the unit circle, and that is the check this model passes.

The 20 forecasts are multi-step: each year's forecast feeds into the next, and the model never sees the 1989 to 2008 values.

The forecasts miss the actual sunspot number by 11.5 on average. Predicting the 1700 to 1988 average every year would miss by 44.0.

How to choose the order of an AR model

The order of an AR model is chosen in three steps: make the series stationary, read its partial autocorrelations, and then compare candidate orders with an information criterion.

If your series has a trend, you difference it first, which means modeling the change from one step to the next instead of the level itself. Sunspot numbers rise and fall without a long-term trend, so the example skips this step.

Autocorrelation measures how strongly a series tracks its own earlier values. The partial autocorrelation function (PACF) measures how well the value k steps back predicts today, with the steps in between taken out.

Plotted as one bar per lag, an AR(p) series shows its last bar outside the plot's shaded band at lag p, and none beyond it.

Akaike's AIC and Schwarz's BIC, two information criteria, both reward a good fit and charge a penalty for every extra weight. BIC charges more, so it tends to pick smaller models. The example's ar_select_order call runs this step with BIC.

Types of autoregressive models

Each autoregressive variant keeps the use of past values and adds one thing the plain AR model cannot handle:

  • An AR(p) model, the base case, predicts from p past values.
  • An ARMA model adds a moving-average part, which predicts from the last few forecast errors as well as the last few values.
  • An ARIMA model differences the series first (the I stands for integrated), so it can follow a trend.
  • A seasonal ARIMA model adds values from one season back, such as last December's demand when it forecasts this December.
  • A VAR model, or vector autoregression, predicts several series together, each from the past values of all of them. Christopher Sims proposed it for macroeconomics in 1980.
  • An ARCH model predicts how much a series will vary rather than its level, such as the swings in financial returns. Robert Engle introduced it in 1982, and Tim Bollerslev's GARCH generalized it in 1986.
  • A neural autoregressive model replaces the weighted sum with a neural network, which can learn patterns a straight-line rule cannot. Language models are this type.

Examples and applications of autoregressive models

Sunspot numbers, the series in the Python example above, are the classic time series example. Others include:

  • Macroeconomic analysis, where VAR models track how output, money, and prices move together.
  • Financial risk, where GARCH models forecast how volatile an asset's returns will be.
  • Capacity planning, such as forecasting next week's call volume from past weeks to staff a contact center.

Generative examples produce text, sound, and images one element at a time:

  • GPT-style language models write text one token at a time.
  • WaveNet generates raw audio one sample at a time, at least 16,000 samples for every second of speech.
  • PixelCNN generates an image one pixel at a time, row by row.
  • Voice AI agents speak replies that a language model writes token by token.

Limitations of autoregressive models

Autoregressive models have four main limitations: they are linear, they need a stable past, their errors compound, and they produce output one step at a time.

  • A classic AR model is linear. A weighted sum cannot follow a relationship that bends, such as demand that saturates.
  • The model needs a stable past. A shock it has never seen, such as a pandemic, breaks the forecast, because the weights only describe history.
  • Errors compound. Each multi-step forecast feeds on earlier forecasts, so a miss early on carries into every later step.
  • Output is sequential. A generative model runs one pass through the network for every token it writes, so a 500-token reply takes 500 decode steps, one full pass through the network each. It also cannot revise a token once written.

Autoregressive models in generative AI

Large language models such as GPT are autoregressive: they generate text one token at a time, and they predict each new token from all the tokens before it.

Generation is a loop. When you send a prompt, the model reads the prompt and computes a probability for every token in its vocabulary. It picks one, appends it to the input, and repeats until it writes a stop token or reaches a length limit.

The pick is usually a sample from those probabilities, not always the top token, which is why the same prompt can give you two different replies.

That loop is why a chatbot's answer can appear on your screen word by word instead of all at once.

The math behind the loop is the chain rule of probability: the chance of a whole sentence is the chance of each word given the words before it, multiplied together.

Statisticians call that split autoregressive factorization, and the GPT-2 paper defines language modeling with it.

The Transformer paper calls its decoder, the part of the model that writes output, auto-regressive for the same reason: each step consumes the symbols generated so far.

Diagram of the token generation loop. The input holds the prompt's tokens and an open slot. The model reads the prompt and computes a probability for every token in its vocabulary, then picks one token. An arrow carries that token back into the open slot: the model appends it to the input and repeats, until it writes a stop token or reaches a length limit.

Training does not need the loop, which is why training runs in parallel while generation is the slow part.

During training the model already has the whole text, so the training setup hides the tokens to the right of each position, and the model learns every position's next-token prediction at once.

Autoregressive vs non-autoregressive models

An autoregressive model produces a sequence one element at a time, left to right, while a non-autoregressive model produces many elements in parallel or fills them in using context from both sides.

Model typeHow it fills a sequenceContext it usesSteps to produce n tokens
Autoregressive (GPT-style decoder)One token at a time, left to rightEarlier tokens onlyn
Masked language model (BERT)Predicts hidden tokens inside a given textTokens on both sidesNot used to generate text
Diffusion modelRefines every position from noiseThe whole sequence at each stepA fixed number of refinement steps
Non-autoregressive translationAll output tokens at onceThe source sentenceOne

BERT is not autoregressive. It hides some words in a sentence and predicts them from the words on both sides, which its authors call a masked language model.

That design makes BERT a model for understanding text, such as classification and question answering, not for writing it.

Diffusion models drop the one-token-per-step loop: they start from noise and refine every position at each step.

The number of diffusion steps does not grow with the length of the output, which is why they can be faster than an autoregressive model that needs one step per token.

Text-to-speech models split the same way. Some generate speech tokens one step at a time, while diffusion and similar models refine a chunk of speech in parallel over a fixed number of steps.

In the first non-autoregressive translation model, parallel output cost accuracy. Gu and colleagues built a model that writes every output word at once, each chosen without seeing the others.

On English to German, the fastest version translated a sentence in 39 ms against 607 ms for the autoregressive model, but scored about 6 points lower on BLEU, a 0 to 100 translation-quality score.

Scoring 100 candidate translations and keeping the best narrowed that gap to about 4 points, but the speedup shrank from 15.6 times to 2.4 times.

Three panels comparing how models fill a sequence of six tokens. Autoregressive, a GPT-style decoder: one token at a time, left to right, with arcs from the earlier tokens only into the next token. Masked language model, such as BERT: two hidden tokens predicted from the tokens on both sides. Diffusion model: every position is refined from noise over several steps, using the whole sequence at each step.

Autoregressive generation in voice AI agents

A voice AI agent turns the caller's speech into text, writes a reply with a language model, and speaks it with text-to-speech.

The agent can start speaking as soon as the first sentence of the reply exists, because the language model writes that reply one token at a time.

On a phone call, you notice the silence before the agent's first word, not how long the rest of the answer takes.

That wait is the model's time to first token, or TTFT, plus the first sentence's tokens, plus speech synthesis. The first sentence is the part that sets the wait, not the length of the whole reply.

If you build the pipeline yourself, you send each finished sentence from the token stream to speech as it completes.

On Telnyx, the chat completions API streams tokens as the model writes them, the text-to-speech WebSocket turns text into audio a sentence at a time, and the Voice API carries the call.

Frequently asked questions

Is GPT an autoregressive model?

GPT models are autoregressive. Training teaches them to predict the next token from the tokens before it, and they generate text by repeating that prediction, one token at a time.

Is BERT an autoregressive model?

BERT is not an autoregressive model. It predicts masked words from the context on both sides at once, so it does not generate text one token after another.

Is an LSTM autoregressive?

An LSTM is autoregressive only when it generates by feeding its own predictions back in. An LSTM is a type of neural network that reads a sequence one step at a time.

An LSTM language model that predicts the next word and feeds it back in is autoregressive; an LSTM that tags a sentence it has already read is not.

What is the difference between autoregression and regression?

A regression predicts one variable from other variables, such as umbrella sales from rainfall. An autoregression predicts a variable from its own earlier values, such as umbrella sales this week from umbrella sales in recent weeks.

What are ARMA and ARIMA models?

ARMA and ARIMA models extend the AR model. ARMA(p, q) adds q past forecast errors to p past values. ARIMA(p, d, q) also differences the series d times first, so it can handle a trend.

Sources

Share on Social

This content was generated with the assistance of AI. Our AI prompt chain workflow is carefully grounded and preferences .gov and .edu citations when available. All content is reviewed by a Telnyx employee to ensure accuracy, relevance, and a high standard of quality.

Sign up and start building.