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

 
 

bug #60113: [octave forge] (statistics) Function 'triinv(x, a, b, c)' returns incorrect values

Submitter:  None
Submitted:  Thu 25 Feb 2021 09:23:13 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Fixed Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  * Closed Release:  * 5.2.0
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 22 Feb 2022 07:33:42 PM UTC, comment #6: 

Marking as fixed and closing report.

Rik <rik5>
Group administrator
Tue 23 Nov 2021 06:01:18 PM UTC, comment #5: 
Nir Krakauer <nir_krakauer>
Fri 05 Mar 2021 07:04:37 PM UTC, comment #4: 

and a script that checks consistency between triinv and tricdf and between tricdf and tripdf

(file #51004, file #51005, file #51006)

A.R. Burgers <arb>
Fri 05 Mar 2021 06:57:55 PM UTC, comment #3: 

an updated changeset that improves both triinv and tripdf.

(file #51003)

A.R. Burgers <arb>
Thu 04 Mar 2021 09:49:27 PM UTC, comment #2: 

The attached changeset b60113.txt takes a step towards fixing tricdf. Certainly better than it was.

(file #50989)

A.R. Burgers <arb>
Thu 25 Feb 2021 01:43:43 PM UTC, comment #1: 

tricdf also seems to have discontinuities and values < 0:


x=linspace(0,10,100);
plot(x,tricdf(x,1,8,3));


A.R. Burgers <arb>
Thu 25 Feb 2021 09:23:13 AM UTC, original submission:  

The function 'triinv(x, a, b, c)' from the Octave Forge package 'statistics' produces output that doesn't look right to me.

I am using statistics-1.4.2.tar.gz downloaded and installed on 25/02/2021 and Octave version 5.2.0. I have uninstalled and re-installed a clean download of the package several times and got identical results each time. I think this problem will occur on any system but for information I am using a Dell Latitude E6230 laptop with Intel Core i5-3340M CPU @ 2.70GHz and 4GB of RAM running Xubuntu 20.04.2 LTS.

The attached file figure1.jpg shows a plot of y = triinv(x, 2, 5, 3). This contains a large discontinuity which it clearly shouldn't have.

figure2.jpg shows the same plot using a quick and dirty implementation of the formula for the quantile function of the triangular random variable with the same arguments. (See https://en.wikipedia.org/wiki/Triangular_distribution (section entitled "Generating triangular-distributed random variates") or https://github.com/distributions-io/triangular-quantile.) This is what the curve should look like.

I think the error is in lines 61 and 65 of the file 'triinv.m'. These lines don't embody the correct formula for the quantile function. (h/2) should appear as a divisor not a multiplier.

Line 61 currently says:


inv(j) += (x(j) * (h/2) * w).^0.5 + a;


but should say:


inv(j) += (x(j) * w / (h/2)).^0.5 + a;


Line 65 currently says:


inv(j) += b - ((1-x(j)) * (h/2) * w).^0.5;


but should say:


inv(j) += b - ((1-x(j)) * w / (h/2)).^0.5;


figure3.jpg shows the same plot using a copy of 'triinv.m' containing the suggested changes in lines 61 and 65.

The same considerations also apply to the corresponding lines (74 and 78) in the subsequent block of code that deals with non-scalar values of a, b and c.

Anonymous

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #51004:  tst_statistics_tri.m added by arb (1KiB - text/plain)
file #51005:  tst_pdf.m added by arb (190B - text/plain)
file #51006:  tst_cdf_inv.m added by arb (160B - text/plain)
file #51003:  b60113_v2.txt added by arb (3KiB - text/plain)
file #50989:  b60113.txt added by arb (1KiB - text/plain)
file #50918:  figure2.jpg added by None (18KiB - image/jpeg)
file #50919:  figure3.jpg added by None (18KiB - image/jpeg)
file #50917:  figure1.jpg added by None (16KiB - image/jpeg)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by nrjank (Updated the item)
  • -email is unavailable- added by nir_krakauer (Posted a comment)
  • -email is unavailable- added by mmuetzel (Updated the item)
  • -email is unavailable- added by arb (Posted a comment)
  •  

    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 12 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-02-22 rik5 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2021-11-23 nrjank StatusNone Ready For Test
    2021-03-05 arb Attached File- Added tst_statistics_tri.m, #51004
        Attached File- Added tst_pdf.m, #51005
        Attached File- Added tst_cdf_inv.m, #51006
    2021-03-05 arb Attached File- Added b60113_v2.txt, #51003
    2021-03-04 arb Attached File- Added b60113.txt, #50989
    2021-03-03 mmuetzel SummaryFunction 'triinv(x, a, b, c)' from 'statistics' package returns incorrect values [octave forge] (statistics) Function 'triinv(x, a, b, c)' returns incorrect values
    2021-02-25 None Attached File- Added figure1.jpg, #50917
        Attached File- Added figure2.jpg, #50918
        Attached File- Added figure3.jpg, #50919

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code