# Estimating the parameters of a beta distribution with zeroes and ones in the sample

I have a list of values in [0,1] that I want to fit to a Beta distribution in order to get the corresponding alpha parameter.

I can't use a beta fitting function because my values might be 0's and 1's.

On wikipedia I found this formula for the method-of-moments estimation of alpha given the sample mean and sample variance:

I don't need any exact fitting, just a good approximation. By using sample mean and variance, I should get rid of all the problems arising with 0s and 1s in my sample, right? Will this still be acceptable?

-
If there are $0$s and $1$s in your sample, then there is evidence against a Beta distribution because this is a continuous distribution. Do you know how are they generated? Are they observed due to rounding for example? – user10525 Jul 23 '12 at 12:05
@Procrastinator: in R, see what happens with zapsmall(rbeta(50, shape1=1/1000, shape2=1/1000))! (This both affirms your point and shows one way in which such data can arise with a "continuous" distribution.) – whuber Jul 23 '12 at 12:32
The output is:  [1] 1.0000000 1.0000000 1.0000000 1.0000000 0.0000000 0.0000000 0.0000000 [8] 0.4790424 1.0000000 1.0000000 0.0000000 0.0000000 0.0000000 1.0000000 [15] 1.0000000 0.0000000 1.0000000 1.0000000 0.0000000 0.0000000 0.0000000 [22] 1.0000000 1.0000000 0.0000000 0.0000000 0.0000000 1.0000000 0.0000000 [29] 1.0000000 1.0000000 0.0000000 1.0000000 1.0000000 1.0000000 1.0000000 [36] 0.0000000 1.0000000 0.0000000 1.0000000 0.0000033 0.0000000 1.0000000 [43] 0.0000000 1.0000000 1.0000000 1.0000000 0.0000000 0.0000000 1.0000000 [50] 0.0000000 Could you explain to me why I get 1.0s? – Ricky Robinson Jul 23 '12 at 13:01
@RickyRobinson It would be better to use the original measurements directly (if they are available) instead of bining them, otherwise the sample is discrete and it would be better to fit a discrete distribution (for example a discretised beta). – user10525 Jul 23 '12 at 13:35
I agree with all of Procrastinator's suggestions and the nice suggestion raised by whuber. We know now that the 0s and 1s don't come by rounding. But how do they arise? That is the fundamental question. If 0 and 1 are the only points that repeat and the data is otherwise discrete. Maybe you can fit a mixture of a discrete distribution concentrated on 0 and 1 with a beta via constrained maximum likelihood. But understanding the data better would help. We can't explain the 0s and 1s for you because we know hardly anything about your data. – Michael Chernick Jul 23 '12 at 14:16