---
title: "Beta Regression: How Closely Did the Brexit Vote Follow Education?"
description: "Beta regression in R, by hand and with betareg, on the share of the Leave vote in the 348 districts of England and Wales (2016) and the census: outcomes between 0 and 1, the mean and precision of the beta distribution, odds ratios and marginal effects, a precision that varies, comparison with least squares, logit-transformed shares and quasi-binomial models, residuals, prediction intervals, the ecological fallacy, neighboring districts and APA reporting."
author: ""
---
```{r options, echo=FALSE, warning=FALSE, message=FALSE}
directory<-if (rstudioapi::isAvailable()) paste0(dirname(rstudioapi::getActiveDocumentContext()$path),"/") else ""
source(paste0(directory, "R/code_options.R"))
# no knitr cache: the page downloads its data each time it runs (in a few seconds),
# and a cached chunk would quietly keep an old download
knitr::opts_chunk$set(fig.height = 4.5, cache = FALSE)
```
## The question: a share as the outcome
In June 2016 the United Kingdom voted to leave the European Union, with 52% for Leave. But the country was divided. In some districts three quarters voted Leave, in others one fifth. What kind of districts were they? Education is the best-known answer: the more people with a degree, the fewer votes for Leave. How close is the relation, and what is left for age and for the share of people born abroad?
The outcome is a **share**, a number between 0 and 1. Ordinary regression has three problems with it. Its straight line leaves the range from 0 to 1 sooner or later. Its errors are supposed to have the same spread everywhere, but shares near 0 or 1 have no room to vary. And near the limits the distribution is skewed.
**Beta regression** (Ferrari & Cribari-Neto, 2004) is the regression for shares, rates and proportions that are **not** counts of yes and no: the share of income spent on food, the share of a leaf that is ill, a test score as a fraction of the maximum, an election result.
```{r packages}
library(betareg) # betareg()
library(ggplot2)
library(sandwich) # vcovCL(): standard errors for districts of the same region
# number formats for the text
f1 <- function(x) formatC(x, format = "f", digits = 1, big.mark = ",")
f2 <- function(x) formatC(x, format = "f", digits = 2, big.mark = ",")
f3 <- function(x) formatC(x, format = "f", digits = 3, big.mark = ",")
# no leading zero
nz <- function(x, d = 2) sub("^(-?)0", "\\1", formatC(x, format = "f", digits = d))
pval <- function(p) if (p < .001) "< .001" else paste("=", nz(p, 3))
num <- function(x) trimws(format(x, big.mark = ","))
pct <- function(x, d = 1) paste0(formatC(100 * x, format = "f", digits = d), "%")
```
---
## 1. The data
The Electoral Commission publishes the result of every district. The 2011 census, through the service *Nomis* of the Office for National Statistics, has their people. Both are free and need no login:
```{r download}
votes <- read.csv(
"https://www.electoralcommission.org.uk/sites/default/files/2019-07/EU-referendum-result-data.csv"
)
census <- function(table, cells) {
# percentage of the residents, by district
d <- read.csv(paste0(
"https://www.nomisweb.co.uk/api/v01/dataset/",
table,
".data.csv?date=latest&geography=TYPE464",
"&rural_urban=0&cell=",
cells,
"&measures=20301&select=geography_code,cell,obs_value"
))
aggregate(OBS_VALUE ~ GEOGRAPHY_CODE, data = d, FUN = sum)
}
degree <- census("NM_623_1", "6") # highest qualification: level 4 or more (degree), % of 16+
old <- census("NM_145_1", "13,14,15,16") # aged 65 and over
uk <- census("NM_611_1", "100") # born in the United Kingdom
brexit <- merge(
votes[, c("Area_Code", "Area", "Region", "Leave", "Valid_Votes")],
degree,
by.x = "Area_Code",
by.y = "GEOGRAPHY_CODE"
)
names(brexit)[6] <- "degree"
brexit$age65 <- old$OBS_VALUE[match(brexit$Area_Code, old$GEOGRAPHY_CODE)]
brexit$abroad <- 100 - uk$OBS_VALUE[match(brexit$Area_Code, uk$GEOGRAPHY_CODE)]
brexit$leave <- brexit$Leave / brexit$Valid_Votes
nrow(brexit)
round(
sapply(brexit[, c("leave", "degree", "age65", "abroad")], function(v) {
c(min = min(v), mean = mean(v), max = max(v))
}),
2
)
```
There are `r nrow(brexit)` districts of England and Wales (Scotland and Northern Ireland have other censuses). `leave` is the share of the valid votes for Leave. `degree`, `age65` and `abroad` are percentages: people with a degree or similar, people of 65 and over, and people born outside the United Kingdom.
---
## 2. Look at the data
```{r look}
ggplot(brexit, aes(degree, leave)) +
geom_point(aes(colour = Region == "London"), alpha = 0.7, size = 2) +
geom_smooth(method = "loess", formula = y ~ x, se = FALSE, colour = "grey30", linewidth = 0.8) +
scale_colour_manual(
values = c(`TRUE` = "#eb6834", `FALSE` = "#2a78d6"),
labels = c("other districts", "London"),
name = NULL
) +
scale_y_continuous(labels = function(v) paste0(100 * v, "%")) +
labs(
title = "Leave vote and education in 348 districts",
x = "adults with a degree (%)",
y = "vote for Leave"
) +
theme_bw() +
theme(legend.position = "bottom")
cor(brexit$leave, brexit$degree)
brexit[order(brexit$leave)[c(1:3, 346:348)], c("Area", "leave", "degree", "age65", "abroad")]
```
The relation is one of the strongest in social statistics, *r* = `r nz(cor(brexit$leave, brexit$degree))`. It is nearly straight. The shares are mostly between 30% and 70%, so the limits 0 and 1 are far away, and we expect a straight line to do well, too. We shall see how much the beta regression adds.
---
## 3. The model step by step, with formulas
### Step 1: the beta distribution
A beta variable lies between 0 and 1. Written with its mean $\mu$ and a **precision** $\phi$:
$$E(y) = \mu, \qquad \text{Var}(y) = \frac{\mu(1 - \mu)}{1 + \phi}$$
The variance is largest in the middle, and goes to zero at 0 and 1. The larger $\phi$, the less the values scatter around the mean.
```{r shapes}
grid <- seq(0.002, 0.998, by = 0.002)
shapes <- do.call(
rbind,
lapply(c(0.1, 0.5, 0.85), function(mu) {
do.call(
rbind,
lapply(c(5, 20, 80), function(phi) {
data.frame(
y = grid,
d = dbeta(grid, mu * phi, (1 - mu) * phi),
mean = paste("mean", mu),
precision = paste0("φ = ", phi)
)
})
)
})
)
shapes$precision <- factor(shapes$precision, levels = paste0("φ = ", c(5, 20, 80)))
ggplot(shapes, aes(y, d, colour = precision)) +
geom_line(linewidth = 0.9) +
facet_wrap(~mean) +
coord_cartesian(ylim = c(0, 12)) +
scale_colour_manual(values = c("#eda100", "#2a78d6", "#1baf7a"), name = NULL) +
labs(title = "Beta distributions", x = "y", y = "density") +
theme_bw() +
theme(legend.position = "bottom")
```
### Step 2: the mean depends on predictors, through a link
As in logistic regression, the logit keeps the mean between 0 and 1:
$$\log\frac{\mu_i}{1 - \mu_i} = x_i^\top\beta$$
$e^{\beta}$ is an **odds ratio** for the mean share. The word "odds" is used as for probabilities: a share of 60% has odds of 60/40 = 1.5.
### Step 3: the precision may depend on predictors, too
$$\log \phi_i = z_i^\top\gamma$$
The simplest model has one $\phi$ for all. Modeling it lets some districts scatter more than others.
### Step 4: maximum likelihood, by hand
The density is $\frac{\Gamma(\phi)}{\Gamma(\mu\phi)\,\Gamma((1-\mu)\phi)}\, y^{\mu\phi - 1}(1 - y)^{(1-\mu)\phi - 1}$, which R knows as `dbeta(y, mu * phi, (1 - mu) * phi)`:
```{r by_hand}
brexit$deg10 <- (brexit$degree - 27) / 10
brexit$old10 <- (brexit$age65 - 17) / 10
brexit$abr10 <- (brexit$abroad - 10) / 10 # per 10 points
X <- model.matrix(~ deg10 + old10 + abr10, data = brexit); y <- brexit$leave
minus_loglik <- function(par) {
mu <- plogis(drop(X %*% par[1:4])); phi <- exp(par[5])
-sum(dbeta(y, mu * phi, (1 - mu) * phi, log = TRUE))
}
hand <- optim(
c(0, 0, 0, 0, 4),
minus_loglik,
method = "BFGS",
control = list(reltol = 1e-14, maxit = 1000)
)
fit <- betareg(leave ~ deg10 + old10 + abr10, data = brexit)
rbind(by_hand = c(hand$par[1:4], exp(hand$par[5])), betareg = coef(fit))
```
---
## 4. Fitting the model and reading the output
```{r fit}
summary(fit)
b <- coef(fit)[1:4]; se <- sqrt(diag(vcov(fit)))[1:4]; or <- exp(b); ci <- exp(confint(fit)[1:4, ])
phi <- coef(fit)[["(phi)"]]
```
We centered the predictors near their means and counted them in steps of 10 percentage points.
- **`(Intercept)`**: the district with average predictors has a logit of `r f2(b[[1]])`, a Leave share of `r pct(plogis(b[[1]]))`.
- **`deg10`**: 10 points more people with a degree multiply the **odds** of Leave by `r f2(or[["deg10"]])`, 95% CI [`r f2(ci["deg10", 1])`, `r f2(ci["deg10", 2])`].
- **`old10`**: 10 points more people of 65 and over, by `r f2(or[["old10"]])`, [`r f2(ci["old10", 1])`, `r f2(ci["old10", 2])`].
- **`abr10`**: 10 points more people born abroad, by `r f2(or[["abr10"]])`, [`r f2(ci["abr10", 1])`, `r f2(ci["abr10", 2])`].
- **`(phi)`** = `r f1(phi)`: the precision. At a mean of 50% the SD of a district around its mean is $\sqrt{0.25/(1 + `r f1(phi)`)}$ = `r pct(sqrt(0.25 / (1 + phi)))`.
- **`Pseudo R-squared`** is the squared correlation of the linear predictor and the logit of the outcome, `r nz(fit$pseudo.r.squared)`.
### In percentage points
Odds of a share are hard to picture. The **average marginal effect** is the mean change of the share itself, $\beta\,\mu(1 - \mu)$ averaged over the districts:
```{r marginal}
mu <- fitted(fit)
ame <- b[-1] * mean(mu * (1 - mu))
set.seed(91)
draws <- MASS::mvrnorm(2000, coef(fit)[1:4], vcov(fit)[1:4, 1:4]) # uncertainty by simulation
sim <- apply(draws, 1, function(bb) { m <- plogis(drop(X %*% bb)); bb[-1] * mean(m * (1 - m)) })
ame_ci <- apply(sim, 1, quantile, c(0.025, 0.975))
round(100 * rbind(ame, ame_ci), 1)
```
Ten points more graduates go with a Leave share that is **`r f1(100 * abs(ame[["deg10"]]))` points lower**, 95% CI [`r f1(100 * abs(ame_ci[2, "deg10"]))`, `r f1(100 * abs(ame_ci[1, "deg10"]))`], in districts with the same age structure and the same share of people born abroad.
---
## 5. Does the scatter change? A model for the precision
```{r precision}
# after the bar: the precision
fit_phi <- betareg(leave ~ deg10 + old10 + abr10 | deg10 + abr10, data = brexit)
round(summary(fit_phi)$coefficients$precision, 3)
lr <- 2 * (as.numeric(logLik(fit_phi)) - as.numeric(logLik(fit)))
c(
LR = lr,
df = 2,
p = pchisq(lr, 2, lower.tail = FALSE),
AIC_constant = AIC(fit),
AIC_varying = AIC(fit_phi)
)
g <- coef(fit_phi, model = "precision")
sd_at <- function(abr) sqrt(0.25 / (1 + exp(g[[1]] + g[[3]] * (abr - 10) / 10)))
c(SD_at_5pct_abroad = sd_at(5), SD_at_40pct_abroad = sd_at(40))
```
The districts do not all scatter equally: the likelihood-ratio test of a varying precision gives $\chi^2$(2) = `r f1(lr)`, *p* `r pval(pchisq(lr, 2, lower.tail = FALSE))`. Around the same mean of 50%, districts with 5% born abroad have an SD of `r pct(sd_at(5))`, those with 40%, `r pct(sd_at(40))`. Diverse districts are less predictable. The coefficients of the **mean** and their standard errors change little:
```{r mean_compare}
round(
cbind(
constant = coef(fit)[1:4],
SE = se,
varying = coef(fit_phi, model = "mean"),
SE_varying = sqrt(diag(vcov(fit_phi)))[1:4]
),
3
)
```
---
## 6. Against the alternatives
```{r alternatives}
ols <- lm(leave ~ deg10 + old10 + abr10, data = brexit)
logit <- lm(qlogis(leave) ~ deg10 + old10 + abr10, data = brexit)
binom <- glm(
cbind(Leave, Valid_Votes - Leave) ~ deg10 + old10 + abr10,
family = binomial,
data = brexit
)
quasi <- glm(
cbind(Leave, Valid_Votes - Leave) ~ deg10 + old10 + abr10,
family = quasibinomial,
data = brexit
)
effects <- rbind(`beta regression` = c(coef(fit)["deg10"], sqrt(vcov(fit)["deg10", "deg10"])),
`OLS on the logit` = coef(summary(logit))["deg10", 1:2],
`binomial (wrong)` = coef(summary(binom))["deg10", 1:2],
`quasi-binomial` = coef(summary(quasi))["deg10", 1:2])
colnames(effects) <- c("b (logit scale)", "SE")
round(effects, 4)
c(OLS_effect_in_points = 100 * coef(ols)[["deg10"]], beta_effect_in_points = 100 * ame[["deg10"]])
dispersion <- summary(quasi)$dispersion
dispersion
```
- **OLS** on the share gives `r f1(100 * coef(ols)[["deg10"]])` points for 10 points of degrees, and the beta regression `r f1(100 * ame[["deg10"]])` on average. Between 30% and 70% a logit is almost straight, so the two agree. With shares near 0 or 1 they would not.
- **OLS on the logit** of the share agrees with the beta regression here. It describes the mean of the logit, not the logit of the mean, and to come back to shares it needs a correction, like the smearing of [gamma regression](EXAMPLE_GAMMA.Rmd).
- **Binomial regression** treats every **voter** as an independent observation. With millions of votes its standard error is `r f1(effects[1, 2] / effects[3, 2])` times smaller than that of the beta regression, and it is nonsense: the dispersion is `r num(round(dispersion))` instead of 1. Voters of one district share their district.
- **Quasi-binomial** corrects the standard errors by this factor, and gives the larger districts more weight. It is a good alternative when the numerator and the denominator are known. Its variance, $\mu(1-\mu)\phi/n$, shrinks with the number of voters, while the beta regression gives every district the same precision.
Which is right? The chance variation of `r num(round(mean(brexit$Valid_Votes)))` votes is tiny. What makes districts differ is everything that the model does not contain. That does not shrink with the size, which speaks for the beta regression.
---
## 7. Checking the model
```{r residuals, fig.height = 6}
res <- data.frame(
fitted = fitted(fit_phi),
r = residuals(fit_phi, type = "quantile"),
Region = brexit$Region,
Area = brexit$Area
)
res$q <- qqnorm(res$r, plot.it = FALSE)$x
pa <- ggplot(res, aes(fitted, r)) +
geom_hline(yintercept = 0, colour = "grey60") +
geom_point(alpha = 0.5, colour = "grey30") +
geom_smooth(method = "loess", formula = y ~ x, se = FALSE, colour = "#eb6834") +
labs(title = "Quantile residuals against the fitted share", x = "fitted share", y = "residual") +
theme_bw()
pb <- ggplot(res, aes(reorder(Region, r, median), r)) +
geom_hline(yintercept = 0, colour = "grey60") +
geom_boxplot(fill = "grey90") +
coord_flip() +
labs(title = "The same, by region", x = NULL, y = "residual") +
theme_bw()
patchwork::wrap_plots(pa, pb, ncol = 1)
shapiro.test(res$r)$p.value
res[order(-abs(res$r))[1:5], c("Area", "Region", "fitted", "r")]
```
Quantile residuals are standard normal if the model is right. They are not quite (the Shapiro–Wilk test rejects it): a few districts voted far less for Leave than their people suggest. Three of the five largest residuals are Liverpool and two of its neighbors. And the residuals are **grouped by region**: the districts of some regions lie above the model together, those of others below. The districts are not independent. Neighbors resemble each other for reasons that are not in the model.
```{r regions}
fit_reg <- betareg(leave ~ deg10 + old10 + abr10 + Region, data = brexit)
lr_reg <- 2 * (as.numeric(logLik(fit_reg)) - as.numeric(logLik(fit)))
df_reg <- length(unique(brexit$Region)) - 1
V_cl <- vcovCL(fit, cluster = brexit$Region)
rbind(without_regions = coef(fit)[2:4], with_regions = coef(fit_reg)[2:4])
rbind(SE_usual = se[2:4], SE_clustered_by_region = sqrt(diag(V_cl))[2:4])
c(
LR_regions = lr_reg,
df = df_reg,
p = pchisq(lr_reg, df_reg, lower.tail = FALSE),
R2_without = fit$pseudo.r.squared,
R2_with = fit_reg$pseudo.r.squared
)
```
Adding the regions improves the fit a lot, $\chi^2$(`r df_reg`) = `r f1(lr_reg)`, and changes the coefficients: that of the share born abroad goes from `r f2(coef(fit)[["abr10"]])` to `r f2(coef(fit_reg)[["abr10"]])`, because most districts with many people born abroad are in London. The standard errors that allow for correlation within regions are `r f1(sqrt(diag(V_cl))[["deg10"]] / se[["deg10"]])` times as large for education. (With only `r df_reg + 1` regions they are rough themselves. A spatial model is the proper tool.)
---
## 8. Predictions
```{r predictions}
grid <- data.frame(deg10 = (seq(14, 68, by = 1) - 27) / 10, old10 = 0, abr10 = 0)
grid$degree <- grid$deg10 * 10 + 27
grid$mean <- predict(fit_phi, grid, type = "response")
grid$low <- predict(fit_phi, grid, type = "quantile", at = 0.05)
grid$high <- predict(fit_phi, grid, type = "quantile", at = 0.95)
ggplot(grid, aes(degree, mean)) +
geom_ribbon(aes(ymin = low, ymax = high), fill = "#2a78d6", alpha = 0.2) +
geom_line(colour = "#2a78d6", linewidth = 1) +
geom_point(data = brexit, aes(degree, leave), alpha = 0.3, size = 1.3) +
scale_y_continuous(labels = function(v) paste0(100 * v, "%"), limits = c(0, 1)) +
labs(
title = "Fitted mean and 90% range for a district with average age and few people born abroad",
x = "adults with a degree (%)",
y = "vote for Leave"
) +
theme_bw() +
theme(plot.title = element_text(size = 11))
at <- function(d) {
v <- round(
100 *
c(
predict(fit_phi, data.frame(deg10 = (d - 27) / 10, old10 = 0, abr10 = 0)),
sapply(c(0.05, 0.95), function(q) {
predict(
fit_phi,
data.frame(deg10 = (d - 27) / 10, old10 = 0, abr10 = 0),
type = "quantile",
at = q
)
})
),
1
)
setNames(v, c("mean", "5%", "95%"))
}
rbind(`20% with a degree` = at(20), `40% with a degree` = at(40))
```
The fitted distribution gives ranges directly, and they never leave the interval from 0 to 1. With 20% graduates, nine in ten such districts are expected between `r f1(at(20)[2])`% and `r f1(at(20)[3])`% for Leave; with 40%, between `r f1(at(40)[2])`% and `r f1(at(40)[3])`%.
---
## 9. Things to keep in mind
- **The ecological fallacy.** The rows are districts, not people. That districts with more graduates voted less for Leave does not prove that graduates did. (Surveys of voters show that they did, but this page cannot.) Robinson (1950) is the classic warning.
- **Exactly 0 or 1** has no place in a beta distribution. A common fix is $(y(n - 1) + 0.5)/n$ (Smithson & Verkuilen, 2006); better is a model with extra parts for the zeros and ones (zero-or-one-inflated beta), or the extended-support versions in recent versions of `betareg`.
- **Is it a share of a whole that was counted?** With successes out of a small known number of trials, use binomial or beta-binomial regression. The beta regression is for shares without a meaningful number of trials, or with a number so large that it does not matter.
- **Several shares that add up to 1** (votes for five parties) need Dirichlet regression, or log-ratios.
- **Scales.** Scores of a questionnaire divided by their range are a frequent use (Smithson & Verkuilen, 2006). Remember that the units are then "share of the range".
- **Links.** The logit is the default. Others can be compared by AIC: `link = "loglog"` etc.
- **The precision is part of the model.** A wrong model for it makes the standard errors wrong. Use sandwich errors (`vcov = sandwich`) if in doubt.
---
## 10. Reporting the results in APA style
A report (APA 7th edition) needs the outcome and its range, the links of the mean and of the precision, odds ratios or effects in points with intervals, the precision, and the unit of analysis. The numbers come from the R objects:
```{r apa_numbers}
sm <- summary(fit_phi)$coefficients$mean; cim <- confint(fit_phi)
ame2 <- sm[-1, 1] * mean(fitted(fit_phi) * (1 - fitted(fit_phi)))
apa_table <- data.frame(
Predictor = c(
"Intercept", "Degree (10 points)", "Aged 65+ (10 points)", "Born abroad (10 points)"
),
b = f3(sm[, 1]),
SE = f3(sm[, 2]),
z = f2(sm[, 3]),
p = sapply(sm[, 4], function(p) sub("^= ", "", pval(p))),
OR = paste0(f2(exp(sm[, 1])), " [", f2(exp(cim[1:4, 1])), ", ", f2(exp(cim[1:4, 2])), "]"),
ame = c("—", f1(100 * ame2))
)
```
**Method** (data analysis):
> The share of valid votes for Leave in the 2016 referendum in the `r nrow(brexit)` districts of England and Wales (Electoral Commission, 2019) was analyzed with beta regression (Ferrari & Cribari-Neto, 2004), with a logit link for the mean and a log link for the precision. Predictors of the mean were the percentages of residents with a degree-level qualification, aged 65 and over, and born outside the United Kingdom (2011 census; Office for National Statistics, 2013), centered and in units of 10 percentage points; the precision depended on the first and the third. Models were compared with likelihood-ratio tests. Analyses were conducted in R (Version `r paste(R.version$major, R.version$minor, sep = ".")`; R Core Team, `r R.version$year`) with the package betareg (Cribari-Neto & Zeileis, 2010).
**Results:**
> The share of Leave votes ranged from `r pct(min(brexit$leave))` to `r pct(max(brexit$leave))` (*M* = `r pct(mean(brexit$leave))`). Districts with more graduates voted less for Leave, *OR* = `r f2(exp(sm["deg10", 1]))` per 10 points, 95% CI [`r f2(exp(cim["deg10", 1]))`, `r f2(exp(cim["deg10", 2]))`], *p* `r pval(sm["deg10", 4])`, on average `r f1(100 * abs(ame2[["deg10"]]))` percentage points (Table 1). The scatter around the mean differed between districts, χ²(2) = `r f1(lr)`, *p* `r pval(pchisq(lr, 2, lower.tail = FALSE))`. Adding the regions improved the model, χ²(`r df_reg`) = `r f1(lr_reg)`, *p* `r pval(pchisq(lr_reg, df_reg, lower.tail = FALSE))`, so the districts are not independent and the standard errors are too small. The results concern districts and not individual voters.
**Table 1**
*Beta Regression of the Share of Leave Votes*
```{r apa_table, echo=FALSE}
knitr::kable(apa_table, col.names = c("Predictor", "*b*", "*SE*", "*z*", "*p*", "Odds ratio [95% CI]", "Average effect (points)"), align = "lrrrrrr", format = "pipe", row.names = FALSE)
```
*Note.* *N* = `r nrow(brexit)` districts. Logit link. Precision modeled with the shares of graduates and of people born abroad. Average effect: mean change of the share for 10 points more of the predictor.
**Points to remember:**
- Say what the share is a share of, and what one row is.
- Report both links, and the model for the precision.
- Translate odds ratios into percentage points.
- Say what you did with zeros and ones.
---
## 11. Summary
| | |
|---|---|
| **When** | The outcome is a continuous share between 0 and 1 (not 0 or 1 exactly) |
| **The model** | $y \sim \text{Beta}$ with mean $\mu$ and precision $\phi$; $\text{logit}(\mu) = x^\top\beta$ |
| **Variance** | $\mu(1 - \mu)/(1 + \phi)$ |
| **How (R)** | `betareg(y ~ x1 + x2 | z, data)`: after the bar, the precision |
| **Reading it** | $e^\beta$: odds ratio of the mean share; better, average marginal effects |
| **Alternatives** | OLS (shares in the middle), quasi-binomial (counts known), zero-or-one-inflated beta |
| **Checks** | Quantile residuals, precision, groups of rows |
| **Related pages** | [Generalized linear models](EXAMPLE_GENERALIZED.rmd), [gamma regression](EXAMPLE_GAMMA.Rmd), [probit](EXAMPLE_PROBIT.Rmd) |
---
## References
Cribari-Neto, F., & Zeileis, A. (2010). Beta regression in R. *Journal of Statistical Software*, *34*(2), 1–24. https://doi.org/10.18637/jss.v034.i02
Electoral Commission. (2019). *Results and turnout at the EU referendum* [Data set]. https://www.electoralcommission.org.uk/research-reports-and-data/our-reports-and-data-past-elections-and-referendums/results-and-turnout-eu-referendum
Ferrari, S., & Cribari-Neto, F. (2004). Beta regression for modelling rates and proportions. *Journal of Applied Statistics*, *31*(7), 799–815. https://doi.org/10.1080/0266476042000214501
Office for National Statistics. (2013). *2011 census: Key statistics for local authorities in England and Wales* [Data set]. Nomis. https://www.nomisweb.co.uk/census/2011
Robinson, W. S. (1950). Ecological correlations and the behavior of individuals. *American Sociological Review*, *15*(3), 351–357. https://doi.org/10.2307/2087176
Smithson, M., & Verkuilen, J. (2006). A better lemon squeezer? Maximum-likelihood regression with beta-distributed dependent variables. *Psychological Methods*, *11*(1), 54–71. https://doi.org/10.1037/1082-989X.11.1.54