R Under development (unstable) (2024-03-08 r86070 ucrt) -- "Unsuffered Consequences" Copyright (C) 2024 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 > options(warn=2) > > ## Caused warnings and unhelpful results in 4.1_1 (Guilherme Jacob) > data(api) > dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) > svyby(~api99, ~stype, dclus1, svymean ) stype api99 se E E 607.7917 22.81660 H H 595.7143 41.76400 M M 608.6000 32.56064 > > set.seed(123) > apiclus1$api99[ sample.int( nrow(apiclus1) , 5 ) ] <- NA > dclus1.na <-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc) > > # subsetting w/ na.rm = FALSE... > svymean( ~api99 , subset( dclus1.na , stype == "E" ) , na.rm = FALSE ) mean SE api99 NA NA > svymean( ~api99 , subset( dclus1.na , stype == "H" ) , na.rm = FALSE ) mean SE api99 595.71 41.764 > svymean( ~api99 , subset( dclus1.na , stype == "M" ) , na.rm = FALSE ) mean SE api99 NA NA > > # ... looks like this: > svyby(~api99, ~stype, dclus1.na , svymean ) stype api99 se E E NA NA H H 595.7143 41.764 M M NA NA > > # subsetting w/ na.rm = TRUE... > svymean( ~api99 , subset( dclus1.na , stype == "E" ) , na.rm = TRUE ) mean SE api99 606.53 22.901 > svymean( ~api99 , subset( dclus1.na , stype == "H" ) , na.rm = TRUE ) mean SE api99 595.71 41.764 > svymean( ~api99 , subset( dclus1.na , stype == "M" ) , na.rm = TRUE ) mean SE api99 613.39 33.224 > > # ... looks like this > svyby(~api99, ~stype, dclus1.na , svymean , na.rm = TRUE ) stype api99 se E E 606.5319 22.90084 H H 595.7143 41.76400 M M 613.3913 33.22358 > > # Without missing values, this works: > svyby(~api99, ~stype, dclus1 , svymean , na.rm = TRUE , covmat = TRUE ) stype api99 se E E 607.7917 22.81660 H H 595.7143 41.76400 M M 608.6000 32.56064 > > # ... but this breaks! > svyby(~api99, ~stype, dclus1.na , svymean , na.rm = TRUE , covmat = TRUE ) stype api99 se E E 606.5319 22.90084 H H 595.7143 41.76400 M M 613.3913 33.22358 > > # ... and i don't think this is the expected behavior > svyby( ~api99, ~stype, dclus1.na , svymean , na.rm.all = TRUE , covmat = TRUE ) stype api99 se E E NA NA H H 595.7143 41.764 M M NA NA > svyby( ~api99, ~stype, dclus1.na , svymean , na.rm.all = TRUE , na.rm = TRUE , covmat = TRUE ) stype api99 se E E 606.5319 22.90084 H H 595.7143 41.76400 M M 613.3913 33.22358 > > > ## Now some more as tests > svyby(~api99, ~stype, dclus1.na , svytotal , na.rm = TRUE , covmat = TRUE ) stype api99 se E E 2894629.0 792809.8 H H 282283.9 101492.9 M M 477513.4 107555.5 > svyby(~api99, ~stype, dclus1.na , svyratio , na.rm = TRUE , denominator=~api00, covmat = TRUE ) stype api99/api00 se.api99/api00 E E 0.9367750 0.006365702 H H 0.9630485 0.010520785 M M 0.9682246 0.009390982 > > ff<-function(f,d,...,na.rm=TRUE) svyglm(f,d,...) > svyby(api99~1, ~stype, dclus1.na , ff , na.rm = TRUE , covmat = TRUE ) stype (Intercept) se.(Intercept) E E 606.5319 22.90084 H H 595.7143 41.76400 M M 613.3913 33.22358 > > proc.time() user system elapsed 1.21 0.12 1.32