# 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.

• Apr 8 at 3:13

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).
• @wc-billings, have you tried running the models? Both give the same Null deviance: 13.46; both give the same Residual deviance: 13.38. The dfs, when treated as Bernoulli, are 9 & 8; when treated as binomial, are 3 & 2. Thus, the chi-squared tests are the same (difference b/t deviances .08, assessed against the chi-squared distribution on the difference b/t dfs 1, yields the same p-value: .78). The p-values for both variables are also the same. Apr 13 at 0:57
• Yes, I have tried running the models--I said that I understand when I compare two models (e.g. null model with current model), the df doesn't matter. But I am confused about how to interpret the distribution of the deviance on its own--the deviance should be $\chi^2_{n-p}$ and we can use this as a hypothesis test to determine where there is overdispersion in the model. Sorry if I did not make this clear in my previous comment, but I am not sure which interpretation of the deviance is correct. Does overdispersion really depend on how the trials are conceptualized? Apr 14 at 16:54