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

Submitter:  Miguel V. S. Frasson <frasson>
Submitted:  Wed 19 Sep 2018 09:29:22 PM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Works For Me Assigned to:  None
Originator Name:  Open/Closed:  * Closed
Release:  * other Operating System:  * GNU/Linux
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sun 28 Nov 2021 08:01:53 PM UTC, comment #3: 

accidentally pasted bug1 output twice.  bug2 output below.

A = 0.8668
B = 0.9127
y =

   1.7795
   2.6463
   3.5131
   4.3799
   5.2467

b2 =

   0.9127
   0.8668

bint2 =

   0.9127   0.9127
   0.8668   0.8668

r2 =

   8.8818e-16
   4.4409e-16
            0
            0
            0

rint2 =

   8.8818e-16 - 1.4133e-15i   8.8818e-16 + 1.4133e-15i
  -1.1360e-15 -          0i   2.0242e-15 +          0i
  -1.9987e-15 -          0i   1.9987e-15 +          0i
  -1.8696e-15 -          0i   1.8696e-15 +          0i
  -1.4133e-15 -          0i   1.4133e-15 +          0i

stats2 =

   1.0000      Inf        0   0.0000


Nicholas Jankowski <nrjank>
Group Member
Sun 28 Nov 2021 08:00:20 PM UTC, comment #2: 

Not seeing this error anymore on Octave 6.4.0 with statistics v.1.4.2.

run from terminal with --eval same way as comment #0, i get:

bug1.m:

A = 0.8668
b1 =

   8.6680e-01
   2.7756e-17

bint1 =

   8.6680e-01   8.6680e-01
  -4.6774e-16   5.2325e-16

r1 =

   4.4409e-16
   4.4409e-16
   3.3307e-16
   3.3307e-16
   3.3307e-16

rint1 =

  -2.4466e-16   1.1328e-15
  -8.1257e-16   1.7007e-15
  -1.2111e-15   1.8772e-15
  -1.0868e-15   1.7530e-15
  -6.2156e-16   1.2877e-15

stats1 =

         -Inf  -3.0000e+00   1.0000e+00   2.4241e-31


and bug2.m:

A = 0.8668
b1 =

   8.6680e-01
   2.7756e-17

bint1 =

   8.6680e-01   8.6680e-01
  -4.6774e-16   5.2325e-16

r1 =

   4.4409e-16
   4.4409e-16
   3.3307e-16
   3.3307e-16
   3.3307e-16

rint1 =

  -2.4466e-16   1.1328e-15
  -8.1257e-16   1.7007e-15
  -1.2111e-15   1.8772e-15
  -1.0868e-15   1.7530e-15
  -6.2156e-16   1.2877e-15

stats1 =

         -Inf  -3.0000e+00   1.0000e+00   2.4241e-31


assuming that the code producing the divide by zero has changed since 2018 and is no longer an issue, closing the report.  Someone can reopen if I'm mistaken.

Nicholas Jankowski <nrjank>
Group Member
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>
Group Member
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 nrjank (Posted a comment)
  • -email is unavailable- added by frasson
  • -email is unavailable- added by frasson (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 10 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2021-11-28 nrjank StatusConfirmed Works For Me
        Open/ClosedOpen Closed
    2018-09-20 mtmiller CategoryLibraries Octave 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.13-4448.
    Corresponding source code