bugGNU Octave - Bugs: bug #54696, [octave forge] (statistics)...

 
 

bug #54696: [octave forge] (statistics) regress function produces division by zero and complex intervals with linear input

Submitted by:  Miguel V. S. Frasson <frasson>
Submitted on:  Wed 19 Sep 2018 09:29:22 PM UTC  
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Open/Closed:  Open
Release:  other Operating System:  GNU/Linux

Add a New Comment(Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

Thu 20 Sep 2018 12:07:05 AM UTC, comment #1:

Confirmed with the current versions of Octave (4.4.1) and the Octave Forge statistics package (1.4.0).

Mike Miller <mtmiller>
Project Administrator
Wed 19 Sep 2018 09:29:22 PM UTC, original submission:

Hi

With an application using regress(), it happened that input data was a column of ones (all percents = 100%), then a warning with division by zero appeared.

y = A * ones(n,1) ==> division by zero on line 167 of regress.m
y = A * X(:,2) + B ==> division by zero on line 169 of regress.m

for any A and B real numbers.

System:
=======

Xubuntu 16.04.

>> ver statistics

----------------------------------------------------------------------
GNU Octave Version: 4.0.0
GNU Octave License: GNU General Public License
Operating System: Linux 4.15.0-34-generic #37~16.04.1-Ubuntu SMP Tue Aug 28 10:44:06 UTC 2018 x86_64
----------------------------------------------------------------------
Package Name | Version | Installation directory
--------------+---------+-----------------------
statistics *| 1.2.4 | /usr/share/octave/packages/statistics-1.2.4

Reproduzing:
============

1) Save file bug1.m with contents

1;
## bug with constant y

pkg load statistics

rand("seed",1)
A = rand()
n = 5;

X = [ones(n,1),(1:n)'];
y = A * ones(n,1);

[b, bint, r, rint, stats] = regress (y, X)

2) Save file bug2.m with contents

1;
## bug with linear y
pkg load statistics

rand("seed",1)
A = rand()
B = rand()
n = 5;

X = [ones(n,1),(1:n)'];

y = A * X(:,2) + B
[b, bint, r, rint, stats] = regress (y , X)

3) from terminal

octave --eval bug1

4) read from terminal

A = 0.86680
warning: division by zero
warning: called from
regress at line 167 column 8
bug at line 13 column 27
b1 =

8.6680e-01
5.5511e-17

bint1 =

8.6680e-01 8.6680e-01
-8.8732e-17 1.9975e-16

r1 =

2.2204e-16
1.1102e-16
0.0000e+00
0.0000e+00
0.0000e+00

rint1 =

2.2204e-16 - 3.5332e-16i 2.2204e-16 + 3.5332e-16i
-2.8400e-16 - 0.0000e+00i 5.0605e-16 + 0.0000e+00i
-4.9967e-16 - 0.0000e+00i 4.9967e-16 + 0.0000e+00i
-4.6740e-16 - 0.0000e+00i 4.6740e-16 + 0.0000e+00i
-3.5332e-16 - 0.0000e+00i 3.5332e-16 + 0.0000e+00i

stats1 =

-Inf -3.0000e+00 1.0000e+00 2.0543e-32

5) from terminal

octave --eval bug2

6) read from terminal

A = 0.86680
B = 0.91265
y =

1.7795
2.6463
3.5131
4.3799
5.2467

warning: division by zero
warning: called from
regress at line 169 column 7
bug2 at line 13 column 27
b2 =

0.91265
0.86680

bint2 =

0.91265 0.91265
0.86680 0.86680

r2 =

4.4409e-16
0.0000e+00
-4.4409e-16
-8.8818e-16
-8.8818e-16

rint2 =

-1.2868e-15 - 0.0000e+00i 2.1750e-15 + 0.0000e+00i
-2.6440e-15 - 0.0000e+00i 2.6440e-15 + 0.0000e+00i
-3.0881e-15 - 0.0000e+00i 2.1999e-15 + 0.0000e+00i
-2.6191e-15 - 0.0000e+00i 8.4274e-16 + 0.0000e+00i
-8.8818e-16 - 2.9783e-23i -8.8818e-16 + 2.9783e-23i

stats2 =

1.00000 Inf 0.00000 0.00000

7) Observe that

  • Notice warning of division by zero on lines 167 and 169
  • Notice rint1 (intervals) have complex numbers! (probably sqrt of negative small numbers)

Cause of problem:
=================

Lines from 165 to 174 from regress.m:

if (nargout > 4)

R2 = 1 - SSE / sum ((y - mean (y)) .^ 2);
# F = (R2 / (p - 1)) / ((1 - R2) / dof);
F = dof / (p - 1) / (1 / R2 - 1);
pval = 1 - fcdf (F, p - 1, dof);

stats = [R2 F pval v];

endif

On line 167, denominator
sum ((y - mean (y)) .^ 2)
is zero with y == A * ones(n,1), for all a real and n integer.

If (p == 1) or (R2 == 1) then it will happend division by zero on line 169.

Miguel V. S. Frasson <frasson>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

Attached Files
file #45056:  bug1.m added by frasson (177B - application/vnd.wolfram.mathematica.package - Input files to reproduce bug)
file #45057:  bug2.m added by frasson (185B - application/vnd.wolfram.mathematica.package - Input files to reproduce bug)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by frasson
  • -email is unavailable- added by frasson (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 8 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-09-20 mtmiller CategoryLibraries => Octave Forge Package
        Item GroupNone => Incorrect Result
        StatusNone => Confirmed
        Release4.0.0 => other
        Summarystatistics' regress function produces division by zero and complex intervals with linear input => [octave forge] (statistics) regress function produces division by zero and complex intervals with linear input
    2018-09-19 frasson Attached File- => Added bug1.m, #45056
        Attached File- => Added bug2.m, #45057
        Carbon-Copy- => Added -email is unavailable-

    Back to the top


    Powered by Savane 3.3