R Under development (unstable) (2026-02-23 r89457 ucrt) -- "Unsuffered Consequences" Copyright (C) 2026 The R Foundation for Statistical Computing Platform: x86_64-w64-mingw32/x64 R is free software and comes with ABSOLUTELY NO WARRANTY. You are welcome to redistribute it under certain conditions. Type 'license()' or 'licence()' for distribution details. R is a collaborative project with many contributors. Type 'contributors()' for more information and 'citation()' on how to cite R or R packages in publications. Type 'demo()' for some demos, 'help()' for on-line help, or 'help.start()' for an HTML browser interface to help. Type 'q()' to quit R. > library(survey) Loading required package: grid Loading required package: Matrix Loading required package: survival Attaching package: 'survey' The following object is masked from 'package:graphics': dotchart > load("db.rda") > d<-svydesign(ids=~psu,data=db,weights=~pweight,fpc=~psu_size) > pop.sex<-data.frame(sex=c("男","女"),Freq=c(4592,4190)) > pop.hos<-data.frame(hospital=c("hos1","hos2", + "hos3","hos4", + "hos5","hos6", + "hos7"), + Freq=c(1796+383,2917,1805,316,420,389,756)) > d<-rake(d,sample.margins=list(~sex,~hospital),population.margins=list(pop.sex,pop.hos)) > ## with option covmat = TRUE, 错误于inflmats[[i]][idxs[[i]], ] <- infs[[i]]: 被替换的项目不是替换值长度的倍数 > svyby(formula = ~FT_num+DMFT+ft_num+dmft, by=~sex,design = d, + FUN=svytotal,na.rm=TRUE,covmat = TRUE,deff=TRUE) sex FT_num DMFT ft_num dmft se.FT_num se.DMFT se.ft_num 女 女 1172.2305 8337.063 186.8056 1474.904 104.5260 486.2314 29.47179 男 男 647.1464 6540.285 308.2464 1883.472 58.2017 377.2176 43.84198 se.dmft DEff.FT_num DEff.DMFT DEff.ft_num DEff.dmft 女 121.8625 0.9624899 2.213134 0.7058200 0.9210157 男 127.0846 0.6329536 1.612501 0.9338083 0.7730376 > > > ## now check correctness > data(api) > dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc) > calstrat<-calibrate(dstrat,~stype+0, pop=c(4421,755,1018)) > svyby(~enroll, ~comp.imp, FUN=svytotal, covmat=TRUE,deff=TRUE,dstrat)->a > svyby(~enroll, ~comp.imp, FUN=svytotal, covmat=TRUE,deff=TRUE,calstrat)->b > > svycontrast(a,c(1,-1))->delta_a > svycontrast(b,c(1,-1))->delta_b > > stopifnot(isTRUE(all.equal(coef(delta_a),coef(delta_b),tol=1e-7))) > stopifnot(isTRUE(all.equal(SE(delta_a),SE(delta_b),tol=1e-7))) > > proc.time() user system elapsed 1.79 0.23 2.01