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

 
 

bug #43721: [octave forge] (statistics) statistical CDF functions lack "upper" argument support

Submitter:  Falk Tannhäuser <fata>
Submitted:  Fri 28 Nov 2014 01:50:30 PM UTC
 
Category:  Octave Forge Package Severity:  1 - Wish
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  In Progress Assigned to:  None
Originator Name:  fata Open/Closed:  * Closed
Release:  * dev Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment (Rich Markup)
   

Comment Type & Canned Response:
       

 

( Jump to the original submission )

Wed 28 Sep 2022 11:08:32 AM UTC, comment #19: 

This has been transferred to Github as issue #48 at https://github.com/gnu-octave/statistics/issues/48
It can be closed.

Andreas Bertsatos <pr0m1th3as>
Mon 08 Aug 2022 06:37:20 PM UTC, comment #18: 

I set a timeline until 30.9.2022 to make a new major release (1.5.0) for the statistics package, which is currently maintained only at Github, with the hope that we will manage to close all previous tickets at savannah and move over to Github completely. My plan thereafter is to make minor releases every couple of months so the users don't have to wait for long time before bug fixes or new features become available.

Opening issues at github with whatever ticket is left open here is a very good idea.

Andreas Bertsatos <pr0m1th3as>
Mon 08 Aug 2022 06:08:47 PM UTC, comment #17: 

yeah, this is not a short task.  will take a look at some and see how straightforward they are. When you get the point of having most of these older bugs closed and if you are planning to move over to github for issue tracking instead, we could prob open one there to keep track of whatever's left and then close this with a pointer.

Nicholas Jankowski <nrjank>
Project Member
Sun 07 Aug 2022 07:28:01 PM UTC, comment #16: 

unidcdf along with all other cdf functions available in inst/distributions/ have been added in the csf wrapper. See commit at https://github.com/gnu-octave/statistics/commit/17862255f7d3822115978f34b6e766f8a858c9bd

I don't have the time to implement the "upper" option in the remaining functions, but if Nicholas or anybody else are willing to make this feature available in other cdf functions, I will happily modify the cdf wrapper to include the 'upper' option for these.

The 'binocdf' has already been added to the cdf wrapper including the 'upper' option. Hopefully, I will get the time to implement an 'rnd' equivalent of the 'cdf' and 'pdf' wrappers.

Feel free to make a pull request at Github or just post the updated functions in this post. A git patch would be nice, but whatever suits you best. I will make sure that any changes are pushed to the github repo.

Andreas Bertsatos <pr0m1th3as>
Fri 05 Aug 2022 09:30:25 PM UTC, comment #15: 

here's a working list of cdf functions that accept 'upper' in matlab, using the list in Octave's cdf wrapper function to generate the list:

cdf
betacdf
binocdf
cauchy_cdf
chi2cdf
discrete_cdf
expcdf
fcdf
gamcdf
geocdf
gevcdf
hygecdf
kolmogorov_smirnov_cdf
laplace_cdf
logistic_cdf
logncdf
normcdf
poisscdf
raylcdf
tcdf
unifcdf
wblcdf

ones we have but are not linked from our cdf and I see having 'upper' over in matlab:

unidcdf

others having 'upper' over in matlab that i don't see implemented in octave yet:
evcdf
ncfcdf
nctcdf
ncx2cdf

Nicholas Jankowski <nrjank>
Project Member
Mon 29 Nov 2021 06:28:24 PM UTC, comment #14: 

ok, reopening after reading more closely.  The various links below point to:

Octave Distributions:
https://www.gnu.org/software/octave/doc/interpreter/Distributions.html

Matlab Cont. Distributions:
https://www.mathworks.com/help/stats/continuous-distributions.html

Matlab Discrete Distributions:
https://www.mathworks.com/help/stats/discrete-distributions.html

noting that those don't point to functions, but pages of lists of functions, what's the easiest way to generate a checklist of implemented OF-statistics functions needing this change?

are they all covered under the section:
https://octave.sourceforge.io/statistics/overview.html#Distributions
?

does someone just need to do a matlab doc check against each one?

Nicholas Jankowski <nrjank>
Project Member
Mon 29 Nov 2021 05:57:23 PM UTC, comment #13: 

The original bug with binocdf is indeed solved, but the 'upper' argument is still not supported in the other *cdf functions.

Nir Krakauer <nir_krakauer>
Sun 28 Nov 2021 07:42:50 PM UTC, comment #12: 

Assuming avinoam's approach solves all of the problems (both accuracy and compatibility were mentioned below), closing bug as fixed. Can reopen or create a new report if there are still any concerns.

Nicholas Jankowski <nrjank>
Project Member
Wed 24 Nov 2021 11:13:40 PM UTC, comment #11: 

I committed the new feature for binocdf following Avinoam's implementation.

Nir Krakauer <nir_krakauer>
Sat 21 Apr 2018 05:44:40 PM UTC, comment #10: 

All of the CDF functions in Octave have been moved to the Octave Forge statistics package, reassigning.

Mike Miller <mtmiller>
Project Administrator
Thu 12 Nov 2015 03:31:12 AM UTC, comment #9: 

I think this bug should be fixed generally.  It appears that just about all of the cumulative distribution functions in the Statistics Toolbox support the 'upper' argument.  I've re-titled the bug to reflect that.

Rik <rik5>
Project Administrator
Thu 11 Dec 2014 08:47:24 PM UTC, comment #8: 

Hi,

Here is a binocdf.m file for review, based on Falk Tannhäuser
implementation of the 'upper' option.

Changes:
1. "upper" was changed to 'upper' (better matlab compatability)
2. A few words of documentation on the 'upper' option
3. New tests

Please check this.

Thanks,

Avinoam 

(file #32651)

Avinoam Kalma <avinoam>
Project Member
Fri 05 Dec 2014 09:40:10 PM UTC, comment #7: 

If there is a complete changeset posted I can review it and push it to Mercurial.

Rik <rik5>
Project Administrator
Tue 02 Dec 2014 03:53:58 PM UTC, comment #6: 

Hello,
Well, for x >= n, binocdf(x, n, p) is exactly 1 and hence binocdf(x, n, p, "upper") is exactly 0. For x < n but x being "close" to n, binocdf(x, n, p) tends to be close to 1, especially if p is close to 0.
Conversely, for x < 0 we have exactly binocdf(x, n, p) == 0 and binocdf(x, n, p, "upper") == 1. For x >= 0 but close to 0 and p close to 1, binocdf(x, n, p) is close to 0 and binocdf(x, n, p, "upper") is close to 1 (possibly equal to 1 within machine precision).
I think it is best to always use betainc(p, x + 1, n - x) for the "upper" case and betainc(1 - p, n - x, x + 1) otherwise.
The user should call binocdf(x, n, p) if he is interested in the probability of a binomially distributed random variable being <= x and binocdf(x, n, p, "upper") for the probability of it being > x.

Falk

Falk Tannhäuser <fata>
Sun 30 Nov 2014 08:08:42 PM UTC, comment #5: 

Hi,

better than my quick & dirty patch :-)

We should add

## @deftypefnx {Function File} {} binocdf (@var{x}, @var{n}, @var{p}, "upper")

and some explanation about the "upper" paameter. I will try
to write something.

Is there a way to know in advance which of

betainc (p, x + 1, n - x)
betainc (1 - p, n - x, x + 1)

Has a better accuracy? We can use it also for the non-lower case.

Avinoam

Avinoam Kalma <avinoam>
Project Member
Sun 30 Nov 2014 01:18:17 PM UTC, comment #4: 

Well, that's a quick&dirty fix for someone needing just approximate Matlab compatibility; however it doesn't solve the problem of accuracy - results below 1e-16 will be wrongly returned as 0, which for many practical purposes is not acceptable.
I attach another version of binocdf.m where in case of "upper",

betainc (p, x + 1, n - x)

is called instead of

betainc (1 - p, n - x, x + 1)

which avoids this loss of accuracy.

For instance,

1 - binocdf(0:10, 10, 1e-5)

yields

[ 9.9996e-05   4.4998e-09   1.2002e-13   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00   0.0000e+00 ]

while with my version

binocdf(0:10, 10, 1e-5, "upper")

yields

[ 9.9996e-05   4.4998e-09   1.1999e-13   2.0999e-18   2.5199e-23   2.0999e-28   1.2000e-33   4.4999e-39   9.9999e-45   1.0000e-50   0.0000e+00 ]

I also added a test case

%!assert (binocdf(99, 100, 0.1, "upper"), 1e-100, 1e-112)

Of course, binocdf() is just one among many other CDF and analogous fixes have to be applied for all the other xxxcdf functions listed on https://www.gnu.org/software/octave/doc/interpreter/Distributions.html#Distributions - that's a considerable amount of work!

(file #32575)

Falk Tannhäuser <fata>
Sat 29 Nov 2014 11:00:08 PM UTC, comment #3: 

Hi,

Please check the attached modified binocdf.m

If the 4th argument is "upper", the result is
1-cdf (X,N, p).

There is no documentation yet.
There is no treatment in special points.

Thanks,

Avinoam

(file #32571)

Avinoam Kalma <avinoam>
Project Member
Fri 28 Nov 2014 04:02:27 PM UTC, comment #2: 

Note however that CDF of other probability distributions (see https://www.gnu.org/software/octave/doc/interpreter/Distributions.html#Distributions for a list) are also concerned by this Matlab incompatibility / missing feature. Compare with the CDF in the "functions" sections of the individual probability distributions listed under http://fr.mathworks.com/help/stats/continuous-distributions.html or http://fr.mathworks.com/help/stats/discrete-distributions.html

Falk Tannhäuser <fata>
Fri 28 Nov 2014 02:39:25 PM UTC, comment #1: 

This function is Octave core so I'm adjusting the title to avoid confusion with the statistics package.

Carnë Draug <carandraug>
Project Member
Fri 28 Nov 2014 01:50:30 PM UTC, original submission:  

In Matlab the cumulative distribution functions (probability / statistics) accept a special argument string "upper" which causes the function to return the complement of the CDF - see for example http://fr.mathworks.com/help/stats/binocdf.html
For example

binocdf(x, N,p , 'upper')

is equivalent to

1 - binocdf(x, N, p)

except that extreme upper tail probabilities are calculated more accurately.
It seems desirable to have the same feature in Octave.

Falk Tannhäuser <fata>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #32651:  binocdf.m added by avinoam (4KiB - application/octet-stream)
file #32575:  binocdf.m added by fata (4KiB - application/octet-stream)
file #32571:  binocdf.m added by avinoam (3KiB - application/octet-stream)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by pr0m1th3as (Posted a comment)
  • -email is unavailable- added by nrjank (Posted a comment)
  • -email is unavailable- added by nir_krakauer (Posted a comment)
  • -email is unavailable- added by gyom
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by avinoam (Updated the item)
  • -email is unavailable- added by avinoam
  • -email is unavailable- added by carandraug (Arno Onken - maintainer of the statistics package)
  • -email is unavailable- added by fata (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 project members can vote.

     

     

     

     

    Follow 21 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-09-28 nrjank Open/ClosedOpen Closed
    2021-11-29 nrjank StatusFixed In Progress
        Open/ClosedClosed Open
    2021-11-28 nrjank StatusConfirmed Fixed
        Open/ClosedOpen Closed
    2019-03-18 gyom Carbon-Copy- Added gyom
    2018-04-21 mtmiller CategoryOctave Function Octave Forge Package
        Summarystatistical CDF functions lack "upper" argument support [octave forge] (statistics) statistical CDF functions lack "upper" argument support
    2015-11-12 rik5 Item GroupFeature Request Matlab Compatibility
        StatusNone Confirmed
        Summarybinocdf - cumulative distribution functions lack "upper" argument statistical CDF functions lack "upper" argument support
    2014-12-11 avinoam Attached File- Added binocdf.m, #32651
    2014-11-30 fata Attached File- Added binocdf.m, #32575
    2014-11-29 avinoam Attached File- Added binocdf.m, #32571
    2014-11-28 avinoam Carbon-Copy- Added avinoam
    2014-11-28 carandraug Severity3 - Normal 1 - Wish
        Item GroupMatlab Compatibility Feature Request
        Release3.8.2 dev
        Operating SystemMicrosoft Windows Any
        SummaryStatistics: cumulative distribution functions lack "upper" argument binocdf - cumulative distribution functions lack "upper" argument
        Carbon-Copy- Added -email is unavailable-

    Back to the top


    Powered by Savane 3.9