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

Incorrect variance for Beta distribution? #1

Open
timueh opened this issue Mar 12, 2019 · 4 comments
Open

Incorrect variance for Beta distribution? #1

timueh opened this issue Mar 12, 2019 · 4 comments

Comments

@timueh
Copy link

timueh commented Mar 12, 2019

Hey there,

I drew samples for the beta distribution and noticed that the variance is off. It seems to be a structural issue. Any ideas?

a = 2; b = 2;
X = sample(@(x) (x.^(a-1).*(1-x).^(b-1) / beta(a,b)), [0 1], 100000);
mean(X), var(X) % = 0.5005, 0.0201

The analytical values for the mean and variance are

mu = a / (a + b) % 0.5
var = a*b/( (a+b)^2*(a+b+1) ) % 0.05

thanks!

@timueh
Copy link
Author

timueh commented Mar 12, 2019

Interesting: If I use ApproxFun.sample in Julia, it works. So there is some bug in the Matlab implementation I suppose?

julia> using SpecialFunctions, ApproxFun

julia> α, β = 2., 2.
(2.0, 2.0)

julia> f = Fun(t->t^-1)*(1-t)^-1)/beta(α,β), 0..1)
Fun(Chebyshev(0..1),[0.75, 6.08434e-17, -0.75])

julia> s = ApproxFun.sample(f,10000);

julia> mean(s), var(s)
(0.4985766951022462, 0.050219874600315156)

Is there a standalone Julia implementation of your inverse CDF sampling that does not depend on types from ApproxFun such as Fun or Chebyshev?

@dlfivefifty
Copy link
Owner

Is there a standalone Julia implementation

No. @ajt60gaibb will have to jump in here as I don't have a working version of Matlab.

@timueh
Copy link
Author

timueh commented Mar 15, 2019

Any idea @ajt60gaibb?

@timueh
Copy link
Author

timueh commented Apr 4, 2019

I'm sorry to bother you again, but is there any advice you can give @ajt60gaibb?

Thanks :)

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

2 participants