1 2R version 3.4.1 (2017-06-30) -- "Single Candle" 3Copyright (C) 2017 The R Foundation for Statistical Computing 4Platform: x86_64-apple-darwin15.6.0 (64-bit) 5 6R is free software and comes with ABSOLUTELY NO WARRANTY. 7You are welcome to redistribute it under certain conditions. 8Type 'license()' or 'licence()' for distribution details. 9 10 Natural language support but running in an English locale 11 12R is a collaborative project with many contributors. 13Type 'contributors()' for more information and 14'citation()' on how to cite R or R packages in publications. 15 16Type 'demo()' for some demos, 'help()' for on-line help, or 17'help.start()' for an HTML browser interface to help. 18Type 'q()' to quit R. 19 20> 21> library(survey) 22Loading required package: grid 23Loading required package: Matrix 24Loading required package: survival 25 26Attaching package: ‘survey’ 27 28The following object is masked from ‘package:graphics’: 29 30 dotchart 31 32> library(RSQLite) 33> 34> data(api) 35> apiclus1$api_stu<-apiclus1$api.stu 36> apiclus1$comp_imp<-apiclus1$comp.imp 37> dclus1<-svydesign(id=~dnum, weights=~pw, fpc=~fpc,data=apiclus1) 38> dbclus1<-svydesign(id=~dnum, weights=~pw, fpc=~fpc, 39+ data="apiclus1",dbtype="SQLite", dbname=system.file("api.db",package="survey")) 40> 41> m<-svymean(~api00+stype,dclus1) 42> m.db<-svymean(~api00+stype, dbclus1) 43> all.equal(coef(m),coef(m.db)) 44[1] TRUE 45> all.equal(vcov(m), vcov(m.db)) 46[1] TRUE 47> 48> r<-svyratio(~api_stu, ~enroll, design=dclus1) 49> r.db<-svyratio(~api_stu, ~enroll, design=dbclus1) 50> all.equal(coef(r), coef(r.db)) 51[1] TRUE 52> all.equal(SE(r), SE(r.db)) 53[1] TRUE 54> 55> b<-svyby(~api99+api00,~stype, design=dclus1, svymean, deff=TRUE) 56> b.db<-svyby(~api99+api00,~stype, design=dbclus1,svymean, deff=TRUE) 57> all.equal(coef(b), coef(b.db)) 58[1] TRUE 59> all.equal(SE(b), SE(b.db)) 60[1] TRUE 61> all.equal(deff(b), deff(b.db)) 62[1] TRUE 63> 64> l<-svyglm(api00~api99+mobility, design=dclus1) 65> l.db<-svyglm(api00~api99+mobility, design=dbclus1) 66> all.equal(coef(l),coef(l.db)) 67[1] TRUE 68> all.equal(vcov(l), vcov(l.db)) 69[1] TRUE 70> 71> dclus1<-update(dclus1, apidiff=api00-api99) 72> dclus1<-update(dclus1, apipct= apidiff/api99) 73> dbclus1<-update(dbclus1, apidiff=api00-api99) 74> dbclus1<-update(dbclus1, apipct= apidiff/api99) 75> 76> u<-svymean(~api00+apidiff+apipct, dclus1) 77> u.db<-svymean(~api00+apidiff+apipct, dbclus1) 78> all.equal(u, u.db) 79[1] TRUE 80> 81> all.equal(nrow(dclus1),nrow(dbclus1)) 82[1] TRUE 83> 84> ## replicate weights 85> rclus1<-as.svrepdesign(dclus1) 86> db_rclus1<-svrepdesign(weights=~pw, repweights="wt[1-9]+", type="JK1", scale=(1-15/757)*14/15, 87+ data="apiclus1rep",dbtype="SQLite", dbname=system.file("api.db",package="survey"),combined.weights=FALSE) 88> m<-svymean(~api00+api99,rclus1) 89> m.db<-svymean(~api00+api99,db_rclus1) 90> all.equal(m,m.db) 91[1] TRUE 92> 93> summary(db_rclus1) 94DB-backed replicate weight design 95Call: svrepdesign(weights = ~pw, repweights = "wt[1-9]+", type = "JK1", 96 scale = (1 - 15/757) * 14/15, data = "apiclus1rep", dbtype = "SQLite", 97 dbname = system.file("api.db", package = "survey"), combined.weights = FALSE) 98Unstratified cluster jacknife (JK1) with 15 replicates. 99Variables: 100 [1] "row_names" "cds" "stype" "name" "sname" 101 [6] "snum" "dname" "dnum" "cname" "cnum" 102[11] "flag" "pcttest" "api00" "api99" "target" 103[16] "growth" "sch_wide" "comp_imp" "both" "awards" 104[21] "meals" "ell" "yr_rnd" "mobility" "acs_k3" 105[26] "acs_46" "acs_core" "pct_resp" "not_hsg" "hsg" 106[31] "some_col" "col_grad" "grad_sch" "avg_ed" "full__1" 107[36] "emer" "enroll" "api_stu" "fpc" "pw" 108[41] "row_names:1" "wt1" "wt2" "wt3" "wt4" 109[46] "wt5" "wt6" "wt7" "wt8" "wt9" 110[51] "wt10" "wt11" "wt12" "wt13" "wt14" 111[56] "wt15" 112> 113> s<-svymean(~api00, subset(rclus1, comp_imp=="Yes")) 114> s.db<-svymean(~api00, subset(db_rclus1, comp_imp=="Yes")) 115> all.equal(s,s.db) 116[1] TRUE 117> 118