# Regression when the dependent variable is between 0 and 1

I am using the scikit-learn library to perform regression. However in my case I need the dependent variable to be constrained in the range 0 to 1. The dependent variable represents count proportions (counts in some category divided by a total count) and is there not continuous. I can see two ways to achieve this.

1. Transform the dependent variable to the full real number line and perform normal regression.
2. Transform the regression problem into a categorical one by selecting n classes each representing the range (i/n) to (i+1/n).

My guess is that the first option wouldn't work well in practice and the second looks like an ugly kludge (which might work).

What is a good way to constrain the dependent variable in regression (in Python)?

Regression for an outcome (ratio or fraction) between 0 and 1 suggested using Beta regression but I don't fully understand this option. Could anyone set out what Beta regression is in technical detail for those who don't use R?

• Possible duplicate of Regression for an outcome (ratio) between 0 and 1
– Tim
Oct 10 '16 at 10:26
• @Tim Thanks. I added something to the question as I don't understand the accepted answer. Oct 10 '16 at 10:29
• Are your outcomes count proportions (counts in some category divided by a total count) or continuous proportions? Oct 10 '16 at 10:31
• @Glen_b They are count proportions. Oct 10 '16 at 10:31
• I know. But note that if you were to write a question "How to specify proportion as a DV in scikit-learn?" it would be closed as off-topic... Oct 10 '16 at 11:08

Beta regressions are used for continuous proportions (like the proportion of land with a particular soil type).

For count proportions, the most common models would be binomial regression models, a particular type of generalized linear model (GLM).

Of those, logistic regression is the most widely used though there's a number of other link functions that are used.

The estimated fit is automatically constrained to lie within the bounds.

It doesn't transform the response; it relies on fitting a function that stays inside the limits.

[Numerous questions on site discuss logistic regression. A few discuss other models - probit regression and complementary log-log regression, for example]

• Thank. Please excuse the naive question but it looks like scikit-learn.org/stable/modules/… expects the dependent variable to be either 0 or 1, not a real number in the range 0 to 1. See e.g. "Logistic regression, despite its name, is a linear model for classification rather than regression." Oct 10 '16 at 10:43
• I think it is worth mentioning (as I did here) that in fact count proportion plus sample size is just another way of storing the same data about number of successes and number of failures, i.e. this is a standard logistic regression problem.
– Tim
Oct 10 '16 at 10:44
• @Lembik logistic regression is not a classifier (see here) and it is possible to use it with proportions data -- but I'm not sure is scikit-learn is able to do so, from what you are saying, I guess it's not.
– Tim
Oct 10 '16 at 10:48
• @Lembik If your software does not allow proportions as DVs then you can hack it by replicating the rows of your data table: e.g. if you have a row with 7/10 proportion, make it 7 rows with outcome 1 and 3 rows with outcome 0. Then run logistic regression. Oct 10 '16 at 10:57
• Some programs (R included) will allow you to specify proportions at each combination of predictors, but as amoeba says you can simply "unpack" your data back to 1s and 0s if you know the successes and the total count (i.e. the numerator and the denominator of your proportion). Oct 10 '16 at 11:47