Running '3stage2phase.R' [3s]
  Running 'DBIcheck.R' [2s]
  Running 'anova-svycoxph.R' [148s]
  Running 'api.R' [141s]
  Running 'badcal.R' [1s]
  Comparing 'badcal.Rout' to 'badcal.Rout.save' ... OK
  Running 'brewer_cpp.R' [2s]
  Running 'bycovmat.R' [2s]
  Running 'caleg.R' [123s]
  Running 'check.R' [1s]
  Comparing 'check.Rout' to 'check.Rout.save' ... OK
  Running 'confintrep.R' [1s]
  Running 'contrast-replicates.R' [74s]
  Running 'coxph-termtest.R' [83s]
  Running 'deff.R' [1s]
  Comparing 'deff.Rout' to 'deff.Rout.save' ... OK
  Running 'defftest.R' [1s]
  Running 'degf-svrepdesign.R' [1s]
  Running 'domain.R' [2s]
  Comparing 'domain.Rout' to 'domain.Rout.save' ... OK
  Running 'fpc.R' [1s]
  Running 'glm-scoping.R' [111s]
  Running 'kalton.R' [1s]
  Comparing 'kalton.Rout' to 'kalton.Rout.save' ... OK
  Running 'logranktest.R' [2s]
  Running 'lonely.psu.R' [2s]
  Comparing 'lonely.psu.Rout' to 'lonely.psu.Rout.save' ... OK
  Running 'mtcars-var.R' [1s]
  Running 'multistage-rcpp.R' [2s]
  Running 'multistage.R' [102s]
  Running 'na_action.R' [1s]
  Running 'newquantile.R' [1s]
  Running 'nwts-cch.R' [84s]
  Running 'nwts.R' [2s]
  Comparing 'nwts.Rout' to 'nwts.Rout.save' ... OK
  Running 'poisson.R' [1s]
  Running 'pps.R' [1s]
  Running 'qrule-swiss.R' [61s]
  Running 'quantile.R' [62s]
  Running 'quantiles-chile.R' [1s]
  Running 'rakecheck.R' [57s]
  Running 'raowuboot.R' [1s]
  Comparing 'raowuboot.Rout' to 'raowuboot.Rout.save' ... OK
  Running 'regTermTest-missing.R' [2s]
  Running 'regpredict.R' [1s]
  Comparing 'regpredict.Rout' to 'regpredict.Rout.save' ... OK
  Running 'rss_scores.R' [1s]
  Running 'scoping.R' [61s]
  Running 'survcurve.R' [60s]
  Running 'svyby-strings.R' [1s]
  Running 'svyby_bug.R' [1s]
  Running 'svyby_se.R' [63s]
  Running 'svycontrast.R' [62s]
  Running 'svyivreg-var.R' [60s]
  Running 'svyivreg.R' [64s]
  Running 'svyolr-rake-subset.R' [1s]
  Running 'svyolr.R' [1s]
  Running 'toy_example_for_postStratify.R' [1s]
  Running 'twophase.R' [2s]
  Comparing 'twophase.Rout' to 'twophase.Rout.save' ... OK
Running the tests in 'tests/anova-svycoxph.R' failed.
Complete output:
  > 
  >  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
  
  > example(svycoxph, ask=FALSE)
  
  svycxp> ## Somewhat unrealistic example of nonresponse bias.
  svycxp> data(pbc, package="survival")
  
  svycxp> pbc$randomized<-with(pbc, !is.na(trt) & trt>0)
  
  svycxp> biasmodel<-glm(randomized~age*edema,data=pbc,family=binomial)
  
  svycxp> pbc$randprob<-fitted(biasmodel)
  
  svycxp> if (is.null(pbc$albumin)) pbc$albumin<-pbc$alb ##pre2.9.0
  
  svycxp> dpbc<-svydesign(id=~1, prob=~randprob, strata=~edema, data=subset(pbc,randomized))
  
  svycxp> rpbc<-as.svrepdesign(dpbc)
  
  svycxp> (model<-svycoxph(Surv(time,status>0)~log(bili)+protime+albumin,design=dpbc))
  Call:
  svycoxph(formula = Surv(time, status > 0) ~ log(bili) + protime + 
      albumin, design = dpbc)
  
                coef exp(coef) se(coef) robust se      z        p
  log(bili)  0.88592   2.42522  0.09140   0.09048  9.791  < 2e-16
  protime    0.24487   1.27745  0.07825   0.08122  3.015  0.00257
  albumin   -1.04298   0.35240  0.21211   0.20454 -5.099 3.41e-07
  
  Likelihood ratio test=  on 3 df, p=
  n= 312, number of events= 144 
  
  svycxp> svycoxph(Surv(time,status>0)~log(bili)+protime+albumin,design=rpbc)
  Call:
  svycoxph.svyrep.design(formula = Surv(time, status > 0) ~ log(bili) + 
      protime + albumin, design = rpbc)
  
                coef exp(coef) se(coef)      z        p
  log(bili)  0.88592   2.42522  0.09838  9.005  < 2e-16
  protime    0.24487   1.27745  0.09373  2.612  0.00899
  albumin   -1.04298   0.35240  0.21966 -4.748 2.05e-06
  
  Likelihood ratio test=NA  on 3 df, p=NA
  n= 312, number of events= 144 
  
  svycxp> s<-predict(model,se=TRUE, type="curve",
  svycxp+      newdata=data.frame(bili=c(3,9), protime=c(10,10), albumin=c(3.5,3.5)))
  
  svycxp> plot(s[[1]],ci=TRUE,col="sienna")
  
  svycxp> lines(s[[2]], ci=TRUE,col="royalblue")
  
  svycxp> quantile(s[[1]], ci=TRUE)
  0.75  0.5 0.25 
  1435 2503 3574 
  attr(,"ci")
       0.025 0.975
  0.75  1217  1786
  0.5   2256  3170
  0.25  3222   Inf
  
  svycxp> confint(s[[2]], parm=365*(1:5))
           0.025     0.975
  365  0.8375139 0.9453781
  730  0.7382750 0.8999016
  1095 0.4784105 0.7478460
  1460 0.3192009 0.6206764
  1825 0.2149475 0.5292978
  > m<-update(model, .~.+I(protime^2))
  > a<-anova(m,model)
  > b<-anova(m, model,force=TRUE)
  > stopifnot(isTRUE(all.equal(b[2:6],a[c(3,4,6,7,8)])))
  > 
  > proc.time()
     user  system elapsed 
     1.96    0.23    2.18 
Running the tests in 'tests/api.R' failed.
Complete output:
  > 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(survey.replicates.mse=TRUE)
  > example(api)
  
  api> library(survey)
  
  api> data(api)
  
  api> mean(apipop$api00)
  [1] 664.7126
  
  api> sum(apipop$enroll, na.rm=TRUE)
  [1] 3811472
  
  api> #stratified sample
  api> dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  
  api> summary(dstrat)
  Stratified Independent Sampling design
  dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  Probabilities:
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.02262 0.02262 0.03587 0.04014 0.05339 0.06623 
  Stratum Sizes: 
               E  H  M
  obs        100 50 50
  design.PSU 100 50 50
  actual.PSU 100 50 50
  Population stratum sizes (PSUs): 
     E    H    M 
  4421  755 1018 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "pw"       "fpc"     
  
  api> svymean(~api00, dstrat)
          mean     SE
  api00 662.29 9.4089
  
  api> svytotal(~enroll, dstrat, na.rm=TRUE)
           total     SE
  enroll 3687178 114642
  
  api> # one-stage cluster sample
  api> dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  
  api> summary(dclus1)
  1 - level Cluster Sampling design
  With (15) clusters.
  dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  Probabilities:
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.02954 0.02954 0.02954 0.02954 0.02954 0.02954 
  Population size (PSUs): 757 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> svymean(~api00, dclus1)
          mean     SE
  api00 644.17 23.542
  
  api> svytotal(~enroll, dclus1, na.rm=TRUE)
           total     SE
  enroll 3404940 932235
  
  api> # two-stage cluster sample
  api> dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2)
  
  api> summary(dclus2)
  2 - level Cluster Sampling design
  With (40, 126) clusters.
  dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2)
  Probabilities:
      Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
  0.003669 0.037743 0.052840 0.042390 0.052840 0.052840 
  Population size (PSUs): 757 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "pw"       "fpc1"     "fpc2"    
  
  api> svymean(~api00, dclus2)
          mean     SE
  api00 670.81 30.099
  
  api> svytotal(~enroll, dclus2, na.rm=TRUE)
           total     SE
  enroll 2639273 799638
  
  api> # two-stage `with replacement'
  api> dclus2wr<-svydesign(id=~dnum+snum, weights=~pw, data=apiclus2)
  
  api> summary(dclus2wr)
  2 - level Cluster Sampling design (with replacement)
  With (40, 126) clusters.
  dclus2wr<-svydesign(id=~dnum+snum, weights=~pw, data=apiclus2)
  Probabilities:
      Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
  0.003669 0.037743 0.052840 0.042390 0.052840 0.052840 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "pw"       "fpc1"     "fpc2"    
  
  api> svymean(~api00, dclus2wr)
          mean     SE
  api00 670.81 30.712
  
  api> svytotal(~enroll, dclus2wr, na.rm=TRUE)
           total     SE
  enroll 2639273 820261
  
  api> # convert to replicate weights
  api> rclus1<-as.svrepdesign(dclus1)
  
  api> summary(rclus1)
  Call: as.svrepdesign.default(dclus1)
  Unstratified cluster jacknife (JK1) with 15 replicates and MSE variances.
  Variables: 
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> svymean(~api00, rclus1)
          mean     SE
  api00 644.17 26.335
  
  api> svytotal(~enroll, rclus1, na.rm=TRUE)
           total     SE
  enroll 3404940 932235
  
  api> # post-stratify on school type
  api> pop.types<-xtabs(~stype, data=apipop)
  
  api> rclus1p<-postStratify(rclus1, ~stype, pop.types)
  
  api> dclus1p<-postStratify(dclus1, ~stype, pop.types)
  
  api> summary(dclus1p)
  1 - level Cluster Sampling design
  With (15) clusters.
  dclus1p<-postStratify(dclus1, ~stype, pop.types)
  Probabilities:
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.01854 0.03257 0.03257 0.03040 0.03257 0.03257 
  Population size (PSUs): 757 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> summary(rclus1p)
  Call: rclus1p<-postStratify(rclus1, ~stype, pop.types)
  Unstratified cluster jacknife (JK1) with 15 replicates and MSE variances.
  Variables: 
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> svymean(~api00, dclus1p)
          mean     SE
  api00 642.31 23.921
  
  api> svytotal(~enroll, dclus1p, na.rm=TRUE)
           total     SE
  enroll 3680893 406293
  
  api> svymean(~api00, rclus1p)
          mean     SE
  api00 642.31 26.936
  
  api> svytotal(~enroll, rclus1p, na.rm=TRUE)
           total     SE
  enroll 3680893 473434
  > 
  > options(survey.replicates.mse=FALSE)
  > example(api)
  
  api> library(survey)
  
  api> data(api)
  
  api> mean(apipop$api00)
  [1] 664.7126
  
  api> sum(apipop$enroll, na.rm=TRUE)
  [1] 3811472
  
  api> #stratified sample
  api> dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  
  api> summary(dstrat)
  Stratified Independent Sampling design
  dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  Probabilities:
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.02262 0.02262 0.03587 0.04014 0.05339 0.06623 
  Stratum Sizes: 
               E  H  M
  obs        100 50 50
  design.PSU 100 50 50
  actual.PSU 100 50 50
  Population stratum sizes (PSUs): 
     E    H    M 
  4421  755 1018 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "pw"       "fpc"     
  
  api> svymean(~api00, dstrat)
          mean     SE
  api00 662.29 9.4089
  
  api> svytotal(~enroll, dstrat, na.rm=TRUE)
           total     SE
  enroll 3687178 114642
  
  api> # one-stage cluster sample
  api> dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  
  api> summary(dclus1)
  1 - level Cluster Sampling design
  With (15) clusters.
  dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  Probabilities:
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.02954 0.02954 0.02954 0.02954 0.02954 0.02954 
  Population size (PSUs): 757 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> svymean(~api00, dclus1)
          mean     SE
  api00 644.17 23.542
  
  api> svytotal(~enroll, dclus1, na.rm=TRUE)
           total     SE
  enroll 3404940 932235
  
  api> # two-stage cluster sample
  api> dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2)
  
  api> summary(dclus2)
  2 - level Cluster Sampling design
  With (40, 126) clusters.
  dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2)
  Probabilities:
      Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
  0.003669 0.037743 0.052840 0.042390 0.052840 0.052840 
  Population size (PSUs): 757 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "pw"       "fpc1"     "fpc2"    
  
  api> svymean(~api00, dclus2)
          mean     SE
  api00 670.81 30.099
  
  api> svytotal(~enroll, dclus2, na.rm=TRUE)
           total     SE
  enroll 2639273 799638
  
  api> # two-stage `with replacement'
  api> dclus2wr<-svydesign(id=~dnum+snum, weights=~pw, data=apiclus2)
  
  api> summary(dclus2wr)
  2 - level Cluster Sampling design (with replacement)
  With (40, 126) clusters.
  dclus2wr<-svydesign(id=~dnum+snum, weights=~pw, data=apiclus2)
  Probabilities:
      Min.  1st Qu.   Median     Mean  3rd Qu.     Max. 
  0.003669 0.037743 0.052840 0.042390 0.052840 0.052840 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "pw"       "fpc1"     "fpc2"    
  
  api> svymean(~api00, dclus2wr)
          mean     SE
  api00 670.81 30.712
  
  api> svytotal(~enroll, dclus2wr, na.rm=TRUE)
           total     SE
  enroll 2639273 820261
  
  api> # convert to replicate weights
  api> rclus1<-as.svrepdesign(dclus1)
  
  api> summary(rclus1)
  Call: as.svrepdesign.default(dclus1)
  Unstratified cluster jacknife (JK1) with 15 replicates.
  Variables: 
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> svymean(~api00, rclus1)
          mean     SE
  api00 644.17 26.329
  
  api> svytotal(~enroll, rclus1, na.rm=TRUE)
           total     SE
  enroll 3404940 932235
  
  api> # post-stratify on school type
  api> pop.types<-xtabs(~stype, data=apipop)
  
  api> rclus1p<-postStratify(rclus1, ~stype, pop.types)
  
  api> dclus1p<-postStratify(dclus1, ~stype, pop.types)
  
  api> summary(dclus1p)
  1 - level Cluster Sampling design
  With (15) clusters.
  dclus1p<-postStratify(dclus1, ~stype, pop.types)
  Probabilities:
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
  0.01854 0.03257 0.03257 0.03040 0.03257 0.03257 
  Population size (PSUs): 757 
  Data variables:
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> summary(rclus1p)
  Call: rclus1p<-postStratify(rclus1, ~stype, pop.types)
  Unstratified cluster jacknife (JK1) with 15 replicates.
  Variables: 
   [1] "cds"      "stype"    "name"     "sname"    "snum"     "dname"   
   [7] "dnum"     "cname"    "cnum"     "flag"     "pcttest"  "api00"   
  [13] "api99"    "target"   "growth"   "sch.wide" "comp.imp" "both"    
  [19] "awards"   "meals"    "ell"      "yr.rnd"   "mobility" "acs.k3"  
  [25] "acs.46"   "acs.core" "pct.resp" "not.hsg"  "hsg"      "some.col"
  [31] "col.grad" "grad.sch" "avg.ed"   "full"     "emer"     "enroll"  
  [37] "api.stu"  "fpc"      "pw"      
  
  api> svymean(~api00, dclus1p)
          mean     SE
  api00 642.31 23.921
  
  api> svytotal(~enroll, dclus1p, na.rm=TRUE)
           total     SE
  enroll 3680893 406293
  
  api> svymean(~api00, rclus1p)
          mean     SE
  api00 642.31 26.934
  
  api> svytotal(~enroll, rclus1p, na.rm=TRUE)
           total     SE
  enroll 3680893 473431
  > 
  > proc.time()
     user  system elapsed 
     1.53    0.17    1.68 
Running the tests in 'tests/caleg.R' failed.
Complete output:
  > ##
  > ## Calibration examples
  > ##
  > 
  > 
  > ## Example of calibration to first-stage clusters
  > 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
  
  > data(api)
  > 
  > clusters<-table(apiclus2$dnum)
  > clusters<-clusters[clusters>1 & names(clusters)!="639"]
  > apiclus2a<-subset(apiclus2, dnum %in% as.numeric(names(clusters)))
  > 
  > dclus2<-svydesign(id=~dnum+snum, fpc=~fpc1+fpc2, data=apiclus2a)
  > 
  > popclusters<-subset(apipop, dnum %in% as.numeric(names(clusters)))
  > 
  > pop<-lapply(as.numeric(names(clusters)), function(cluster) {
  +   colSums(model.matrix(~api99, model.frame(~api99, subset(popclusters, dnum %in% cluster))))})
  > 
  > names(pop)<-names(clusters)
  > 
  > dclus2g<-calibrate(dclus2, ~api99, pop,stage=1)
  > 
  > svymean(~api99, dclus2)
          mean     SE
  api99 642.14 31.434
  > svymean(~api99, dclus2g)
          mean    SE
  api99 654.49 29.82
  > 
  > round(svyby(~api99, ~dnum, design=dclus2, svymean),4)
      dnum    api99      se
  83    83 694.3333  0.0000
  132  132 505.0000  0.0000
  152  152 574.0000  0.0000
  173  173 894.7500  0.0000
  198  198 533.7500  0.0000
  200  200 589.8000  6.8335
  228  228 477.0000  0.0000
  295  295 646.4000  0.0000
  302  302 903.5000  0.0000
  403  403 852.4000  0.0000
  452  452 533.0000  0.0000
  480  480 614.2000  0.0000
  523  523 580.5000  0.0000
  534  534 564.6000  0.0000
  549  549 896.2000  0.0000
  552  552 730.0000  0.0000
  570  570 518.4000  7.5478
  575  575 800.8000  4.2513
  596  596 785.6000  2.4155
  620  620 591.6000 10.5869
  638  638 560.2000  4.0954
  674  674 760.0000  0.0000
  679  679 610.2500  0.0000
  687  687 718.6667  0.0000
  701  701 651.5000  0.0000
  711  711 690.5000  0.0000
  731  731 702.0000  2.1744
  768  768 562.5000  0.0000
  781  781 854.4000  0.7456
  > 
  > round(svyby(~api99, ~dnum, design=dclus2g, svymean),4)
      dnum    api99 se
  83    83 694.3333  0
  132  132 505.0000  0
  152  152 574.0000  0
  173  173 894.7500  0
  198  198 533.7500  0
  200  200 567.5455  0
  228  228 477.0000  0
  295  295 646.4000  0
  302  302 903.5000  0
  403  403 852.4000  0
  452  452 533.0000  0
  480  480 614.2000  0
  523  523 580.5000  0
  534  534 564.6000  0
  549  549 896.2000  0
  552  552 730.0000  0
  570  570 548.9444  0
  575  575 824.5357  0
  596  596 787.5714  0
  620  620 609.3750  0
  638  638 585.6429  0
  674  674 760.0000  0
  679  679 610.2500  0
  687  687 718.6667  0
  701  701 651.5000  0
  711  711 690.5000  0
  731  731 700.6667  0
  768  768 562.5000  0
  781  781 851.0000  0
  > 
  > ## Averaging to first stage
  > 
  > dclus1<- svydesign(id = ~dnum, weights = ~pw, data = apiclus1, fpc = ~fpc)
  > pop<-colSums(cbind(1,apipop$enroll),na.rm=TRUE)
  > 
  > dclus1g<-calibrate(dclus1, ~enroll, pop, aggregate=1)
  > 
  > svytotal(~enroll,dclus1g)
           total SE
  enroll 3811472  0
  > svytotal(~api.stu,dclus1g)
            total    SE
  api.stu 3242857 38967
  > 
  > #variation within clusters should be zero
  > all.equal(0, max(ave(weights(dclus1g),dclus1g$cluster,FUN=var),na.rm=TRUE))
  [1] TRUE
  > 
  > ##bounded weights
  >  dclus1g<-calibrate(dclus1, ~enroll, pop)
  >  range(weights(dclus1g)/weights(dclus1))
  [1] 0.7906782 1.7891164
  >  dclus1gb<-calibrate(dclus1, ~enroll, pop, bounds=c(.6,1.5))
  >  range(weights(dclus1gb)/weights(dclus1))
  [1] 0.7198751 1.5000000
  > 
  > ## Ratio estimators
  > dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  > svytotal(~api.stu,dstrat)
            total    SE
  api.stu 3086009 99477
  > common<-svyratio(~api.stu, ~enroll, dstrat, separate=FALSE)
  > total.enroll<-sum(apipop$enroll,na.rm=TRUE)
  > predict(common, total=total.enroll)
  $total
           enroll
  api.stu 3190038
  
  $se
            enroll
  api.stu 29565.98
  
  > dstratg<-calibrate(dstrat,~enroll-1, total.enroll, variance=1)
  > svytotal(~api.stu, dstratg)
            total    SE
  api.stu 3190038 29566
  > 
  > ## postStratify vs calibrate in stratified sample (Ben French)
  > set.seed(17)
  > dat<-data.frame(y=rep(0:1,each=100),x=rnorm(200)+2*rep(0:1,each=100),
  +                 z=rbinom(200,1,.2), fpc=rep(c(100,10000),each=100))
  > dat$w<-ifelse(dat$y,dat$z,1-dat$z)
  > popw<-data.frame(w=c("0","1"), Freq=c(2000,8000))
  >  des<-svydesign(id=~1,fpc=~fpc, data=dat,strata=~y)
  > postStratify(des,~w,popw)->dps
  > dcal<-calibrate(des,~factor(w), pop=c(10000,8000))
  > 
  > all.equal(SE(svymean(~x,dcal)),SE(svymean(~x,dps)))
  [1] TRUE
  > 
  > ## missing data in calibrated design
  > dps$variables$z[1]<-NA
  > summary(svyglm(y~z+x,design=dps,family=quasibinomial))
  
  Call:
  svyglm(formula = y ~ z + x, design = dps, family = quasibinomial)
  
  Survey design:
  postStratify(des, ~w, popw)
  
  Coefficients:
              Estimate Std. Error t value Pr(>|t|)    
  (Intercept)  -0.1203     0.3380  -0.356    0.722    
  z             6.2118     0.6451   9.630   <2e-16 ***
  x             2.2602     0.2514   8.992   <2e-16 ***
  ---
  Signif. codes:  0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
  
  (Dispersion parameter for quasibinomial family taken to be 1.919987)
  
  Number of Fisher Scoring iterations: 9
  
  > 
  > ## Ratio estimator using the heteroskedasticity parameter (Daniel Oehm)
  > # should match the ratio estmate above
  > dstratgh <- calibrate(dstrat,~enroll-1, total.enroll, variance=apistrat$enroll)
  > svytotal(~api.stu, dstratgh)
            total    SE
  api.stu 3190038 29566
  > 
  > ## individual boundary constraints as multiplicative values (Daniel Oehm)
  > bnds <- list(
  +   lower = c(1, 1, rep(-Inf, nrow(apistrat)-2)), 
  +   upper = c(1, 1, rep(Inf, nrow(apistrat)-2))) # the first two weights will remain unchanged the others are free to move
  > lapply(bnds, head)
  $lower
  [1]    1    1 -Inf -Inf -Inf -Inf
  
  $upper
  [1]   1   1 Inf Inf Inf Inf
  
  > dstratg1<-calibrate(dstrat, ~enroll-1, total.enroll, bounds = bnds, variance=apistrat$enroll)
  > svytotal(~api.stu, dstratg1)
            total    SE
  api.stu 3190133 29561
  > head(weights(dstrat))
      1     2     3     4     5     6 
  44.21 44.21 44.21 44.21 44.21 44.21 
  > head(weights(dstratg1))
         1        2        3        4        5        6 
  44.21000 44.21000 45.72055 45.72055 45.72055 45.72055 
  > all.equal(weights(dstrat)[1:2], weights(dstratg1)[1:2])
  [1] TRUE
  > 
  > ## individual boundary constraints as constant values (Daniel Oehm)
  > bnds <- list(
  +   lower = c(44.21, 44.21, rep(-Inf, nrow(apistrat)-2)), 
  +   upper = c(44.21, 44.21, rep(Inf, nrow(apistrat)-2))) # the first two weights will remain unchanged
  > lapply(bnds, head)
  $lower
  [1] 44.21 44.21  -Inf  -Inf  -Inf  -Inf
  
  $upper
  [1] 44.21 44.21   Inf   Inf   Inf   Inf
  
  > dstratg2<-calibrate(dstrat, ~enroll-1, total.enroll, bounds = bnds, bounds.const = TRUE, variance=apistrat$enroll)
  > svytotal(~api.stu, dstratg2)
            total    SE
  api.stu 3190133 29561
  > head(weights(dstrat))
      1     2     3     4     5     6 
  44.21 44.21 44.21 44.21 44.21 44.21 
  > head(weights(dstratg2))
         1        2        3        4        5        6 
  44.21000 44.21000 45.72055 45.72055 45.72055 45.72055 
  > all.equal(round(weights(dstrat)[1:2], 8), round(weights(dstratg2)[1:2]), 8) # minor rounding error but all good
  [1] TRUE
  > 
  > # sparse matrix support (Daniel Oehm)
  > dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  > pop.totals<-c(`(Intercept)`=6194, stypeH=755, stypeM=1018)
  > dclus1g<-calibrate(dclus1, ~stype, pop.totals)
  > svymean(~api00, dclus1g)
          mean     SE
  api00 642.31 23.921
  > svytotal(~enroll, dclus1g)
           total     SE
  enroll 3680893 406293
  > 
  > pop.totals<-c(`(Intercept)`=6194, stypeH=755, stypeM=1018)
  > dclus1g<-calibrate(dclus1, ~stype, pop.totals, sparse = TRUE)
  > svymean(~api00, dclus1g)
          mean     SE
  api00 642.31 23.921
  > svytotal(~enroll, dclus1g)
           total     SE
  enroll 3680893 406293
  > 
  > pop.totals<-c(`(Intercept)`=6194, stypeH=755, stypeM=1018)
  > dclus1g<-calibrate(dclus1, ~stype, pop.totals, sparse = TRUE, calfun = "raking")
  > svymean(~api00, dclus1g)
          mean     SE
  api00 642.31 23.921
  > svytotal(~enroll, dclus1g)
           total     SE
  enroll 3680893 406293
  > 
  > proc.time()
     user  system elapsed 
     2.59    0.21    2.79 
Running the tests in 'tests/contrast-replicates.R' failed.
Complete output:
  > ## test use of replicates in svyby, svycontrast
  > 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
  
  > 
  > data(api)
  > dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  > rclus1<-as.svrepdesign(dclus1)
  > 
  > meanlogs_without<-svyby(~log(enroll),~stype,svymean, design=rclus1,covmat=TRUE)
  > c_without<-svycontrast(meanlogs_without, quote(exp(E-H)))
  > vcov(c_without)
             contrast
  contrast 0.06862947
  > 
  > meanlogs_with<-svyby(~log(enroll),~stype,svymean, design=rclus1,covmat=TRUE,return.replicates=TRUE)
  > 
  > c_with<-svycontrast(meanlogs_with, quote(exp(E-H)))
  > 
  > v_with<- vcov(rclus1, c_with$replicates)
  > 
  > r<- attr(meanlogs_with, "replicates")
  > vr_with<-vcov(rclus1,exp(r[,1]-r[,2]))
  > 
  > stopifnot(all.equal(as.numeric(v_with),as.numeric(vr_with)))
  > stopifnot(all.equal(as.numeric(v_with),as.numeric(vcov(c_with))))
  > 
  > proc.time()
     user  system elapsed 
     1.07    0.09    1.12 
Running the tests in 'tests/coxph-termtest.R' failed.
Complete output:
  > 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(survival)
  > set.seed(2021-6-25)
  > test1 <- list(time=c(4,3,1,1,2,2,3),
  +               status=c(1,1,1,0,1,1,0),
  +               x1=as.factor(rbinom(7, 2, 0.5)),
  +               x=c(0,2,1,1,1,0,0))
  > # Fit a stratified model
  > mod_c <- coxph(Surv(time, status) ~ x1 + x, test1)
  > mod_d <- coxph(Surv(time, status) ~ x + x1, test1)
  > stopifnot(all.equal(regTermTest(mod_c, ~x1, df = Inf)[c("chisq","df","test.terms","p")],
  + regTermTest(mod_d, ~x1, df = Inf)[c("chisq","df","test.terms","p")]))
  > 
  > data(pbc, package="survival")
  > 
  > pbc$randomized<-with(pbc, !is.na(trt) & trt>0)
  > biasmodel<-glm(randomized~age*edema,data=pbc,family=binomial)
  > pbc$randprob<-fitted(biasmodel)
  > if (is.null(pbc$albumin)) pbc$albumin<-pbc$alb ##pre2.9.0
  > 
  > dpbc<-svydesign(id=~1, prob=~randprob, strata=~edema, data=subset(pbc,randomized))
  > library(splines)
  > model<-svycoxph(formula = Surv(time, status > 0) ~ bili + protime + albumin+ns(bili,4)[,1:3], design = dpbc)
  > test<-regTermTest(model, ~ns(bili,4)[,1:3],method="LRT")
  > stopifnot(all.equal(test$chisq, 47.314, tolerance=1e-4))
  > stopifnot(all.equal(test$lambda, c(1.4764260, 1.0109836, 0.6923415),tolerance=1e-4))
  > 
  > proc.time()
     user  system elapsed 
     1.03    0.07    1.09 
Running the tests in 'tests/glm-scoping.R' failed.
Complete output:
  > ## bug report from Thomas Leeper, fixed in version 3.32-3
  > 
  > 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
  
  > data(api)
  > dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  > 
  > # pass `family` directly (WORKS!)
  > svyglm(api00~ell+meals+mobility, design=dstrat, family = gaussian())
  Stratified Independent Sampling design
  svydesign(id = ~1, strata = ~stype, weights = ~pw, data = apistrat, 
      fpc = ~fpc)
  
  Call:  svyglm(formula = api00 ~ ell + meals + mobility, design = dstrat, 
      family = gaussian())
  
  Coefficients:
  (Intercept)          ell        meals     mobility  
     820.8873      -0.4806      -3.1415       0.2257  
  
  Degrees of Freedom: 199 Total (i.e. Null);  194 Residual
  Null Deviance:	    3023000 
  Residual Deviance: 1029000 	AIC: 2308
  > 
  > # passing `family` via ... (WORKS!)
  > myfun1 <- function(formula, design, ...) {
  +     svyglm(formula, design = design, ...)
  + }
  > myfun1(api00~ell+meals+mobility, design=dstrat, family = gaussian())
  Stratified Independent Sampling design
  svydesign(id = ~1, strata = ~stype, weights = ~pw, data = apistrat, 
      fpc = ~fpc)
  
  Call:  svyglm(formula = formula, design = design, family = ..1)
  
  Coefficients:
  (Intercept)          ell        meals     mobility  
     820.8873      -0.4806      -3.1415       0.2257  
  
  Degrees of Freedom: 199 Total (i.e. Null);  194 Residual
  Null Deviance:	    3023000 
  Residual Deviance: 1029000 	AIC: 2308
  > 
  > # passing `family` via default argument (DOES NOT WORK!)
  > myfun2 <- function(formula, design, family = gaussian()) {
  +     svyglm(formula, design = design, family = family)
  + }
  > myfun2(api00~ell+meals+mobility, design=dstrat, family = gaussian())
  Stratified Independent Sampling design
  svydesign(id = ~1, strata = ~stype, weights = ~pw, data = apistrat, 
      fpc = ~fpc)
  
  Call:  svyglm(formula = formula, design = design, family = family)
  
  Coefficients:
  (Intercept)          ell        meals     mobility  
     820.8873      -0.4806      -3.1415       0.2257  
  
  Degrees of Freedom: 199 Total (i.e. Null);  194 Residual
  Null Deviance:	    3023000 
  Residual Deviance: 1029000 	AIC: 2308
  > 
  > proc.time()
     user  system elapsed 
     1.09    0.14    1.20 
Running the tests in 'tests/multistage.R' failed.
Complete output:
  > ## 
  > ## Check that multistage samples still work
  > ##
  > 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
  
  > example(mu284)
  
  mu284> data(mu284)
  
  mu284> (dmu284<-svydesign(id=~id1+id2,fpc=~n1+n2, data=mu284))
  2 - level Cluster Sampling design
  With (5, 15) clusters.
  (dmu284<-svydesign(id=~id1+id2,fpc=~n1+n2, data=mu284))
  
  mu284> (ytotal<-svytotal(~y1, dmu284))
     total     SE
  y1 15080 2274.3
  
  mu284> vcov(ytotal)
          y1
  y1 5172234
  > 
  > 
  > proc.time()
     user  system elapsed 
     1.10    0.14    1.23 
Running the tests in 'tests/nwts-cch.R' failed.
Complete output:
  > 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(survival)
  > data(nwtco)
  > 
  > ntwco<-subset(nwtco, !is.na(edrel))
  > 
  > load("nwtco-subcohort.rda")
  > nwtco$subcohort<-subcohort
  > 
  > d_BorganII <- twophase(id=list(~seqno,~seqno),
  +                        strata=list(NULL,~interaction(instit,rel)),
  +                        data=nwtco, subset=~I(rel |subcohort))
  > 
  > ##Coefficient results same as Splus with code from
  > ## http://faculty.washington.edu/norm/software.html
  > ## SE slightly larger due to using sandwich variance.
  > 
  > svycoxph(Surv(edrel, rel)~factor(stage)+factor(histol)+I(age/12), design=d_BorganII)
  Call:
  svycoxph(formula = Surv(edrel, rel) ~ factor(stage) + factor(histol) + 
      I(age/12), design = d_BorganII)
  
                     coef exp(coef) se(coef) robust se      z        p
  factor(stage)2  0.46286   1.58861  0.23762   0.18087  2.559  0.01049
  factor(stage)3  0.58309   1.79156  0.23965   0.17848  3.267  0.00109
  factor(stage)4  1.05967   2.88541  0.26182   0.20524  5.163 2.43e-07
  factor(histol)2 1.59744   4.94035  0.17688   0.13342 11.973  < 2e-16
  I(age/12)       0.02994   1.03039  0.02942   0.03337  0.897  0.36972
  
  Likelihood ratio test=  on 5 df, p=
  n= 1062, number of events= 571 
  > 
  > ##
  > ## This gives higher standard errors. calibrate() does not recompute the
  > ## finite population correction if a calibration variable happens to predict
  > ## sampling perfectly. It probably should.
  > ##
  > d_BorganIIps<-calibrate(twophase(id=list(~seqno,~seqno),
  +                            strata=list(NULL,~rel),
  +                            data=nwtco, subset=~I(rel |subcohort)), 
  +                         phase=2, formula=~interaction(instit,rel),
  +                         epsilon=1e-10)
  > 
  > svycoxph(Surv(edrel, rel)~factor(stage)+factor(histol)+I(age/12), design=d_BorganIIps)
  Call:
  svycoxph(formula = Surv(edrel, rel) ~ factor(stage) + factor(histol) + 
      I(age/12), design = d_BorganIIps)
  
                     coef exp(coef) se(coef) robust se      z        p
  factor(stage)2  0.46286   1.58861  0.23762   0.18076  2.561  0.01045
  factor(stage)3  0.58309   1.79156  0.23965   0.17838  3.269  0.00108
  factor(stage)4  1.05967   2.88541  0.26182   0.20513  5.166 2.39e-07
  factor(histol)2 1.59744   4.94035  0.17688   0.13044 12.246  < 2e-16
  I(age/12)       0.02994   1.03039  0.02942   0.03331  0.899  0.36876
  
  Likelihood ratio test=  on 5 df, p=
  n= 1062, number of events= 571 
  > 
  > proc.time()
     user  system elapsed 
     1.71    0.23    1.93 
Running the tests in 'tests/qrule-swiss.R' failed.
Complete output:
  > 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
  
  > 
  > data_no_strat <- data.frame(x = 1:10, id = 1:10, fpc = 10, probs = 1)
  > 
  > design_no_strat <- svydesign(id = ~id, 
  +                              probs = ~probs, 
  +                              data = data_no_strat, 
  +                              fpc = ~fpc)
  > 
  > quantiles <- c(0.01, 0.05, 0.1, 0.15, seq(21, 81, 10)*0.01, 0.85, 0.9, 0.95, 0.99)
  > 
  > res <- svyquantile(~x, design_no_strat, quantiles, ci = TRUE,
  +             interval.type = "mean", qrule = "hf1")
  > 
  > stopifnot(all(diff(res$x[,"quantile"])>=0))
  > 
  > 
  > 
  > proc.time()
     user  system elapsed 
     1.00    0.15    1.09 
Running the tests in 'tests/quantile.R' failed.
Complete output:
  > 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
  
  > set.seed(42)
  > 
  > df<-data.frame(x=exp(rnorm(1000)))
  > df$y<-round(df$x,1)
  > ddf<-svydesign(id=~1,data=df)
  Warning message:
  In svydesign.default(id = ~1, data = df) :
    No weights or probabilities supplied, assuming equal probability
  > rdf<-as.svrepdesign(ddf)
  > 
  > SE(oldsvyquantile(~x,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE))
        0.01        0.1        0.5        0.9       0.99 
  0.01543792 0.01264453 0.03386225 0.16131948 2.10605799 
  > 
  > SE(oldsvyquantile(~x,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE))
                 x
  q0.01 0.01554946
  q0.1  0.01425828
  q0.5  0.03428012
  q0.9  0.16457488
  q0.99 1.88672412
  > 
  > SE(oldsvyquantile(~x,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,df=Inf))
        0.01        0.1        0.5        0.9       0.99 
  0.01545209 0.01265608 0.03388011 0.16145776 2.10061576 
  > 
  > SE(oldsvyquantile(~x,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,df=Inf))
                 x
  q0.01 0.01556240
  q0.1  0.01420086
  q0.5  0.03430175
  q0.9  0.16461019
  q0.99 1.88818131
  > 
  > 
  > oldsvyquantile(~y,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,ties="rounded",interval.type="betaWald")
  $quantiles
          0.01       0.1       0.5  0.9 0.99
  y 0.02352941 0.2230769 0.9340909 3.55  9.4
  
  $CIs
  , , y
  
               0.01       0.1       0.5      0.9      0.99
  (lower 0.01594200 0.2020115 0.8578143 3.207543  7.568142
  upper) 0.03287947 0.2467045 1.0059815 3.862241 14.978632
  
  
  > 
  > oldsvyquantile(~y,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE)
  Statistic:
          y
  q0.01 0.1
  q0.1  0.3
  q0.5  1.0
  q0.9  3.6
  q0.99 9.4
  SE:
                 y
  q0.01 0.02547977
  q0.1  0.02547977
  q0.5  0.02547977
  q0.9  0.15287859
  q0.99 1.88302540
  > 
  > oldsvyquantile(~y,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,ties="rounded",interval.type="betaWald",df=Inf)
  $quantiles
          0.01       0.1       0.5  0.9 0.99
  y 0.02352941 0.2230769 0.9340909 3.55  9.4
  
  $CIs
  , , y
  
               0.01       0.1       0.5      0.9      0.99
  (lower 0.01594200 0.2020115 0.8578143 3.207543  7.568142
  upper) 0.03287947 0.2467045 1.0059815 3.862241 14.978632
  
  
  > 
  > oldsvyquantile(~y,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE, df=Inf)
  Statistic:
          y
  q0.01 0.1
  q0.1  0.3
  q0.5  1.0
  q0.9  3.6
  q0.99 9.4
  SE:
                 y
  q0.01 0.02551067
  q0.1  0.02551067
  q0.5  0.02551067
  q0.9  0.15306404
  q0.99 1.88450896
  > 
  > 
  > 
  > df<-data.frame(x=exp(rnorm(20)))
  > df$y<-round(df$x,1)
  > ddf<-svydesign(id=~1,data=df)
  Warning message:
  In svydesign.default(id = ~1, data = df) :
    No weights or probabilities supplied, assuming equal probability
  > rdf<-as.svrepdesign(ddf)
  > SE(oldsvyquantile(~x,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE))
        0.01        0.1        0.5        0.9       0.99 
  0.03576771 0.07329496 0.30149917 2.03440784 1.88468597 
  > 
  > SE(oldsvyquantile(~x,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE))
                 x
  q0.01 0.00000000
  q0.1  0.04598541
  q0.5  0.25943731
  q0.9  2.12343073
  q0.99 1.91998924
  > 
  > SE(oldsvyquantile(~x,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,df=Inf))
        0.01        0.1        0.5        0.9       0.99 
  0.03637398 0.07470310 0.29938115 2.16381289 2.00708994 
  > 
  > SE(oldsvyquantile(~x,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,df=Inf))
                 x
  q0.01 0.00000000
  q0.1  0.04732818
  q0.5  0.24957966
  q0.9  2.25211815
  q0.99 2.04043154
  > 
  > 
  > oldsvyquantile(~y,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,ties="rounded",interval.type="betaWald")
  $quantiles
    0.01  0.1  0.5 0.9 0.99
  y  0.1 0.15 0.75 2.4 8.68
  
  $CIs
  , , y
  
             0.01       0.1       0.5      0.9       0.99
  (lower 0.100000 0.1000000 0.3674054 1.352279  0.5674674
  upper) 1.132533 0.3464541 1.6303784 8.473337 10.2000000
  
  
  > 
  > oldsvyquantile(~y,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE)
  Statistic:
           y
  q0.01 0.10
  q0.1  0.20
  q0.5  0.80
  q0.9  2.40
  q0.99 8.68
  SE:
                 y
  q0.01 0.00000000
  q0.1  0.02611112
  q0.5  0.26542051
  q0.9  2.10908603
  q0.99 1.91777710
  > 
  > oldsvyquantile(~y,ddf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE,ties="rounded",interval.type="betaWald",df=Inf)
  $quantiles
    0.01  0.1  0.5 0.9 0.99
  y  0.1 0.15 0.75 2.4 8.68
  
  $CIs
  , , y
  
             0.01       0.1       0.5      0.9       0.99
  (lower 0.100000 0.1000000 0.3674054 1.352279  0.5674674
  upper) 1.132533 0.3464541 1.6303784 8.473337 10.2000000
  
  
  > 
  > oldsvyquantile(~y,rdf, c(0.01,0.1,0.5,0.9,0.99),ci=TRUE, df=Inf)
  Statistic:
           y
  q0.01 0.10
  q0.1  0.20
  q0.5  0.80
  q0.9  2.40
  q0.99 8.68
  SE:
                 y
  q0.01 0.00000000
  q0.1  0.02551067
  q0.5  0.25244616
  q0.9  2.23558589
  q0.99 2.03881114
  > 
  > proc.time()
     user  system elapsed 
     1.67    0.15    1.81 
Running the tests in 'tests/rakecheck.R' failed.
Complete output:
  > 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
  
  > 
  > data(api)
  > dclus1 <- svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  > rclus1 <- as.svrepdesign(dclus1)
  > 
  > ## population marginal totals for each stratum
  > pop.types <- data.frame(stype=c("E","H","M"), Freq=c(4421,755,1018))
  > pop.schwide <- data.frame(sch.wide=c("No","Yes"), Freq=c(1072,5122))
  > 
  > rclus1r <- rake(rclus1, list(~stype,~sch.wide), list(pop.types, pop.schwide))
  > 
  > svymean(~api00, rclus1r)
          mean     SE
  api00 641.23 26.873
  > svytotal(~enroll, rclus1r)
           total     SE
  enroll 3647300 463511
  > 
  > ff<-~stype+sch.wide
  > poptotals<-colSums(model.matrix(ff,model.frame(ff,apipop)))
  > rclus1g<-calibrate(rclus1, ~stype+sch.wide, poptotals,calfun="raking")
  > 
  > svymean(~api00,rclus1g)
          mean     SE
  api00 641.23 26.874
  > svytotal(~enroll,rclus1g)
           total     SE
  enroll 3647280 463582
  > 
  > summary(weights(rclus1g)/weights(rclus1r))
         V1           V2          V3          V4           V5          V6   
   Min.   :1    Min.   :1   Min.   :1   Min.   :1    Min.   :1   Min.   :1  
   1st Qu.:1    1st Qu.:1   1st Qu.:1   1st Qu.:1    1st Qu.:1   1st Qu.:1  
   Median :1    Median :1   Median :1   Median :1    Median :1   Median :1  
   Mean   :1    Mean   :1   Mean   :1   Mean   :1    Mean   :1   Mean   :1  
   3rd Qu.:1    3rd Qu.:1   3rd Qu.:1   3rd Qu.:1    3rd Qu.:1   3rd Qu.:1  
   Max.   :1    Max.   :1   Max.   :1   Max.   :1    Max.   :1   Max.   :1  
   NA's   :11   NA's   :4   NA's   :2   NA's   :13   NA's   :2   NA's   :4  
         V7          V8           V9         V10          V11    
   Min.   :1   Min.   :1    Min.   :1   Min.   :1    Min.   :1   
   1st Qu.:1   1st Qu.:1    1st Qu.:1   1st Qu.:1    1st Qu.:1   
   Median :1   Median :1    Median :1   Median :1    Median :1   
   Mean   :1   Mean   :1    Mean   :1   Mean   :1    Mean   :1   
   3rd Qu.:1   3rd Qu.:1    3rd Qu.:1   3rd Qu.:1    3rd Qu.:1   
   Max.   :1   Max.   :1    Max.   :1   Max.   :1    Max.   :1   
   NA's   :4   NA's   :16   NA's   :9   NA's   :34   NA's   :21  
        V12              V13          V14         V15    
   Min.   :0.9997   Min.   :1    Min.   :1   Min.   :1   
   1st Qu.:1.0001   1st Qu.:1    1st Qu.:1   1st Qu.:1   
   Median :1.0001   Median :1    Median :1   Median :1   
   Mean   :1.0000   Mean   :1    Mean   :1   Mean   :1   
   3rd Qu.:1.0001   3rd Qu.:1    3rd Qu.:1   3rd Qu.:1   
   Max.   :1.0002   Max.   :1    Max.   :1   Max.   :1   
   NA's   :37       NA's   :13   NA's   :1   NA's   :12  
  > 
  > 
  > ## Do it for a design without replicate weights
  > dclus1r<-rake(dclus1, list(~stype,~sch.wide), list(pop.types, pop.schwide))
  > 
  > svymean(~api00, dclus1r)
          mean     SE
  api00 641.23 23.704
  > svytotal(~enroll, dclus1r)
           total     SE
  enroll 3647300 400603
  > 
  > dclus1g<-calibrate(dclus1, ~stype+sch.wide, poptotals,calfun="raking")
  > 
  > svymean(~api00,dclus1g)
          mean     SE
  api00 641.23 23.704
  > svytotal(~enroll,dclus1g)
           total     SE
  enroll 3647280 400603
  > 
  > summary(weights(dclus1g)/weights(dclus1r))
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
        1       1       1       1       1       1 
  > 
  > 
  > 
  > ## Example of raking with partial joint distributions
  > pop.table <- xtabs(~stype+sch.wide,apipop)
  > pop.imp<-data.frame(comp.imp=c("No","Yes"),Freq=c(1712,4482))
  > dclus1r2<-rake(dclus1, list(~stype+sch.wide, ~comp.imp),
  +                list(pop.table, pop.imp))
  > svymean(~api00, dclus1r2)
          mean     SE
  api00 642.62 22.732
  > 
  > ff1 <-~stype*sch.wide+comp.imp
  > 
  > poptotals1<-colSums(model.matrix(ff1,model.frame(ff1,apipop)))
  > dclus1g2<-calibrate(dclus1, ~stype*sch.wide+comp.imp, poptotals1, calfun="raking")
  > 
  > svymean(~api00, dclus1g2)
          mean     SE
  api00 642.61 22.731
  > 
  > summary(weights(dclus1r2)/weights(dclus1g2))
     Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
    0.999   1.000   1.000   1.000   1.000   1.002 
  > 
  > proc.time()
     user  system elapsed 
     1.57    0.17    1.75 
Running the tests in 'tests/scoping.R' failed.
Complete output:
  > 
  > ## regression test for testing regression
  > 
  > 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
  
  > data(api)
  > 
  > dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  > 
  > 
  > f<-function(){
  +   form<-acs.46~stype
  +   svyglm(formula=form, design = dstrat)  
  + }
  > 
  > g<-function(form){
  +   svyglm(formula=form, design = dstrat)  
  + }
  > f()
  Stratified Independent Sampling design
  svydesign(id = ~1, strata = ~stype, weights = ~pw, data = apistrat, 
      fpc = ~fpc)
  
  Call:  svyglm(formula = form, design = dstrat)
  
  Coefficients:
  (Intercept)       stypeH       stypeM  
      28.7449       0.7551       0.4022  
  
  Degrees of Freedom: 133 Total (i.e. Null);  129 Residual
    (66 observations deleted due to missingness)
  Null Deviance:	    1838 
  Residual Deviance: 1835 	AIC: 719.8
  > g(acs.46~stype)
  Stratified Independent Sampling design
  svydesign(id = ~1, strata = ~stype, weights = ~pw, data = apistrat, 
      fpc = ~fpc)
  
  Call:  svyglm(formula = form, design = dstrat)
  
  Coefficients:
  (Intercept)       stypeH       stypeM  
      28.7449       0.7551       0.4022  
  
  Degrees of Freedom: 133 Total (i.e. Null);  129 Residual
    (66 observations deleted due to missingness)
  Null Deviance:	    1838 
  Residual Deviance: 1835 	AIC: 719.8
  > 
  > f<-function(){
  +   form<-Surv(acs.46)~stype
  +   svycoxph(formula=form, design = dstrat)  
  + }
  > 
  > g<-function(form){
  +   svycoxph(formula=form, design = dstrat)  
  + }
  > 
  > f()
  Call:
  svycoxph(formula = form, design = dstrat)
  
            coef exp(coef) se(coef) robust se      z     p
  stypeH -0.6766    0.5083   1.0208    0.6652 -1.017 0.309
  stypeM -0.2509    0.7781   0.2308    0.2089 -1.201 0.230
  
  Likelihood ratio test=  on 2 df, p=
  n= 134, number of events= 134 
     (66 observations deleted due to missingness)
  > g(Surv(acs.46)~stype)
  Call:
  svycoxph(formula = form, design = dstrat)
  
            coef exp(coef) se(coef) robust se      z     p
  stypeH -0.6766    0.5083   1.0208    0.6652 -1.017 0.309
  stypeM -0.2509    0.7781   0.2308    0.2089 -1.201 0.230
  
  Likelihood ratio test=  on 2 df, p=
  n= 134, number of events= 134 
     (66 observations deleted due to missingness)
  > 
  > ## check coxph for a single predictor
  > svycoxph(Surv(acs.46)~api00,design=dstrat)
  Call:
  svycoxph(formula = Surv(acs.46) ~ api00, design = dstrat)
  
             coef exp(coef)  se(coef) robust se     z     p
  api00 6.060e-06 1.000e+00 6.244e-04 7.492e-04 0.008 0.994
  
  Likelihood ratio test=  on 1 df, p=
  n= 134, number of events= 134 
     (66 observations deleted due to missingness)
  > 
  > proc.time()
     user  system elapsed 
     0.98    0.15    1.12 
Running the tests in 'tests/survcurve.R' failed.
Complete output:
  > 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(survival)
  > 
  > pbc2<-rbind(pbc,pbc)
  > pbc2$id<-rep(1:418,2)
  > 
  > dpbc1<-svydesign(id=~1, data=pbc)
  Warning message:
  In svydesign.default(id = ~1, data = pbc) :
    No weights or probabilities supplied, assuming equal probability
  > dpbc2<-svydesign(id=~id, data=pbc2)
  Warning message:
  In svydesign.default(id = ~id, data = pbc2) :
    No weights or probabilities supplied, assuming equal probability
  > 
  > s1<-svykm(Surv(time,status>0)~1, subset(dpbc1, bili>6), se=TRUE)
  > s2<-svykm(Surv(time,status>0)~1, subset(dpbc2, bili>6), se=TRUE)
  > 
  > (c1<-confint(s1,(1:5)*365))
           0.025     0.975
  365  0.6446215 0.8594153
  730  0.5410938 0.7766848
  1095 0.2683127 0.5103356
  1460 0.1444731 0.3722001
  1825 0.1009672 0.3204713
  > (c2<-confint(s2,(1:5)*365))
           0.025     0.975
  365  0.6446215 0.8594153
  730  0.5410938 0.7766848
  1095 0.2683127 0.5103356
  1460 0.1444731 0.3722001
  1825 0.1009672 0.3204713
  > all.equal(c1, c2)
  [1] TRUE
  > 
  > m1<-svycoxph(Surv(time,status>0)~log(bili), design=dpbc1)
  > m2<-svycoxph(Surv(time,status>0)~log(bili), design=dpbc2)
  > 
  > d<-data.frame(bili=c(5,10))
  > p1<-predict(m1, se=TRUE, newdata=d,type="curve")
  > p2<-predict(m2, se=TRUE, newdata=d,type="curve")
  > 
  > (pc1<-confint(p1[[1]],(1:5)*365))
           0.025     0.975
  365  0.8410027 0.9266263
  730  0.7371114 0.8548312
  1095 0.5517779 0.7018583
  1460 0.4335073 0.5992819
  1825 0.3260899 0.5046241
  > (pc2<-confint(p2[[1]],(1:5)*365))
           0.025     0.975
  365  0.8409490 0.9267054
  730  0.7370152 0.8549432
  1095 0.5515848 0.7019513
  1460 0.4332252 0.5992968
  1825 0.3257172 0.5045795
  > all.equal(pc1, pc2)
  [1] "Mean relative difference: 0.0002070722"
  > 
  > (q1<-quantile(p1[[2]]))
  0.75  0.5 0.25 
   489  930 1492 
  > (q2<-quantile(p2[[2]]))
  0.75  0.5 0.25 
   489  930 1492 
  > all.equal(q1,q2)
  [1] TRUE
  > 
  > proc.time()
     user  system elapsed 
     2.39    0.17    2.54 
Running the tests in 'tests/svyby_se.R' failed.
Complete output:
  > 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
  
  > data(api)
  > dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  > 
  > a<-svyby(~enroll,~stype,design=dstrat,svytotal,vartype=c("ci","se"))
  > b<-svyby(~enroll,~stype,design=dstrat,svytotal,vartype=c("se","ci"))
  > 
  > 
  > stopifnot(all.equal(SE(a),SE(b)))
  > 
  > proc.time()
     user  system elapsed 
     1.06    0.06    1.12 
Running the tests in 'tests/svycontrast.R' failed.
Complete output:
  > 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
  
  > data(api)
  > dclus2<-svydesign(id=~dnum+snum, weights=~pw, data=apiclus2)
  > rclus2<-as.svrepdesign(dclus2)
  > model<-svyglm(formula = api00 ~ ell + meals + mobility, design = rclus2)
  > svycontrast(model, c(ell=1,meals=0))
           contrast     SE
  contrast  -2.0592 1.6177
  > a<-svycontrast(model, c(0,1,0,0))
  > 
  > model2<-svyglm(formula = api00 ~ ell + meals + mobility, design = rclus2,return.replicates=TRUE)
  > svycontrast(model2, c(ell=1,meals=0))
           contrast     SE
  contrast  -2.0592 1.6177
  > a2<-svycontrast(model2, c(0,1,0,0))
  > stopifnot(!is.null(a2$replicates))
  > 
  > proc.time()
     user  system elapsed 
     1.06    0.12    1.18 
Running the tests in 'tests/svyivreg-var.R' failed.
Complete output:
  > 
  > 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
  
  > data(api)
  > dstrat<-svydesign(id=~1,strata=~stype, weights=~pw, data=apistrat, fpc=~fpc)
  > a<-summary(svyglm(api00~ell+meals+mobility, design=dstrat))
  > b<- summary(svyivreg(api00~ell+meals+mobility, design=dstrat))
  > stopifnot(isTRUE(all.equal(a$cov.scaled, b$vcov)))
  > 
  > proc.time()
     user  system elapsed 
     1.07    0.15    1.23 
Running the tests in 'tests/svyivreg.R' failed.
Complete output:
  > 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(AER)
  Loading required package: car
  Loading required package: carData
  Loading required package: lmtest
  Loading required package: zoo
  
  Attaching package: 'zoo'
  
  The following objects are masked from 'package:base':
  
      as.Date, as.Date.numeric
  
  Loading required package: sandwich
  > 
  > load("cigsw.rda")
  > 
  > des<-svydesign(id=~1, weights=~wt, data=cigsw)
  > m<-svyivreg(log(packs) ~ log(rprice) + log(rincome) | log(rincome) + tdiff + I(tax/cpi), design=des)
  > 
  > all.equal(as.vector(coef(m)), c(10.42009 , -1.588135, 0.6140887),tolerance=1e-6)
  [1] TRUE
  > all.equal(as.vector(SE(m)), c( 1.047699, .3394232,  .3614382 ),tolerance=1e-6)
  [1] TRUE
  > 
  > proc.time()
     user  system elapsed 
     0.98    0.21    1.20