# Beta regression of proportion data including 1 and 0

I am trying to produce a model for which I have a response variable which is a proportion between 0 and 1, this includes quite a few 0s and 1s but also many values in between. I am thinking about attempting a beta regression. The package I have found for R (betareg) only allows values in between 0 and 1 but not including 0 or 1 them selves. I have read elsewhere that theoretically the beta distribution should be able to handle values of 0 or 1 but I do not know how to handle this in R.I have seen some people add 0.001 to the zeros and take 0.001 from the ones, but I am not sure this is a good idea?

Alternatively I could logit transform the response variable and use linear regression. In this case I have the same problem with the 0 and 1's which cannot be log transformed.

• Knowing the counts--not just the proportions--is crucial no matter what you do. But once you have the counts, the first model to consider, even if it's just a point of departure, is logistic regression. – whuber Jan 18 '13 at 22:03
• Well, a beta is between 0 and 1 (almost surely). If you observe them you should use a model that gives a chance to observe your sample. A couple of answers seem to cover that kind of approach; I'd start with them. – Glen_b -Reinstate Monica Jan 22 '13 at 10:49

You could use zero- and/or one inflated beta regression models which combine the beta distribution with a degenerate distribution to assign some probability to 0 and 1 respectively. For details see the following references:

Ospina, R., & Ferrari, S. L. P. (2010). Inflated beta distributions. Statistical Papers, 51(1), 111-126. Ospina, R., & Ferrari, S. L. P. (2012). A general class of zero-or-one inflated beta regression models. Computational Statistics and Data Analysis, 56(6), 1609 - 1623.

These models are easy to implement with the gamlss package for R.

• Do you have an example of how to implement them on R? – Ouistiti May 3 '17 at 20:14
• @Ouistiti the zoib package does it easily. – Mark White Nov 25 '17 at 17:09

The documentation for the R betareg package mentions that

if y also assumes the extremes 0 and 1, a useful transformation in practice is (y * (n−1) + 0.5) / n where n is the sample size.

http://cran.r-project.org/web/packages/betareg/vignettes/betareg.pdf

They give the reference Smithson M, Verkuilen J (2006). "A Better Lemon Squeezer? Maximum-Likelihood Regression with Beta-Distributed Dependent Variables." Psychological Methods, 11 (1), 54–71.

Don't you do a logit transform to make the variable ranging from minus infinity to plus infinity? I am not sure if data having 0 and 1 should be a problem. Is that showing any error message? By the way, if you only have proportions your analysis will always come out wrong. You need to use weight=argument to glm with the number of cases.

If nothing works, you can use a median split or a quartile split or whatever cut point you think appropriate to split out the DV into several categories and then run an Ordinal logistic regression instead. That may work. Try these things.

I don't think personally that adding 0.001 to the zeros and taking 0.001 from the ones is a too bad idea, but it has some problems which will be discussed later. Just think, why don't you add and subtract 0.000000001 (or even more of the decimals)? That will better represent 0 and 1!! It may seem to you that it doesn't make much difference. But it actually does.

Let's see the following:

> #odds when 0 is replaced by 0.00000001

> 0.00000001/(1-0.00000001)
 1e-08
> log(0.00000001/(1-0.00000001))
 -18.42068

> #odds when 1 is replaced by (1-0.00000001):

> (1-0.00000001)/(1-(1-0.00000001))
 1e+08
> log((1-0.00000001)/(1-(1-0.00000001)))
 18.42068

> #odds when 0 is replaced by 0.001

> 0.001/(1-0.001)
 0.001001001
> log(0.001/(1-0.001))
 -6.906755

> #odds when 1 is replaced by (1-0.001):

> (1-0.001)/(1-(1-0.001))
 999
> log((1-0.001)/(1-(1-0.001)))
 6.906755


So, you see, you need to keep the odds as close as (0/1) and (1/0). You expect the log odds ranging from minus infinity to plus infinity. So, to add or subtract, you need to choose up to a really really long decimal place, so that the log odds becomes close to infinity (or very large)!! The extent you will consider large enough, solely depends on you.

Check out the following, where an ad hoc transformation is mentioned maartenbuis.nl/presentations/berlin10.pdf on slide 17. Also you could modeling 0 and 1 with two separate logistic regressions and then use Beta regression for those not at the boundary.

The beta model is for a binary variable that is modeled as Bernoulli-distributed with unknown probability $p$. The beta model calculates a likelihood over $p$, which is beta-distributed.

Your variable is a proportion. You could model the proportion as being beta-distributed with unknown parameters $a, b$. The model you want is the conjugate prior of the beta distribution, which will then calculate a likelihood over $a, b$.

I would have to derive the model again, but if I remember correctly, for proportions $x_1, \dotsc, x_n$ you return three expectation parameters: $n$, the number of points, and if my memory is right $\sum_j[\psi(\sum_i x_i) - \psi(x_j)]$ and $\sum_j[\psi(\sum_i 1-x_i) - \psi(1-x_j)]$. These are the parameters of a distribution over the parameters of your beta distribution, which model your proportions.