[Bug]: Scalar PLR rejects a treatment on a small scale: the near-zero check on E[psi_a] uses an absolute threshold

Open
#464 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@vrjdev is already working on this.

Since Nov 17, 2026.

  • #467 by @vrjdev — open

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
20/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale

Research direction

Read doubleml/double_ml_linear_score.py at LinearScoreMixin._est_causal_pars and review the absolute near-zero check described in the issue. Reproduce the failure with the supplied scalar PLR example at treatment scale 1e-7, then check the expected scale-invariant coefficient and standard error against DoubleMLPLR. The issue is already being worked on in open pull request #467.

Written by the indexing model from the issue text.

Description

Describe the bug

LinearScoreMixin._est_causal_pars (doubleml/double_ml_linear_score.py:88 on main) refuses to estimate when |E[psi_a]| < 1e-12:

if np.any(np.abs(mean_psi_a) < 1e-12):
    raise ValueError("Division by near-zero detected in linear score estimation. ...")

The threshold is absolute, but E[psi_a] carries the units of the treatment. For the scalar PLR, psi_a = -(d - m(x))^2 (partialling out) or -(d - m(x)) * d (IV-type), so it scales with d². A treatment whose residual standard deviation is below about 1e-6 in its own units is rejected, although the estimate is well defined: in other units (e.g. multiplied by 1e-7), the same treatment has the same effect up to the scale. The legacy DoubleMLPLR estimates it fine. The error message also points at the wrong cause ("issues with the nuisance models or data").

This only affects the new scalar API on main (from #394); it is not in a release yet. The scalar IRM isn't affected in practice, since its psi_a doesn't depend on the treatment's units.

Minimum reproducible code snippet
import numpy as np
from sklearn.linear_model import LinearRegression

import doubleml as dml
from doubleml.plm.plr_scalar import PLR

np.random.seed(0)
n = 1000
x = np.random.normal(size=(n, 3))
d = x[:, 0] + np.random.normal(size=n)
y = 0.5 * d + x[:, 1] + np.random.normal(size=n)

for scale in [1.0, 1e-7]:  # the same treatment in other units: theta becomes 0.5 / scale
    data = dml.DoubleMLData.from_arrays(x, y, d * scale)
    legacy = dml.DoubleMLPLR(data, LinearRegression(), LinearRegression(), n_folds=5).fit()
    print(f"scale={scale:g}: E[psi_a] = {np.mean(legacy.psi_elements['psi_a']):.3g}")
    print(f"  DoubleMLPLR:  coef * scale = {legacy.coef[0] * scale:.4f}, se * scale = {legacy.se[0] * scale:.4f}")
    scalar = PLR(data, ml_l=LinearRegression(), ml_m=LinearRegression())
    scalar.set_sample_splitting(legacy.smpls)
    try:
        scalar.fit()
        print(f"  PLR (scalar): coef * scale = {scalar.coef[0] * scale:.4f}, se * scale = {scalar.se[0] * scale:.4f}")
    except ValueError as e:
        print(f"  PLR (scalar): ValueError: {e}")
Expected Result

The scalar PLR estimates the rescaled treatment, like DoubleMLPLR (output with a scale-free check):

scale=1: E[psi_a] = -1.04
  DoubleMLPLR:  coef * scale = 0.4802, se * scale = 0.0321
  PLR (scalar): coef * scale = 0.4802, se * scale = 0.0321
scale=1e-07: E[psi_a] = -1.04e-14
  DoubleMLPLR:  coef * scale = 0.4831, se * scale = 0.0321
  PLR (scalar): coef * scale = 0.4831, se * scale = 0.0321

The two DoubleMLPLR fits draw different sample splits (hence 0.4802 vs 0.4831); the scalar model reuses each one's splits.

Actual Result
scale=1: E[psi_a] = -1.04
  DoubleMLPLR:  coef * scale = 0.4802, se * scale = 0.0321
  PLR (scalar): coef * scale = 0.4802, se * scale = 0.0321
scale=1e-07: E[psi_a] = -1.04e-14
  DoubleMLPLR:  coef * scale = 0.4831, se * scale = 0.0321
  PLR (scalar): ValueError: Division by near-zero detected in linear score estimation. E[psi_a] is very close to zero. This may indicate issues with the nuisance models or data.
Versions
Linux x86_64 (glibc 2.34)
Python 3.12.16
DoubleML main @ 9c7dbea (unreleased; not in 0.11.4)
Scikit-Learn 1.9.1
Dominant language
Python
Stars
800
Forks
133
Avg merge
1d 12h
Merged PRs (30d)
29

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from DoubleML/doubleml-for-py

All issues in DoubleML/doubleml-for-py

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.