Repository navigation
Description
Describe the bug
ProcessMLE cannot handle missing values. ProcessMLE.from_formula raises
an error whenever a variable used in any of its formulas has a missing value,
although from_formula drops such rows by default (missing="drop"), as it
does for other models. Building the model from arrays with missing="drop"
fails as well. Each path fails differently:
| Path | Error |
|---|---|
from_formula, missing value in the mean formula, one-column scale and smooth formulas |
ValueError: The leading dimensions of all array arguments must be equal. (_check_args) |
| same, two-column scale and smooth formulas | ValueError: Shape mismatch between endog/exog and extra 2d arrays given to model. (ModelData.handle_missing) |
from_formula, missing value only in a variable of scale_formula |
ValueError: operands could not be broadcast together with shapes (40,1) (39,1) |
ProcessMLE(..., missing="drop"), two-column exog_scale and exog_smooth |
IndexError: boolean index did not match indexed array along axis 1 (_drop_nans_2d) |
ProcessMLE(..., missing="drop"), one-column exog_scale and exog_smooth |
constructs, then loglike raises IndexError: index 39 is out of bounds for axis 0 with size 39 |
There are three causes:
ProcessMLE.__init__checks and groups the arguments as passed
(_check_args(endog, exog, exog_scale, ...)andenumerate(groups)),
not the attributes after the base class has dropped the rows with missing
values. The lengths then disagree, or the group indices point past the end
of the reduced data.- The base class's missing-value handling (
ModelData.handle_missing)
treats 2-D extra arrays as square (n, n) matrices ("grab 2d arrays that
are assumed to be symmetric") and drops both rows and columns, so
exog_scale,exog_smoothandexog_noisewith more than one column
cannot be reduced. from_formulaevaluatesscale_formula,smooth_formulaand
noise_formulaseparately from the mean formula, so each drops its own
rows with missing values.
Code Sample, a copy-pastable example
import numpy as np
import pandas as pd
from statsmodels.regression.process_regression import ProcessMLE
rng = np.random.default_rng(0)
n = 40
data = pd.DataFrame(
{
"y": rng.standard_normal(n),
"x": rng.standard_normal(n),
"time": np.tile(np.arange(5.0), 8),
"g": np.repeat(np.arange(8), 5),
}
)
data.loc[3, "y"] = np.nan # a single missing value
model = ProcessMLE.from_formula(
"y ~ x",
data,
scale_formula="0 + x",
smooth_formula="0 + x",
time="time",
groups="g",
)Expected Output
The rows with a missing value in any of the formulas (or arrays) are dropped
from endog, exog, exog_scale, exog_smooth, exog_noise, time and
groups, as for other models, and the model can be fitted. At least, a clear
error that missing values are not supported.
Actual Output
Traceback (most recent call last):
File "repro.py", line 18, in <module>
model = ProcessMLE.from_formula(
File "statsmodels/regression/process_regression.py", line 471, in from_formula
mod = super().from_formula(
File "statsmodels/base/model.py", line 278, in from_formula
mod = cls(endog, exog, *args, **kwargs)
File "statsmodels/regression/process_regression.py", line 318, in __init__
_check_args(endog, exog, exog_scale, exog_smooth, exog_noise, time, groups)
File "statsmodels/regression/process_regression.py", line 203, in _check_args
raise ValueError(msg)
ValueError: The leading dimensions of all array arguments must be equal.Versions
INSTALLED VERSIONS
------------------
Python: 3.15.2.final.0
OS: Linux 6.18.58.1-microsoft-standard-WSL2 x86_64
statsmodels
===========
Installed: 0.15.1.dev2703+gd005266da
Required Dependencies
=====================
cython: 3.3.2
numpy: 2.5.5
scipy: 1.18.1
pandas: 3.1.1
dateutil: 4.0.0
patsy: 1.0.3The code involved is the same in 0.14.6 (_check_args on the arguments,
enumerate(groups), the scale formula evaluated on its own, and the
square-matrix assumption in handle_missing).
Checklist
- I have searched the issue tracker for a similar issue and did not find one.
- I have confirmed this bug exists on the
mainbranch.
AI disclosure: found while reviewing statsmodels.formula with Claude Code
(Claude Opus 5.5), which reproduced the failures and drafted this report; I
reviewed it.
Activity
BUG: Drop missing values in all ProcessMLE arrays