GLM weights vs. identical observations I was recently working on a homework assignment on binary GLMs and the following question came up when comparing solutions with a classmate. The data for the problem was given as a contingency table, say





Case
Control




Exposed
1
2


Unexposed
3
4




for a small example. In order to make analysis in R easier, we both decided to turn this into a data frame format. I created the data frame like this:
df1 <- data.frame(
    exposure = c(1, 1, 1, 0, 0, 0, 0, 0, 0, 0),
    outcome = c(1, 0, 0, 1, 1, 1, 0, 0, 0, 0)
)

whereas my classmate did this:
df2 <- data.frame(
  count = c(1, 2, 3, 4),
  exposure = c(1, 1, 0, 0),
  outcome = c(1, 0, 1, 0)
)

So when running models I did something like
glm(outcome ~ exposure, data = df1, family = binomial)
and my classmate did
glm(outcome ~ exposure, data = df2, family = binomial, weights = count)
and I am not sure which of these is correct. Our models produced the same estimates of parameters, standard error, and deviance, with the exception that the residual degrees of freedom for the weighted model was much smaller than the residual degrees of freedom for the unweighted model.
So my overall question is: which of these approaches is correct? Is this the correct way to use weights in a glm? Is there a way to have R account for the repeated observations in the degrees of freedom if weights is wrong?
To share my thoughts: I think that using the weights instructs R what the entries for the $W$ matrix in a weighted regression model should be. My linear algebra is a bit rusty but I think it just so happens that this turns out to produce the same results as having the repeated observations in the $X$ matrix for an unweighted regression. Thus, R performs the weighted regression and gets the same estimates, but only counts degrees of freedom for observations that are actually there. I.e. the "weights" in GLM are just sampling weights, not actual weights that can replace physically observing the same thing multiple times.
 A: There is no difference.  Both are correct (as can be seen by the fact that the outputs are the same).  One treats the data as 10 Bernoulli data and the other treats them as 2 binomial data constituting, collectively, 10 Bernoulli trials.

Update:  The question seems to be about which residual df is correct to use to assess the possibility of overdispersion.
Overdispersion doesn't really apply for Bernoulli data (see: Overdispersion in logistic regression).  It does potentially apply to binomial data that really are binomial.  This was a canned example and it's not clear whether it is more correct to consider these data as Bernoulli or binomial.  Overdispersion also doesn't apply with only one categorical regressor (in this case, Exposed).  Even with a continuous $X$ and binomial data, inferring overdispersion can be ambiguous, it may just be that polynomial or interaction terms are needed (cf., Test logistic regression model using residual deviance and degrees of freedom, and Understanding lack of fit in logistic regression).
