# Discrepancy in degrees of freedom from R svyglm vs glm

I fitted a Poisson model using svyglm in R. The null and residual deviances from the svyglm model are as expected. For the degrees of freedom however, I get confusing results. With a sample size of n=4526 and 7 parameters in the model (including the intercept), I expected a null degrees of freedom of 4526-1 = 4525, and a residual degrees of freedom of 4526-7 = 4519. This is exactly what I got with the glm model. The svyglm gives me the expected degrees of freedom for the null (4525) but not the residual. Could someone please explain what is happening here?

For simplicity, I am stripping down the output to the most critical elements:

#OUTPUT FROM SVYGLM. Degrees of Freedom: 4525 Total (i.e. Null); 33 Residual (1138 observations deleted due to missingness) Null Deviance: 1189 Residual Deviance: 770.7 AIC: NA

#OUTPUT FROM GLM. Degrees of Freedom: 4525 Total (i.e. Null); 4519 Residual (9433 observations deleted due to missingness) Null Deviance: 1339 Residual Deviance: 945.7 AIC: 1404

The respective codes used were:

svyglm(rhs, design = svyobject, family=quasipoisson(), rescale= TRUE)
glm(formula = rhs, family = poisson(), data = s)


Where rhs represents the equation ever_ecig ~ relevel(as.factor(current_shisha), ref = "0") + relevel(as.factor(saw_smoking), ref = "0") + relevel(as.factor(current_cigarette), ref = "0") + relevel(as.factor(enjoy), ref = "0") + relevel(as.factor(favor_ban_indoor), ref = "0") + relevel(as.factor(susceptible), ref = "0")

• I don't know the answer, but when I'm investigating issues with things like svyglm, I set the weights to 1, and make each case it's own id. Then the results should be identical. Then I can start changing things back, and this (sometimes) identifies the issue. May 26, 2022 at 20:33

You don't say anything about your survey design. The residual df for a svyglm object is the design df plus one, minus the number of parameters estimated. From the code

    g\$df.residual <- degf(design) + 1 - length(coef(g)[!is.na(coef(g))])


The design df is (number of PSUs minus number of strata) for the subpopulation being analysed, if design information is given.

If replicate weights are given instead, the design df is one less than the column rank of the matrix of replicate weights.

From the help page for svyglm: If df.resid is not specified the df for the null model is computed by degf and the residual df computed by subtraction. This is recommended by Korn and Graubard and is correct for PSU-level covariates but is potentially very conservative for individual-level covariates.

• Many thanks for your detailed response. Greatly appreciated.
– Ter
May 28, 2022 at 11:16