coatless-rpkg / visualize

Visualize probability distributions values
http://r-pkg.thecoatlessprofessor.com/visualize/
Other
4 stars 1 forks source link

Mean and variance of exponential and gamma distributions #15

Open lgawarec opened 5 days ago

lgawarec commented 5 days ago

The mean and variance displayed are incorrect. For example visualize.exp(1,theta=2,"lower") pexp(1,rate=2)

give the same probabilities, but mu=2 and sigma^2=4 are displayed instead of mu = 0.5 and sigma^2=0.25.

coatless commented 5 days ago

@lgawarec Mmm, there might be a hang up in how the exponential distributions are implemented.

If we're using R's implementation, this rests upon:

$$f(w) = \lambda e^{-\lambda w}$$

However, visualize.exp() function signature is noting a $\theta$ parameterization:

$$f(x) = \frac{1}{\theta} e^{-x/\theta}$$

Though, glancing at the source:

https://github.com/coatless-rpkg/visualize/blob/c43b25cdbcd229fc23109eaaf1979d2eb662fc60/R/visualize.exp.R#L33-L35

We're directly using R's implementation.

So, we'll need to apply a conversion between the two of a quick division:

$\theta=\frac{1}{\lambda}$ and $\lambda=\frac{1}{\theta}$

Thanks for finding the bug!