4
$\begingroup$

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.

$\endgroup$
1

1 Answer 1

2
$\begingroup$

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

$\endgroup$
11
  • $\begingroup$ They objectively compute different degrees of freedom. Is this just a quirk of R not taking the weights into account for df calculation? $\endgroup$
    – wzbillings
    Apr 10, 2021 at 15:53
  • 1
    $\begingroup$ @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. $\endgroup$ Apr 13, 2021 at 0:57
  • 1
    $\begingroup$ 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? $\endgroup$
    – wzbillings
    Apr 14, 2021 at 16:54
  • 1
    $\begingroup$ @wz-billings, I see. I didn't understand that's what your question was. 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 & it's not clear that it is more correct to consider these data as Bernoulli or binomial. $\endgroup$ Apr 14, 2021 at 17:53
  • 1
    $\begingroup$ Overdispersion also doesn't apply w/ only 1 categorical regressor (exposed), even w/ a continuous X & 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 & Understanding lack of fit in logistic regression). $\endgroup$ Apr 14, 2021 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.