Time Series Stats: Predicting the Future with AI

Applied Statistics
A practical introduction to time series analysis, stationarity, ARIMA models, forecasting, and diagnostics for AI and clinical decision-making.
Published

July 15, 2024

Modified

June 9, 2026

Executive Summary

Many datasets are not just collections of independent observations.

They unfold over time.

That changes everything.

When data are ordered in time, the past can influence the future. Observations close together may be more similar than observations far apart. Trends, seasonality, shocks, and persistence all begin to matter.

This is the setting of time series analysis (Box et al. 2015; Hyndman and Athanasopoulos 2021).

Time series methods are built for questions such as:

  • is this process stable over time?
  • how strongly does the present depend on the recent past?
  • can we separate signal from temporal noise?
  • and how should we forecast future values with uncertainty?

These are classical statistical questions, but they are also deeply relevant to AI/ML.

Time series concepts underlie:

  • forecasting systems,
  • anomaly detection,
  • sequential decision models,
  • and the logic of more advanced models such as RNNs and LSTMs.

This post introduces:

  • stationarity,
  • autoregressive and moving-average structure,
  • ARIMA models,
  • forecasting with confidence intervals,
  • and practical diagnostics using a health-trend style example.

Time series analysis matters because once time enters the data, independence leaves the room.


Time Changes the Statistical Problem

In ordinary cross-sectional analysis, we often assume observations are independent.

Time series data break that assumption almost immediately.

If a variable is measured daily, weekly, or monthly, then today’s value may depend on:

  • yesterday’s value,
  • last week’s shock,
  • seasonal cycles,
  • or long-term drift.

That means the order of the data carries information.

This is why time series analysis is not just “regression with dates attached.” It is a different modeling problem (Box et al. 2015; Hyndman and Athanasopoulos 2021).

The analyst must account for temporal dependence, not merely average relationships.


A Time Series Is About Dependence Across Time

A time series can be thought of as a sequence:

\[ Y_1, Y_2, Y_3, \dots, Y_T \]

where each value is indexed by time.

The key idea is that these values are not arbitrary neighbors. Their ordering matters.

Time dependence can show up through:

  • trend, where the series drifts upward or downward
  • seasonality, where the series repeats cyclical patterns
  • autocorrelation, where past values help predict future values
  • volatility changes, where uncertainty itself varies over time

Understanding these patterns is the first step in any time series workflow.


Stationarity Is One of the Core Ideas

One of the most important concepts in time series analysis is stationarity.

A stationary process is one whose statistical properties are stable over time.

In broad applied terms, this often means:

  • the mean does not drift systematically,
  • the variance is roughly stable,
  • and the dependence structure is not changing unpredictably across time.

Why does this matter?

Because many classical time series models, including ARIMA components, work best when the underlying series is stationary or has been transformed into something close to stationary.

A nonstationary series often contains trend or other structure that must be handled before modeling dependence properly.


A Health-Trend Example Makes the Problem Concrete

To keep the example practical, we will simulate a simple monthly health-trend series, such as infection counts, clinic demand, or symptom burden over time.

The example includes:

  • a mild upward trend
  • seasonal structure
  • and random noise
library(dplyr)
library(tibble)
library(ggplot2)

n_time <- 120

ts_df <- tibble::tibble(
  month = 1:n_time,
  seasonal = 8 * sin(2 * pi * month / 12),
  trend = 0.25 * month,
  noise = rnorm(n_time, mean = 0, sd = 4)
) |>
  dplyr::mutate(
    health_metric = 50 + trend + seasonal + noise
  )

ggplot2::ggplot(ts_df, ggplot2::aes(x = month, y = health_metric)) +
  ggplot2::geom_line(linewidth = 0.7) +
  ggplot2::labs(
    title = "Simulated Monthly Health Trend",
    x = "Month",
    y = "Health Metric"
  ) +
  ggplot2::theme_minimal()

This is clearly not a flat, independent series. It contains time structure that must be modeled explicitly.


Visual Inspection Is the First Diagnostic in Time Series Work

Before fitting any formal model, it helps to plot the series.

That is not optional decoration. It is a core diagnostic step.

A time series plot can reveal:

  • trend
  • seasonality
  • abrupt level shifts
  • outliers
  • changing variance
  • or structural breaks

These features often determine what kind of model is appropriate.

A series with strong trend should not be treated the same way as a mean-stationary series with short-term autocorrelation only.


Stationarity Can Be Investigated Formally

Visual inspection is useful, but analysts often also want a formal test for stationarity.

One common choice is the Augmented Dickey-Fuller test.

This test evaluates whether the series appears to contain a unit root, which is one indicator of nonstationarity.

required_pkgs <- c("tseries")
missing_pkgs <- required_pkgs[
  !vapply(required_pkgs, requireNamespace, logical(1), quietly = TRUE)
$$

if (length(missing_pkgs) > 0) {
  stop("Missing packages: ", paste(missing_pkgs, collapse = ", "))
}

tseries::adf.test(ts_df$health_metric)

The ADF test is useful, but it should not be treated as the only decision tool.

In practice, stationarity assessment is best based on:

  • plots
  • domain knowledge
  • and formal diagnostics together

Differencing Is a Common Way to Address Nonstationarity

If a series has trend, one common fix is differencing.

The first difference is:

\[ \nabla Y_t = Y_t - Y_{t-1} \]

This removes persistent level drift and often helps stabilize the mean structure.

Let us difference the simulated series.

ts_df <- ts_df |>
  dplyr::mutate(
    diff_health_metric = c(NA, diff(health_metric))
  )

ggplot2::ggplot(ts_df, ggplot2::aes(x = month, y = diff_health_metric)) +
  ggplot2::geom_line(linewidth = 0.7, na.rm = TRUE) +
  ggplot2::labs(
    title = "First-Differenced Health Trend",
    x = "Month",
    y = "Differenced Value"
  ) +
  ggplot2::theme_minimal()

The differenced series often looks more stable and is closer to the kind of object classical ARIMA models are designed to handle.


AR and MA Models Capture Different Kinds of Dependence

Two of the most important building blocks in time series analysis are:

  • autoregressive (AR) models
  • moving average (MA) models

Autoregressive Idea

An AR model says the current value depends on previous values.

For an AR(1) model:

\[ Y_t = \phi Y_{t-1} + \varepsilon_t \]

This means the present is directly regressed on the recent past.

Moving Average Idea

An MA model says the current value depends on current and past shocks.

For an MA(1) model:

\[ Y_t = \varepsilon_t + \theta \varepsilon_{t-1} \]

This means dependence arises through the propagation of error terms.

These two ideas can be combined.


ARIMA Combines Differencing with AR and MA Structure

ARIMA stands for (Box et al. 2015; Hyndman and Athanasopoulos 2021):

  • AR: autoregressive terms
  • I: integrated, meaning differencing
  • MA: moving average terms

An ARIMA((p,d,q)) model includes:

  • (p): number of AR terms
  • (d): number of differences
  • (q): number of MA terms

This is one of the most important classical forecasting frameworks because it handles:

  • nonstationarity through differencing
  • serial dependence through AR and MA structure

That makes ARIMA a powerful baseline time series model.


Autocorrelation Plots Help Suggest Model Structure

Two classic tools in time series diagnostics are:

  • the autocorrelation function (ACF)
  • the partial autocorrelation function (PACF)

These help suggest whether AR or MA structure may be present.

par(mfrow = c(1, 2))
acf(na.omit(ts_df$diff_health_metric), main = "ACF of Differenced Series")
pacf(na.omit(ts_df$diff_health_metric), main = "PACF of Differenced Series")

par(mfrow = c(1, 1))

In applied workflows, these plots are used heuristically.

They do not mechanically determine the right model, but they provide useful clues about the temporal dependence structure.


Fitting an ARIMA Model in R

We can fit an ARIMA model directly using arima() or forecast::Arima().

Below is a simple example.

fit_arima <- arima(ts_df$health_metric, order = c(1, 1, 1))
fit_arima

Call:
arima(x = ts_df$health_metric, order = c(1, 1, 1))

Coefficients:
          ar1     ma1
      -0.1953  0.0556
s.e.   0.4750  0.4794

sigma^2 estimated as 41.9:  log likelihood = -391.11,  aic = 788.22

This model includes:

  • one AR term
  • first differencing
  • one MA term

In real workflows, model selection may be guided by:

  • ACF/PACF behavior
  • information criteria such as AIC
  • and forecast performance

Automated ARIMA Selection Can Be Useful, but Should Be Interpreted Carefully

In practice, many analysts use automated model selection.

required_pkgs <- c("forecast")
missing_pkgs <- required_pkgs[
  !vapply(required_pkgs, requireNamespace, logical(1), quietly = TRUE)
$$

if (length(missing_pkgs) > 0) {
  stop("Missing packages: ", paste(missing_pkgs, collapse = ", "))
}

ts_obj <- ts(ts_df$health_metric, frequency = 12)
fit_auto <- forecast::auto.arima(ts_obj)
fit_auto

Automated selection can be convenient, but it should not replace understanding.

A model chosen by information criteria is still only as useful as:

  • the assumptions behind it
  • the time structure in the data
  • and the forecasting context

Automation is helpful. Interpretation still matters.


Forecasting Requires Uncertainty, Not Just Point Predictions

One of the main goals of time series modeling is forecasting.

But a forecast is not just a future point estimate. It is also an uncertainty statement.

That is why forecast plots usually include:

  • a central forecast line
  • and confidence bands around it

These bands widen as the forecast horizon increases because uncertainty accumulates.

ts_obj <- ts(ts_df$health_metric, frequency = 12)
fit_auto <- forecast::auto.arima(ts_obj)
fc <- forecast::forecast(fit_auto, h = 12)

plot(fc)

This is one of the places where classical statistics remains especially valuable: it forces uncertainty back into future predictions.


Forecast Confidence Bands Are a Guard Against False Precision

Forecast intervals are essential because future uncertainty is often larger than users expect.

Without uncertainty bands, a forecast can look falsely exact.

This is especially dangerous in:

  • health systems planning
  • staffing forecasts
  • supply chain projections
  • operational readiness estimates
  • financial or market trend communication

A point forecast says what is most plausible under the model. The confidence band reminds us how uncertain that future still is.

This is one of the key lessons time series analysis shares with the broader statistical tradition.


Residual Diagnostics Still Matter After Model Fitting

A fitted ARIMA model should leave residuals that look approximately like white noise.

That means the model should have captured most of the systematic time dependence.

Residual checks often include:

  • residual plots
  • residual ACF
  • Ljung-Box style tests for remaining autocorrelation
ts_resid <- residuals(fit_arima)

par(mfrow = c(1, 2))
plot(ts_resid, type = "l", main = "ARIMA Residuals", ylab = "Residual")
acf(ts_resid, main = "ACF of ARIMA Residuals")

par(mfrow = c(1, 1))

If substantial autocorrelation remains, the model may be missing important temporal structure.


Time Series Methods Matter in AI/ML Because Sequence Matters

Modern AI/ML systems often work with sequential data:

  • physiological monitoring streams
  • stock prices
  • web traffic
  • wearable sensor data
  • device telemetry
  • language tokens
  • temporal event logs

What classical time series methods teach is not obsolete in these contexts.

They teach:

  • dependence across time
  • the importance of temporal ordering
  • the need for stationarity or transformation
  • and the distinction between signal and sequential noise

Even complex sequence models such as RNNs and LSTMs still live in the world of temporal dependence that classical time series analysis helped formalize.


ARIMA Is Not the Whole Story, but It Is a Powerful Baseline

ARIMA is not the only time series tool.

It does not automatically handle:

  • complex nonlinear structure
  • rich external covariates
  • regime switching
  • high-dimensional multivariate dependencies
  • or all seasonal complexities without extension

But it remains extremely valuable because it is:

  • interpretable
  • well understood
  • fast to fit
  • and often surprisingly competitive as a forecasting baseline

In ML practice, a strong classical baseline is always valuable. If a much more complex model does not clearly outperform it, that is meaningful.


A Health-Trend Plot with a Simple Forecast Illustration

A useful final visualization is to split the series into training and future periods and show a basic forecast conceptually.

train_df <- ts_df |>
  dplyr::filter(month <= 108)

test_df <- ts_df |>
  dplyr::filter(month > 108)

ggplot2::ggplot() +
  ggplot2::geom_line(
    data = train_df,
    ggplot2::aes(x = month, y = health_metric),
    linewidth = 0.7
  ) +
  ggplot2::geom_line(
    data = test_df,
    ggplot2::aes(x = month, y = health_metric),
    linetype = 2,
    linewidth = 0.7
  ) +
  ggplot2::labs(
    title = "Training Period and Held-Out Future Segment",
    x = "Month",
    y = "Health Metric"
  ) +
  ggplot2::theme_minimal()

This kind of plot helps reinforce that forecasting should be evaluated on future-like data, not only on in-sample fit.


A Practical Checklist for Applied Work

Before fitting or reporting a time series model, ask:

  • Is the series approximately stationary, or does it need transformation?
  • Is there visible trend or seasonality?
  • Have I plotted the data before modeling?
  • Do ACF and PACF suggest meaningful dependence structure?
  • Are residuals approximately white noise after fitting?
  • Am I reporting forecast uncertainty, not just point forecasts?
  • Is ARIMA a sensible baseline before moving to more complex sequential models?
  • Does the model reflect the real forecasting use case?

These questions usually improve both rigor and communication.


NoteWhere This Shows Up in AI/ML

ICU early warning systems — including the sepsis prediction models deployed in Epic and Cerner — depend on time-series vital sign streams: each new observation inherits context from the preceding hours, and deterioration signals often emerge from trajectory rather than from any single value. LSTM and Transformer-based models for clinical early warning are architecturally designed to capture exactly this temporal dependency, treating each patient encounter as a sequence rather than an independent cross-section. The failure mode is using a static logistic regression model trained on admission-snapshot features to predict 24-hour deterioration in patients already in the ICU: the model sees where the patient started, not where the trajectory is heading, and systematically misses patients who deteriorate rapidly from an initially stable baseline. In military far-forward care, where vital signs may be recorded at irregular intervals under austere conditions, standard time-series assumptions about regular sampling intervals break down and must be explicitly addressed before applying ARIMA or LSTM-based approaches.

Closing: Time Series Analysis Teaches Statistical Respect for Time

Time series analysis matters because time introduces structure that ordinary methods cannot ignore.

AR, MA, and ARIMA models help analysts think clearly about:

  • dependence
  • stationarity
  • forecasting
  • and uncertainty over time

They remain valuable in their own right, and they also provide a conceptual foundation for more advanced AI/ML methods built for sequential data.

Time series methods still matter because predicting the future is not only about fitting patterns, but about respecting how the past shapes the present and constrains the future.


Tip📚 Go Deeper: Real-World Evidence Toolkit

This post is part of the Real-World Evidence Toolkit — a companion reference with temporal data modeling templates, stationarity diagnostics, ARIMA scaffolds, and interrupted time series analysis code.

→ Open the Real-World Evidence Toolkit


Series Callout

Note

This post is part of a broader Applied Statistics for AI and Clinical Decision-Making Series:

  • Probability fundamentals for machine learning
  • Random variables and expectation
  • Common probability distributions
  • Central Limit Theorem
  • Law of Large Numbers
  • Sampling methods for Biostats and ML
  • Hypothesis testing in the age of AI
  • Confidence intervals
  • Maximum likelihood estimation
  • Bayesian inference
  • Linear regression
  • Logistic regression
  • Generalized linear models
  • Analysis of variance
  • Principal component analysis
  • Cluster analysis
  • Time series analysis
  • Survival analysis
  • Non-parametric methods
  • Bias-variance tradeoff
  • Regularization
  • Cross-validation
  • Information theory
  • Optimization techniques
  • Linear algebra basics
  • Calculus for ML
  • Monte Carlo methods
  • Dimensionality curse and reduction techniques
  • Model evaluation metrics
  • Ensemble methods

References

Box, George E. P., Gwilym M. Jenkins, Gregory C. Reinsel, and Greta M. Ljung. 2015. Time Series Analysis: Forecasting and Control. 5th ed. Wiley.
Hyndman, Rob J., and George Athanasopoulos. 2021. Forecasting: Principles and Practice. 3rd ed. OTexts. https://otexts.com/fpp3/.