Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inverse exponential distribution has inconsistent parametrisation #108

Open
Fuco1 opened this issue Apr 26, 2024 · 1 comment
Open

Inverse exponential distribution has inconsistent parametrisation #108

Fuco1 opened this issue Apr 26, 2024 · 1 comment

Comments

@Fuco1
Copy link

Fuco1 commented Apr 26, 2024

Given a cdf F defined on positive numbers for a random variable X, we can find the reciprocal random variable Y = 1/X and its cdf G as follows:

G(y) = Pr(Y <= y) // definition

substitute Y = 1/X and rearrange

Pr(Y <= y) = Pr(X >= 1/y) = 1 - Pr(X < 1/y) = 1 - F(1/y)

Therefore G(y) = 1 - F(1/y)

In this package however:

## this is G(y) in terms of original exponential F(x) cdf
> 1 - cdf(dist_exponential(0.5), 1 / 1:10)[[1]]      
 [1] 0.6065 0.7788 0.8465 0.8825 0.9048 0.9200 0.9311 0.9394 0.9460 0.9512

## using inverse exponential with the same rate gives different results
> cdf(dist_inverse_exponential(0.5), 1:10)[[1]]    
 [1] 0.1353 0.3679 0.5134 0.6065 0.6703 0.7165 0.7515 0.7788 0.8007 0.8187

## using inverse exponential with the reciprocal of the rate gives correct results
> cdf(dist_inverse_exponential(1 / 0.5), 1:10)[[1]]  
 [1] 0.6065 0.7788 0.8465 0.8825 0.9048 0.9200 0.9311 0.9394 0.9460 0.9512

So you can see that we need to parametrize the inverse function with the reciprocal rate to get the same result.

In my opinion this is a confusing API and it caught me a bit off guard while I realized where I was getting weird numbers from :)

Edit:

Using the dist_transformed we get another interesting interplay, notice the quantiles being first 0.8 and then 0.2

> dist_transformed(dist_exponential(1/0.3), \(x) 1/x, \(x) 1/x) %>% quantile(0.8)
[1] 2.071
> dist_inverse_exponential(0.3) %>% quantile(0.2)
[1] 2.071
> 

I'm quite confused to be honest :D

@Fuco1
Copy link
Author

Fuco1 commented May 7, 2024

Another thing is that Weibull distribution with shape = 1 is the same as exponential, but also uses reciprocal "rate" argument (called scale in this package).

I don't know if it makes sense to unify this or what are the usual conventions there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant