# Binomial regression in R: lm() with logit, vs glm() with family=binomial

I am currently learning about GLMs. Suppose my predictor variable generates a number of "successes" and "failures" as the response variable. Naturally I want to model the probability of success as a binomial model.

x <- 1:5
y_s <- c(9,6,2,4,1)
y_f <- 10-y_s


A generalised linear model fits a linear regression to the logit link function ie.$$\ln\left(\frac{p}{1-p}\right)=\mathbf{X\beta}$$ Using the lm function in R gives

logit <- function(p) {return(log(p/(1-p)))}
mod_lm <- lm( logit(y_s/(y_s+y_f)) ~ x)
mod_lm$coefficients # 1.4058816 -0.6291569  But using glm with family=binomial gives mod_glm <- glm( cbind(y_s, y_f) ~ x, family=binomial(link="logit")) mod_glm$coefficients
# 1.2626202  -0.5726736


I can't seem to understand why these numbers are not the same. There's been several other questions on this site that are somewhat similar (eg. here) but they're not quite the same. Am I missing something regarding how GLM works in R? Perhaps I am not understanding exactly what the GLM family is.

These are different modeling strategies. Agresti called your first model with log transformation "the transformed-data approach" (Agresti 2015). Let's call the log function, $$g$$, which could be the link function in GLM or transformation function in transformed-data approach. In the first case (GLM), you model $$g[E(y_i)]$$, whereas in the second, you model $$E[g(y_i)]$$. According to Agresti (2015, 6), "with the GLM approach, [model] parameters ... describe effects of explanatory variables on $$E(y_i)$$, after applying the inverse function for $$g$$." However, in the data-transformation approach, this is not the case and "the model does not translate to exact information about $$E(y_i)$$ or the effect of [predictor] $$x_{i1}$$ on $$E(y_i)$$." That's why you have different results.