R Under development (unstable) (2024-03-19 r86153 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 > library(RSQLite) > > data(api) > apiclus1$api_stu<-apiclus1$api.stu > apiclus1$comp_imp<-apiclus1$comp.imp > dclus1<-svydesign(id=~dnum, weights=~pw, fpc=~fpc,data=apiclus1) > dbclus1<-svydesign(id=~dnum, weights=~pw, fpc=~fpc, + data="apiclus1",dbtype="SQLite", dbname=system.file("api.db",package="survey")) > > m<-svymean(~api00+stype,dclus1) > m.db<-svymean(~api00+stype, dbclus1) > all.equal(coef(m),coef(m.db)) [1] TRUE > all.equal(vcov(m), vcov(m.db)) [1] TRUE > > r<-svyratio(~api_stu, ~enroll, design=dclus1) > r.db<-svyratio(~api_stu, ~enroll, design=dbclus1) > all.equal(coef(r), coef(r.db)) [1] TRUE > all.equal(SE(r), SE(r.db)) [1] TRUE > > b<-svyby(~api99+api00,~stype, design=dclus1, svymean, deff=TRUE) > b.db<-svyby(~api99+api00,~stype, design=dbclus1,svymean, deff=TRUE) > all.equal(coef(b), coef(b.db)) [1] TRUE > all.equal(SE(b), SE(b.db)) [1] TRUE > all.equal(deff(b), deff(b.db)) [1] TRUE > > l<-svyglm(api00~api99+mobility, design=dclus1) > l.db<-svyglm(api00~api99+mobility, design=dbclus1) > all.equal(coef(l),coef(l.db)) [1] TRUE > all.equal(vcov(l), vcov(l.db)) [1] TRUE > > dclus1<-update(dclus1, apidiff=api00-api99) > dclus1<-update(dclus1, apipct= apidiff/api99) > dbclus1<-update(dbclus1, apidiff=api00-api99) > dbclus1<-update(dbclus1, apipct= apidiff/api99) > > u<-svymean(~api00+apidiff+apipct, dclus1) > u.db<-svymean(~api00+apidiff+apipct, dbclus1) > all.equal(u, u.db) [1] TRUE > > all.equal(nrow(dclus1),nrow(dbclus1)) [1] TRUE > all.equal(nrow(subset(dclus1,stype=="E")), + nrow(subset(dbclus1,stype=="E"))) [1] "Mean relative difference: 0.2708333" > > ## replicate weights > rclus1<-as.svrepdesign(dclus1) > db_rclus1<-svrepdesign(weights=~pw, repweights="wt[1-9]+", type="JK1", scale=(1-15/757)*14/15, + data="apiclus1rep",dbtype="SQLite", dbname=system.file("api.db",package="survey"),combined.weights=FALSE) > m<-svymean(~api00+api99,rclus1) > m.db<-svymean(~api00+api99,db_rclus1) > all.equal(m,m.db) [1] TRUE > > summary(db_rclus1) DB-backed replicate weight design Call: svrepdesign(weights = ~pw, repweights = "wt[1-9]+", type = "JK1", scale = (1 - 15/757) * 14/15, data = "apiclus1rep", dbtype = "SQLite", dbname = system.file("api.db", package = "survey"), combined.weights = FALSE) Unstratified cluster jacknife (JK1) with 15 replicates. Variables: [1] "row_names" "cds" "stype" "name" "sname" [6] "snum" "dname" "dnum" "cname" "cnum" [11] "flag" "pcttest" "api00" "api99" "target" [16] "growth" "sch_wide" "comp_imp" "both" "awards" [21] "meals" "ell" "yr_rnd" "mobility" "acs_k3" [26] "acs_46" "acs_core" "pct_resp" "not_hsg" "hsg" [31] "some_col" "col_grad" "grad_sch" "avg_ed" "full__1" [36] "emer" "enroll" "api_stu" "fpc" "pw" [41] "row_names:1" "wt1" "wt2" "wt3" "wt4" [46] "wt5" "wt6" "wt7" "wt8" "wt9" [51] "wt10" "wt11" "wt12" "wt13" "wt14" [56] "wt15" > > s<-svymean(~api00, subset(rclus1, comp_imp=="Yes")) > s.db<-svymean(~api00, subset(db_rclus1, comp_imp=="Yes")) > all.equal(s,s.db) [1] TRUE > > proc.time() user system elapsed 2.12 0.31 2.42