
R version 3.1.0 (2014-04-10) -- "Spring Dance"
Copyright (C) 2014 The R Foundation for Statistical Computing
Platform: x86_64-apple-darwin13.1.0 (64-bit)

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)

Attaching package: 'survey'

The following object is masked from 'package:graphics':

    dotchart

> data(api)
> options(survey.replicates.mse=TRUE)
> dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
> rclus1<-as.svrepdesign(dclus1)
> 
> a<-svyby(~api00+api99, ~comp.imp+sch.wide,design=rclus1,svymean,
+          covmat=TRUE,drop.empty.groups=FALSE)
> b<-svyby(~api00+api99, ~comp.imp+sch.wide,design=rclus1,svymean,
+          covmat=TRUE,drop.empty.groups=TRUE)
> 
> stopifnot(all(na.omit(
+               as.vector(as.matrix(SE(a)))==sqrt(diag(vcov(a)))
+ )))
> stopifnot(all(
+               as.vector(as.matrix(SE(b)))==sqrt(diag(vcov(b)))
+               ))
> 
> rat <- svyratio(~ell+mobility, ~mobility+meals, dclus1,covmat=TRUE)
> all <- svytotal(~ell+mobility+meals, dclus1)
> 
> stopifnot(all(abs(vcov(svycontrast(all,
+                                    list(quote(ell/mobility),
+                                         quote(mobility/mobility),
+                                         quote(ell/meals),quote(mobility/meals))))
+                   -vcov(rat))<1e-10))
> 
> stopifnot(all(abs(SE(rat)-sqrt(diag(vcov(rat))))<1e-10))
> 
> rat <- svyratio(~ell+mobility, ~mobility+meals, rclus1,covmat=TRUE)
> all <- svytotal(~ell+mobility+meals, rclus1, return.replicates=TRUE)
> 
> con<-svycontrast(all,
+                  list(quote(ell/mobility),
+                       quote(mobility/mobility),
+                       quote(ell/meals),quote(mobility/meals)))
> 
> stopifnot(all(abs(survey:::svrVar(con$replicates, rclus1$scale,rclus1$rscales,mse=rclus1$mse, coef=coef(con))-vcov(rat))<1e-10))
> 
> options(survey.replicates.mse=FALSE)
> dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
> rclus1<-as.svrepdesign(dclus1)
> 
> a<-svyby(~api00+api99, ~comp.imp+sch.wide,design=rclus1,svymean,
+          covmat=TRUE,drop.empty.groups=FALSE)
> b<-svyby(~api00+api99, ~comp.imp+sch.wide,design=rclus1,svymean,
+          covmat=TRUE,drop.empty.groups=TRUE)
> 
> stopifnot(all(na.omit(
+               as.vector(as.matrix(SE(a)))==sqrt(diag(vcov(a)))
+ )))
> stopifnot(all(
+               as.vector(as.matrix(SE(b)))==sqrt(diag(vcov(b)))
+               ))
> 
> rat <- svyratio(~ell+mobility, ~mobility+meals, dclus1,covmat=TRUE)
> all <- svytotal(~ell+mobility+meals, dclus1)
> 
> stopifnot(all(abs(vcov(svycontrast(all,
+                                    list(quote(ell/mobility),
+                                         quote(mobility/mobility),
+                                         quote(ell/meals),quote(mobility/meals))))
+                   -vcov(rat))<1e-10))
> 
> stopifnot(all(abs(SE(rat)-sqrt(diag(vcov(rat))))<1e-10))
> 
> rat <- svyratio(~ell+mobility, ~mobility+meals, rclus1,covmat=TRUE)
> all <- svytotal(~ell+mobility+meals, rclus1, return.replicates=TRUE)
> 
> con<-svycontrast(all,
+                  list(quote(ell/mobility),
+                       quote(mobility/mobility),
+                       quote(ell/meals),quote(mobility/meals)))
> 
> stopifnot(all(abs(survey:::svrVar(con$replicates, rclus1$scale,rclus1$rscales,mse=rclus1$mse, coef=coef(con))-vcov(rat))<1e-10))
> 
> 
> 
> proc.time()
   user  system elapsed 
  0.299   0.027   0.333 
