with.svyimputationList.Rd
Performs a survey analysis on each of the designs in a
svyimputationList
objects and returns a list of results suitable
for MIcombine
. The analysis may be specified as an expression or
as a function.
A svyimputationList
object
An expression giving a survey analysis
A function taking a survey design object as its argument
for future expansion
Use multicore
package to distribute imputed data sets over multiple processors?
An logical expression specifying the subset
A list of the results from applying the analysis to each design object.
MIcombine
, in the mitools
package
library(mitools)
data.dir<-system.file("dta",package="mitools")
files.men<-list.files(data.dir,pattern="m.\\.dta$",full=TRUE)
men<-imputationList(lapply(files.men, foreign::read.dta,
warn.missing.labels=FALSE))
files.women<-list.files(data.dir,pattern="f.\\.dta$",full=TRUE)
women<-imputationList(lapply(files.women, foreign::read.dta,
warn.missing.labels=FALSE))
men<-update(men, sex=1)
women<-update(women,sex=0)
all<-rbind(men,women)
designs<-svydesign(id=~id, strata=~sex, data=all)
designs
#> Multiple (5) imputations: svydesign(id = ~id, strata = ~sex, data = all)
results<-with(designs, svymean(~drkfre))
MIcombine(results)
#> Multiple imputation results:
#> with(designs, svymean(~drkfre))
#> MIcombine.default(results)
#> results se
#> drkfreNon drinker 0.41692308 0.02705950
#> drkfrenot in last wk 0.33555556 0.02082624
#> drkfre<3 days last wk 0.20632479 0.01701647
#> drkfre>=3 days last wk 0.04119658 0.00776177
summary(MIcombine(results))
#> Multiple imputation results:
#> with(designs, svymean(~drkfre))
#> MIcombine.default(results)
#> results se (lower upper) missInfo
#> drkfreNon drinker 0.41692308 0.02705950 0.36387940 0.46996676 2 %
#> drkfrenot in last wk 0.33555556 0.02082624 0.29469352 0.37641759 6 %
#> drkfre<3 days last wk 0.20632479 0.01701647 0.17297052 0.23967906 2 %
#> drkfre>=3 days last wk 0.04119658 0.00776177 0.02596223 0.05643093 7 %
repdesigns<-as.svrepdesign(designs, type="boot", replicates=50)
MIcombine(with(repdesigns, svymean(~drkfre)))
#> Multiple imputation results:
#> with(repdesigns, svymean(~drkfre))
#> MIcombine.default(with(repdesigns, svymean(~drkfre)))
#> results se
#> drkfreNon drinker 0.41692308 0.025370783
#> drkfrenot in last wk 0.33555556 0.020675251
#> drkfre<3 days last wk 0.20632479 0.015791738
#> drkfre>=3 days last wk 0.04119658 0.007900786