Skip to content

Fix confidence interval when slope significance breaks down in invpred - #477

Merged
pr0m1th3as merged 2 commits into
gnu-octave:mainfrom
AvanishSalunke:invpred
Sep 9, 2026
Merged

Fix confidence interval when slope significance breaks down in invpred#477
pr0m1th3as merged 2 commits into
gnu-octave:mainfrom
AvanishSalunke:invpred

Conversation

@AvanishSalunke

Copy link
Copy Markdown
Contributor

invpred always returned dxlo = Inf, dxup = Inf whenever the slope wasn't significant, treating every such case as an interval covering the whole real line. But in some cases the correct interval is only unbounded on one side, with a finite value on the other. Fixed by checking which case applies instead of assuming both sides are always infinite.

BEFORE:

octave:3> [x0, dxlo, dxup] = invpred((1:5)', [1; 5; 2; 8; 3], 100)
x0 = 140.43
dxlo = Inf
dxup = Inf

AFTER:

octave:3> [x0, dxlo, dxup] = invpred((1:5)', [1; 5; 2; 8; 3], 100)
x0 = 140.43
dxlo = 111.31
dxup = Inf

MATLAB:

>> [x0, dxlo, dxup] = invpred((1:5)', [1; 5; 2; 8; 3], 100)

x0 =

  140.4286


dxlo =

  111.3077


dxup =

   Inf

@pr0m1th3as

Copy link
Copy Markdown
Member

Thanks for this. The reasoning is right and it is worth having.

MATLAB ships an invpred of its own, and its documentation states exactly what this PR implements:

The intervals are not simultaneous and are not necessarily finite. Some intervals may extend from a finite value to -Inf or +Inf, and some may extend over the entire real line.

I checked the scalar cases against R2024a and they agree to every digit it displays, at the default alpha and at alpha = 0.5, for both predopt values. So the direction and the arithmetic are both correct.

One thing blocks it: with the interval requested, the new branch fails on a non-scalar y0. It has to be all three outputs, since invpred returns before the interval code when nargout < 2.

>> [x0, dxlo, dxup] = invpred ((1:5)', [1;5;2;8;3], [100; 200]);
error: operator -: nonconformant arguments (op1 is 2x1, op2 is 0x1)

>> [x0, dxlo, dxup] = invpred ((1:5)', [1;5;2;8;3], [-100; 100]);
error: =: nonconformant arguments (op1 is 1x1, op2 is 2x1)

centre and halfwidth are the same size as y0, but only offset is indexed on the right-hand side of the two new assignments:

dxup(lower_ray) = centre(lower_ray) - halfwidth(lower_ray) - offset(lower_ray);
dxlo(upper_ray) = offset(upper_ray) - centre(upper_ray) - halfwidth(upper_ray);

main answers these calls with dxlo and dxup both Inf rather than raising, so it is a regression and not just an uncovered case. The same page is explicit that this has to work: "Y0 can be an array of any size", and "Both DXLO and DXUP have the same size as Y0".

Could you add tests with a vector y0 as well? Your scalar test passes because a scalar makes the sizes agree by accident, so it never reaches the code the patch rewrites. Two values from R2024a, on your own fixture:

  • invpred ((1:5)', [1;5;2;8;3], [-100; 100]) gives dxlo = [Inf; 111.3077] and dxup = [120.0731; Inf]
  • invpred ((1:5)', [1;5;2;8;3], [100; 200]) gives dxlo = [111.3077; 226.7256] and dxup = [Inf; Inf]

With those two changes this is good to go.

@AvanishSalunke

Copy link
Copy Markdown
Contributor Author

Hello @pr0m1th3as updated !!

center and halfwidth weren't indexed by the mask while offset was, so it broke as soon as y0 had more than one element. Fixed it by indexing all three consistently.

Also added the two vector - y0 testcases.

@pr0m1th3as
pr0m1th3as merged commit d500ad6 into gnu-octave:main Sep 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants