PACF

This function estimates the partial autocorrelation function (PACF), which measures the direct correlation between x_t and x_{t-k} after controlling for intermediate lags.

In autoregressive model identification, PACF helps indicate candidate model order by highlighting lags with substantial direct dependence.

The PACF at lag k can be interpreted as the final coefficient in an AR(k) regression.

Excel Usage

=PACF(x, nlags, pacf_method, alpha)
  • x (list[list], required): Time-series observations as a 2D range.
  • nlags (int, optional, default: null): Maximum lag to compute; null uses statsmodels default.
  • pacf_method (str, optional, default: “ywadjusted”): Estimation method for PACF.
  • alpha (float, optional, default: null): Significance level for confidence intervals; null disables intervals.

Returns (list[list]): 2D table with columns lag, pacf, conf_low, and conf_high.

Example 1: PACF using Yule-Walker adjusted method

Inputs:

x nlags pacf_method alpha
1 2 3 4 5 4 3 2 4 ywadjusted

Excel formula:

=PACF({1,2,3,4,5,4,3,2}, 4, "ywadjusted", )

Expected output:

Result
0 1
1 0.571429
2 -0.649832
3 -0.832527
4 -1.57327
Example 2: PACF with confidence intervals

Inputs:

x nlags pacf_method alpha
2 1 2 1 2 1 2 1 2 4 burg 0.05

Excel formula:

=PACF({2,1,2,1,2,1,2,1,2}, 4, "burg", 0.05)

Expected output:

Result
0 1 1 1
1 -0.97561 -1.62893 -0.322288
2 1 0.346679 1.65332
3 3.14684e-16 -0.653321 0.653321
4 2.5924e-16 -0.653321 0.653321
Example 3: PACF using OLS adjusted estimator

Inputs:

x nlags pacf_method alpha
5 4 6 5 7 6 8 7 9 3 ols-adjusted

Excel formula:

=PACF({5,4,6,5,7,6,8,7,9}, 3, "ols-adjusted", )

Expected output:

Result
0 1
1 0.5625
2 1.28571
3 -0.5
Example 4: PACF using Levinson-Durbin biased estimator

Inputs:

x nlags pacf_method alpha
3 2 4 3 5 4 6 5 3 ldbiased

Excel formula:

=PACF({3,2,4,3,5,4,6,5}, 3, "ldbiased", )

Expected output:

Result
0 1
1 0.25
2 0.288889
3 -0.346983

Python Code

import numpy as np
from statsmodels.tsa.stattools import pacf as sm_pacf

def pacf(x, nlags=None, pacf_method='ywadjusted', alpha=None):
    """
    Compute partial autocorrelation values across lags for lag-order diagnostics.

    See: https://www.statsmodels.org/stable/generated/statsmodels.tsa.stattools.pacf.html

    This example function is provided as-is without any representation of accuracy.

    Args:
        x (list[list]): Time-series observations as a 2D range.
        nlags (int, optional): Maximum lag to compute; null uses statsmodels default. Default is None.
        pacf_method (str, optional): Estimation method for PACF. Valid options: YW, YW Adjusted, OLS, OLS Inefficient, OLS Adjusted, YWM, YWMLE, LD, LD Adjusted, LDB, LD Biased, Burg. Default is 'ywadjusted'.
        alpha (float, optional): Significance level for confidence intervals; null disables intervals. Default is None.

    Returns:
        list[list]: 2D table with columns lag, pacf, conf_low, and conf_high.
    """
    try:
        def to1d(values):
            if isinstance(values, list):
                if all(isinstance(row, list) for row in values):
                    raw = [item for row in values for item in row]
                else:
                    raw = values
            else:
                raw = [values]

            out = []
            for item in raw:
                try:
                    out.append(float(item))
                except (TypeError, ValueError):
                    continue
            return out

        valid_methods = (
            "yw", "ywadjusted", "ols", "ols-inefficient", "ols-adjusted",
            "ywm", "ywmle", "ld", "ldadjusted", "ldb", "ldbiased", "burg"
        )
        if pacf_method not in valid_methods:
            return "Error: method is not a supported PACF estimator"

        series = to1d(x)
        if len(series) < 3:
            return "Error: x must contain at least three numeric values"

        result = sm_pacf(np.asarray(series, dtype=float), nlags=nlags, method=pacf_method, alpha=alpha)

        if isinstance(result, tuple):
            pacf_vals, confint = result
        else:
            pacf_vals = result
            confint = None

        pacf_arr = np.asarray(pacf_vals, dtype=float)
        conf_arr = np.asarray(confint, dtype=float) if confint is not None else None

        table = []
        for lag in range(len(pacf_arr)):
            low = ""
            high = ""
            if conf_arr is not None and lag < len(conf_arr):
                low = float(conf_arr[lag][0])
                high = float(conf_arr[lag][1])
            table.append([lag, float(pacf_arr[lag]), low, high])

        return table
    except Exception as e:
        return f"Error: {str(e)}"

Online Calculator

Time-series observations as a 2D range.
Maximum lag to compute; null uses statsmodels default.
Estimation method for PACF.
Significance level for confidence intervals; null disables intervals.