twolodzko / extraDistr

Additional univariate and multivariate distributions
51 stars 11 forks source link

Running pgev, pgpd, pbbinom functions with numeric(0) result in R crashing #4

Closed m1hawkgsm closed 7 years ago

m1hawkgsm commented 7 years ago

Found this through using the fitdistrplus package when estimating a generalized pareto distribution, but realized it does the same effect on a number of p distribution functions (tested pgpd, pbbinom, pgev all fail, but seems okay with some like pnorm and pdgamma).

Basically, if I run pgpd(q = numeric(0), mu = 0, sigma= 1, xi = 0, lower.tail = TRUE, log.p = FALSE), R crashes. Similarly for other functions mentioned (not sure if more, didn't check all of your p functions).

Reason why this matters: I'm estimating a distribution using censored data via MLE using fitdistcens from the package fitidistrplus and it builds the likelihood function as if we have left/right/interval censored data (meaning, if I actually don't have all three, part of the function ends up calling the distribution function from extraDistr with empty numeric(0) quantile argument. Normally that's fine as, for example, ppois just returns numeric(0) which is exactly what one would expect (and not a crash).

Guessing the underlying C++ should have a length check or something? I already bothered the fitdistrplus authors to include checks if there's actually data for each type of censoring when building these function calls, but figured you'd like to know.

twolodzko commented 7 years ago

@m1hawkgsm Thanks for the bug report. This is an interesting bug -- honestly I never thought of it, neither tested for it. Actually it concerns with literally every function in this package. Hopefully it can be easily fixed and will be in the next CRAN release of the package. In the next few days I'll post a fix on github and it will be available in the github version.

dutangc commented 7 years ago

Dear package maintainer,

Could you please send me an email when push the bug-fixed version of extraDistr on CRAN?

Despite this bug, your package is particularly good, that's why I put in the task view. Soon I will update what are the core packages of the view. You might be added to the list.

By the way, on http://www.rpackages.io/view/Distributions, you can see that your package is regularly downloaded.

Christophe one of fitdistrplus' authors

twolodzko commented 7 years ago

@dutangc Thanks for your message. I hope to find some time to post fixes and test them in the following week or two and then post in on CRAN. I'll remember to e-mail you then.