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

Convenience methods for distributions from mean and standard deviation #105

Closed
teobros opened this issue Apr 26, 2023 · 0 comments · Fixed by #116
Closed

Convenience methods for distributions from mean and standard deviation #105

teobros opened this issue Apr 26, 2023 · 0 comments · Fixed by #116
Assignees
Labels
enhancement Improvement of existing code

Comments

@teobros
Copy link

teobros commented Apr 26, 2023

It is more common to have the mean and standard deviation of a random quantity (e.g., obtained from experiments or data sheests) than the parameters of a distribution. Thus, it would be nice to have a function that gets the mean, standard deviation and distribution type and returns the distribution parameters in a tuple.

As a proof of concept, see the functions used to create a Gumbel and a Lognormal distribution.

function distribution_parameters(mean::Real, std::Real, d::Type{Distributions.Gumbel})
	β = std * sqrt(6) / pi
	μ = mean - MathConstants.γ * β
	return μ, β
end

function distribution_parameters(mean::Real, std::Real, d::Type{Distributions.LogNormal})
	μ = log(mean^2/sqrt(std^2+mean^2))
	σ = sqrt(log(std^2/mean^2+1))
	return μ, σ
end

Gumbel(distribution_parameters(50, 5, Gumbel)...)

LogNormal(distribution_parameters(28.8e4-19.9e4,2.64e4, LogNormal)...)
@FriesischScott FriesischScott self-assigned this Apr 26, 2023
@FriesischScott FriesischScott added the enhancement Improvement of existing code label May 25, 2023
@FriesischScott FriesischScott linked a pull request Jun 1, 2023 that will close this issue
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Improvement of existing code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants