1library(survey) 2 3data(api) 4 5## one-stage cluster sample 6dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) 7 8# svyglm model 9mod <- svyglm(api99 ~ enroll + api.stu, design = dclus1, deff = TRUE) 10 11#deffs returned from svyglm model - implausibly high 12deff(mod) 13#> (Intercept) enroll api.stu 14#> 351.3500 457.6799 491.5567 15 16# run mod with same data and glm() 17srs_mod <- glm(api99 ~ enroll + api.stu, data = apiclus1) 18 19# manually calculate deffs 20 21clust_se <- summary(mod)$coefficients[,2] 22srs_se <- summary(srs_mod)$coefficients[,2] 23 24deffs <- clust_se^2 / srs_se^2 25stopifnot(all.equal(deffs, deff(mod))) 26 27