
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

> ## check many permutations of fpc specification
> example(fpc)

fpc> data(fpc)

fpc> fpc
  stratid psuid weight nh Nh   x
1       1     1      3  5 15 2.8
2       1     2      3  5 15 4.1
3       1     3      3  5 15 6.8
4       1     4      3  5 15 6.8
5       1     5      3  5 15 9.2
6       2     1      4  3 12 3.7
7       2     2      4  3 12 6.6
8       2     3      4  3 12 4.2

fpc> withoutfpc<-svydesign(weights=~weight, ids=~psuid, strata=~stratid, variables=~x, 
fpc+    data=fpc, nest=TRUE)

fpc> withoutfpc
Stratified Independent Sampling design (with replacement)
svydesign(weights = ~weight, ids = ~psuid, strata = ~stratid, 
    variables = ~x, data = fpc, nest = TRUE)

fpc> svymean(~x, withoutfpc)
    mean     SE
x 5.4481 0.7413

fpc> withfpc<-svydesign(weights=~weight, ids=~psuid, strata=~stratid,
fpc+ fpc=~Nh, variables=~x, data=fpc, nest=TRUE)

fpc> withfpc
Stratified Independent Sampling design
svydesign(weights = ~weight, ids = ~psuid, strata = ~stratid, 
    fpc = ~Nh, variables = ~x, data = fpc, nest = TRUE)

fpc> svymean(~x, withfpc)
    mean    SE
x 5.4481 0.616

fpc> ## Other equivalent forms 
fpc> withfpc<-svydesign(prob=~I(1/weight), ids=~psuid, strata=~stratid,
fpc+ fpc=~Nh, variables=~x, data=fpc, nest=TRUE)

fpc> svymean(~x, withfpc)
    mean    SE
x 5.4481 0.616

fpc> withfpc<-svydesign(weights=~weight, ids=~psuid, strata=~stratid,
fpc+ fpc=~I(nh/Nh), variables=~x, data=fpc, nest=TRUE)

fpc> svymean(~x, withfpc)
    mean    SE
x 5.4481 0.616

fpc> withfpc<-svydesign(weights=~weight, ids=~interaction(stratid,psuid),
fpc+ strata=~stratid, fpc=~I(nh/Nh), variables=~x, data=fpc)

fpc> svymean(~x, withfpc)
    mean    SE
x 5.4481 0.616

fpc> withfpc<-svydesign(ids=~psuid, strata=~stratid, fpc=~Nh,
fpc+  variables=~x,data=fpc,nest=TRUE)

fpc> svymean(~x, withfpc)
    mean    SE
x 5.4481 0.616

fpc> withfpc<-svydesign(ids=~psuid, strata=~stratid,
fpc+ fpc=~I(nh/Nh), variables=~x, data=fpc, nest=TRUE)

fpc> svymean(~x, withfpc)
    mean    SE
x 5.4481 0.616
> 
> 
> proc.time()
   user  system elapsed 
  0.194   0.025   0.229 
