R : Copyright 2005, The R Foundation for Statistical Computing Version 2.1.1 (2005-06-20), ISBN 3-900051-07-0 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 a HTML browser interface to help. Type 'q()' to quit R. > ### *
> ### > attach(NULL, name = "CheckExEnv") > assign(".CheckExEnv", as.environment(2), pos = length(search())) # base > ## add some hooks to label plot pages for base and grid graphics > setHook("plot.new", ".newplot.hook") > setHook("persp", ".newplot.hook") > setHook("grid.newpage", ".gridplot.hook") > > assign("cleanEx", + function(env = .GlobalEnv) { + rm(list = ls(envir = env, all.names = TRUE), envir = env) + RNGkind("default", "default") + set.seed(1) + options(warn = 1) + delayedAssign("T", stop("T used instead of TRUE"), + assign.env = .CheckExEnv) + delayedAssign("F", stop("F used instead of FALSE"), + assign.env = .CheckExEnv) + sch <- search() + newitems <- sch[! sch %in% .oldSearch] + for(item in rev(newitems)) + eval(substitute(detach(item), list(item=item))) + missitems <- .oldSearch[! .oldSearch %in% sch] + if(length(missitems)) + warning("items ", paste(missitems, collapse=", "), + " have been removed from the search path") + }, + env = .CheckExEnv) > assign("..nameEx", "__{must remake R-ex/*.R}__", env = .CheckExEnv) # for now > assign("ptime", proc.time(), env = .CheckExEnv) > grDevices::postscript("mitools-Examples.ps") > assign("par.postscript", graphics::par(no.readonly = TRUE), env = .CheckExEnv) > options(contrasts = c(unordered = "contr.treatment", ordered = "contr.poly")) > options(warn = 1) > library('mitools') > > assign(".oldSearch", search(), env = .CheckExEnv) > assign(".oldNS", loadedNamespaces(), env = .CheckExEnv) > cleanEx(); ..nameEx <- "MIcombine" > > ### * MIcombine > > flush(stderr()); flush(stdout()) > > ### Name: MIcombine > ### Title: Multiple imputation inference > ### Aliases: MIcombine MIcombine.default MIcombine.imputationResultList > ### print.MIresult summary.MIresult vcov.MIresult > ### Keywords: htest manip > > ### ** Examples > > data(smi) > models<-with(smi, glm(drinkreg~wave*sex,family=binomial())) > summary(MIcombine(models)) Multiple imputation results: with.imputationList(smi, glm(drinkreg ~ wave * sex, family = binomial())) MIcombine.default(models) results se (lower upper) missInfo (Intercept) -2.25974358 0.26830731 -2.78584855 -1.7336386 4 % wave 0.24055250 0.06587423 0.11092461 0.3701804 12 % sex 0.64905222 0.34919264 -0.03537187 1.3334763 1 % wave:sex -0.03725422 0.08609199 -0.20623121 0.1317228 7 % > > betas<-MIextract(models,fun=coef) > vars<-MIextract(models, fun=vcov) > summary(MIcombine(betas,vars)) Multiple imputation results: MIcombine.default(betas, vars) results se (lower upper) missInfo (Intercept) -2.25974358 0.26830731 -2.78584855 -1.7336386 4 % wave 0.24055250 0.06587423 0.11092461 0.3701804 12 % sex 0.64905222 0.34919264 -0.03537187 1.3334763 1 % wave:sex -0.03725422 0.08609199 -0.20623121 0.1317228 7 % > > > > cleanEx(); ..nameEx <- "MIextract" > > ### * MIextract > > flush(stderr()); flush(stdout()) > > ### Name: MIextract > ### Title: Extract a parameter from a list of results > ### Aliases: MIextract > ### Keywords: manip > > ### ** Examples > > data(smi) > models<-with(smi, glm(drinkreg~wave*sex,family=binomial())) > > betas<-MIextract(models,fun=coef) > vars<-MIextract(models, fun=vcov) > summary(MIcombine(betas,vars)) Multiple imputation results: MIcombine.default(betas, vars) results se (lower upper) missInfo (Intercept) -2.25974358 0.26830731 -2.78584855 -1.7336386 4 % wave 0.24055250 0.06587423 0.11092461 0.3701804 12 % sex 0.64905222 0.34919264 -0.03537187 1.3334763 1 % wave:sex -0.03725422 0.08609199 -0.20623121 0.1317228 7 % > > > > cleanEx(); ..nameEx <- "imputationList" > > ### * imputationList > > flush(stderr()); flush(stdout()) > > ### Name: imputationList > ### Title: Constructor for imputationList objects > ### Aliases: imputationList print.imputationList rbind.imputationList > ### cbind.imputationList dimnames.imputationList dim.imputationList > ### update.imputationList > ### Keywords: manip > > ### ** Examples > > 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)) Warning in FUN(X[[1]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[2]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[3]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[4]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[5]], ...) : value labels (mis) for mdrkfre are missing > files.women<-list.files(data.dir,pattern="f.\.dta$",full=TRUE) > women<-imputationList(lapply(files.women, foreign::read.dta)) Warning in FUN(X[[1]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[2]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[3]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[4]], ...) : value labels (mis) for mdrkfre are missing Warning in FUN(X[[5]], ...) : value labels (mis) for mdrkfre are missing > men<-update(men, sex=1) > women<-update(women,sex=0) > all<-rbind(men,women) > all<-update(all, drinkreg=as.numeric(drkfre)>2) > all MI data with 5 datasets Call: rbind(...) > > > > cleanEx(); ..nameEx <- "smi" > > ### * smi > > flush(stderr()); flush(stdout()) > > ### Name: smi > ### Title: Multiple imputations > ### Aliases: smi > ### Keywords: datasets > > ### ** Examples > > data(smi) > with(smi, table(sex, drkfre)) [[1]] drkfre sex Non drinker not in last wk <3 days last wk >=3 days last wk 0 282 201 105 12 1 207 194 134 35 [[2]] drkfre sex Non drinker not in last wk <3 days last wk >=3 days last wk 0 282 195 109 14 1 200 200 132 38 [[3]] drkfre sex Non drinker not in last wk <3 days last wk >=3 days last wk 0 278 202 109 11 1 209 194 131 36 [[4]] drkfre sex Non drinker not in last wk <3 days last wk >=3 days last wk 0 284 188 114 14 1 203 206 128 33 [[5]] drkfre sex Non drinker not in last wk <3 days last wk >=3 days last wk 0 288 191 109 12 1 206 192 136 36 attr(,"call") with.imputationList(smi, table(sex, drkfre)) > model1<-with(smi, glm(drinkreg~wave*sex, family=binomial())) > MIcombine(model1) Multiple imputation results: with.imputationList(smi, glm(drinkreg ~ wave * sex, family = binomial())) MIcombine.default(model1) results se (Intercept) -2.25974358 0.26830731 wave 0.24055250 0.06587423 sex 0.64905222 0.34919264 wave:sex -0.03725422 0.08609199 > summary(MIcombine(model1)) Multiple imputation results: with.imputationList(smi, glm(drinkreg ~ wave * sex, family = binomial())) MIcombine.default(model1) results se (lower upper) missInfo (Intercept) -2.25974358 0.26830731 -2.78584855 -1.7336386 4 % wave 0.24055250 0.06587423 0.11092461 0.3701804 12 % sex 0.64905222 0.34919264 -0.03537187 1.3334763 1 % wave:sex -0.03725422 0.08609199 -0.20623121 0.1317228 7 % > > > > cleanEx(); ..nameEx <- "with.imputationList" > > ### * with.imputationList > > flush(stderr()); flush(stdout()) > > ### Name: with.imputationList > ### Title: Evaluate an expression in multiple imputed datasets > ### Aliases: with.imputationList > ### Keywords: manip > > ### ** Examples > > data(smi) > models<-with(smi, glm(drinkreg~wave*sex,family=binomial())) > tables<-with(smi, table(drkfre,sex)) > with(smi, fun=summary) [[1]] id wave mmetro parsmk Min. :920001 Min. :1.0 Min. :0.0000 Min. :0.0000 1st Qu.:920138 1st Qu.:2.0 1st Qu.:1.0000 1st Qu.:0.0000 Median :920283 Median :3.5 Median :1.0000 Median :1.0000 Mean :920312 Mean :3.5 Mean :0.9026 Mean :0.7487 3rd Qu.:920436 3rd Qu.:5.0 3rd Qu.:1.0000 3rd Qu.:1.0000 Max. :920793 Max. :6.0 Max. :1.0000 Max. :1.0000 drkfre alcdos alcdhi Non drinker :489 Non drinker :488 Min. :0.0000 not in last wk :395 not in last wk :382 1st Qu.:0.0000 <3 days last wk :239 av <5units/drink_day :139 Median :0.0000 >=3 days last wk: 47 av =>5units/drink_day:161 Mean :0.1667 3rd Qu.:0.0000 Max. :1.0000 smk cistot mdrkfre sex non/ex-smoker:839 Min. : 0.000 Min. :0.0000 Min. :0.0000 <6 days :201 1st Qu.: 1.000 1st Qu.:0.0000 1st Qu.:0.0000 6/7 days :130 Median : 4.000 Median :0.0000 Median :0.0000 Mean : 6.819 Mean :0.1393 Mean :0.4872 3rd Qu.:10.000 3rd Qu.:0.0000 3rd Qu.:1.0000 Max. :56.000 Max. :1.0000 Max. :1.0000 drinkreg Mode :logical FALSE:884 TRUE :286 [[2]] id wave mmetro parsmk Min. :920001 Min. :1.0 Min. :0.0000 Min. :0.0000 1st Qu.:920138 1st Qu.:2.0 1st Qu.:1.0000 1st Qu.:0.0000 Median :920283 Median :3.5 Median :1.0000 Median :1.0000 Mean :920312 Mean :3.5 Mean :0.9026 Mean :0.7487 3rd Qu.:920436 3rd Qu.:5.0 3rd Qu.:1.0000 3rd Qu.:1.0000 Max. :920793 Max. :6.0 Max. :1.0000 Max. :1.0000 drkfre alcdos alcdhi Non drinker :482 Non drinker :483 Min. :0.0000 not in last wk :395 not in last wk :382 1st Qu.:0.0000 <3 days last wk :241 av <5units/drink_day :136 Median :0.0000 >=3 days last wk: 52 av =>5units/drink_day:169 Mean :0.1658 3rd Qu.:0.0000 Max. :1.0000 smk cistot mdrkfre sex non/ex-smoker:851 Min. : 0.000 Min. :0.0000 Min. :0.0000 <6 days :197 1st Qu.: 1.000 1st Qu.:0.0000 1st Qu.:0.0000 6/7 days :122 Median : 4.000 Median :0.0000 Median :0.0000 Mean : 6.613 Mean :0.1393 Mean :0.4872 3rd Qu.:10.000 3rd Qu.:0.0000 3rd Qu.:1.0000 Max. :56.000 Max. :1.0000 Max. :1.0000 drinkreg Mode :logical FALSE:877 TRUE :293 [[3]] id wave mmetro parsmk Min. :920001 Min. :1.0 Min. :0.0000 Min. :0.0000 1st Qu.:920138 1st Qu.:2.0 1st Qu.:1.0000 1st Qu.:0.0000 Median :920283 Median :3.5 Median :1.0000 Median :1.0000 Mean :920312 Mean :3.5 Mean :0.9026 Mean :0.7487 3rd Qu.:920436 3rd Qu.:5.0 3rd Qu.:1.0000 3rd Qu.:1.0000 Max. :920793 Max. :6.0 Max. :1.0000 Max. :1.0000 drkfre alcdos alcdhi Non drinker :487 Non drinker :486 Min. :0.0000 not in last wk :396 not in last wk :382 1st Qu.:0.0000 <3 days last wk :240 av <5units/drink_day :138 Median :0.0000 >=3 days last wk: 47 av =>5units/drink_day:164 Mean :0.1667 3rd Qu.:0.0000 Max. :1.0000 smk cistot mdrkfre sex non/ex-smoker:833 Min. : 0.000 Min. :0.0000 Min. :0.0000 <6 days :204 1st Qu.: 1.000 1st Qu.:0.0000 1st Qu.:0.0000 6/7 days :133 Median : 4.000 Median :0.0000 Median :0.0000 Mean : 6.601 Mean :0.1393 Mean :0.4872 3rd Qu.:10.000 3rd Qu.:0.0000 3rd Qu.:1.0000 Max. :56.000 Max. :1.0000 Max. :1.0000 drinkreg Mode :logical FALSE:883 TRUE :287 [[4]] id wave mmetro parsmk Min. :920001 Min. :1.0 Min. :0.0000 Min. :0.0000 1st Qu.:920138 1st Qu.:2.0 1st Qu.:1.0000 1st Qu.:0.0000 Median :920283 Median :3.5 Median :1.0000 Median :1.0000 Mean :920312 Mean :3.5 Mean :0.9026 Mean :0.7487 3rd Qu.:920436 3rd Qu.:5.0 3rd Qu.:1.0000 3rd Qu.:1.0000 Max. :920793 Max. :6.0 Max. :1.0000 Max. :1.0000 drkfre alcdos alcdhi Non drinker :487 Non drinker :486 Min. :0.0000 not in last wk :394 not in last wk :382 1st Qu.:0.0000 <3 days last wk :242 av <5units/drink_day :142 Median :0.0000 >=3 days last wk: 47 av =>5units/drink_day:160 Mean :0.1650 3rd Qu.:0.0000 Max. :1.0000 smk cistot mdrkfre sex non/ex-smoker:843 Min. : 0.000 Min. :0.0000 Min. :0.0000 <6 days :200 1st Qu.: 1.000 1st Qu.:0.0000 1st Qu.:0.0000 6/7 days :127 Median : 4.000 Median :0.0000 Median :0.0000 Mean : 6.779 Mean :0.1393 Mean :0.4872 3rd Qu.:10.000 3rd Qu.:0.0000 3rd Qu.:1.0000 Max. :56.000 Max. :1.0000 Max. :1.0000 drinkreg Mode :logical FALSE:881 TRUE :289 [[5]] id wave mmetro parsmk Min. :920001 Min. :1.0 Min. :0.0000 Min. :0.0000 1st Qu.:920138 1st Qu.:2.0 1st Qu.:1.0000 1st Qu.:0.0000 Median :920283 Median :3.5 Median :1.0000 Median :1.0000 Mean :920312 Mean :3.5 Mean :0.9026 Mean :0.7487 3rd Qu.:920436 3rd Qu.:5.0 3rd Qu.:1.0000 3rd Qu.:1.0000 Max. :920793 Max. :6.0 Max. :1.0000 Max. :1.0000 drkfre alcdos alcdhi Non drinker :494 Non drinker :493 Min. :0.0000 not in last wk :383 not in last wk :376 1st Qu.:0.0000 <3 days last wk :245 av <5units/drink_day :135 Median :0.0000 >=3 days last wk: 48 av =>5units/drink_day:166 Mean :0.1598 3rd Qu.:0.0000 Max. :1.0000 smk cistot mdrkfre sex non/ex-smoker:843 Min. : 0.000 Min. :0.0000 Min. :0.0000 <6 days :197 1st Qu.: 1.000 1st Qu.:0.0000 1st Qu.:0.0000 6/7 days :130 Median : 4.000 Median :0.0000 Median :0.0000 Mean : 6.662 Mean :0.1393 Mean :0.4872 3rd Qu.:10.000 3rd Qu.:0.0000 3rd Qu.:1.0000 Max. :45.000 Max. :1.0000 Max. :1.0000 drinkreg Mode :logical FALSE:877 TRUE :293 attr(,"call") with.imputationList(smi, fun = summary) > > > > ### *