statrs-dev / statrs

Statistical computation library for Rust
https://docs.rs/statrs/latest/statrs/
MIT License
546 stars 78 forks source link

BUG: `laplace.inverse_cdf()` is not correct. #160

Closed WarrenWeckesser closed 2 years ago

WarrenWeckesser commented 2 years ago

The implementation of the inverse_cdf() method for the Laplace distribution is missing calls to ln(). The following https://github.com/statrs-dev/statrs/blob/435739b180913fa0e815403836eb74cd79041d60/src/distribution/laplace.rs#L127-L131

should be

        if p <= 0.5 {
            self.location + self.scale * (2. * p).ln()
        } else {
            self.location - self.scale * (2. - 2. * p).ln()
        }

(See, for example, the entry for Quantile in the table on the right in the Laplace distribution wikipedia page.)

I'll submit a pull request with a fix.