survey package

References

Load package and data

library(survey)
data(api)

Student performance in California schools

Description:

 The Academic Performance Index is computed for all California
 schools based on standardised testing of students. The data sets
 contain information for all schools with at least 100 students and
 for various probability samples of the data.
head(apisrs)

Simple random sample example

Create survey design object from dataset

srs_design <- svydesign(id = ~ 1, fpc = ~ fpc, data = apisrs)
class(srs_design)
[1] "survey.design2" "survey.design" 
srs_design
Independent Sampling design
svydesign(id = ~1, fpc = ~fpc, data = apisrs)

Functions in survey package

svyCprod    svyboxplot  svyby   svycdf
svychisq    svyciprop   svycontrast     svycoplot
svycoxph    svydesign   svyfactanal     svyglm
svyhist     svykappa    svykm   svyloglin
svylogrank  svymean     svymle  svyolr
svyplot     svyprcomp   svyquantile     svyranktest
svyratio    svyrecvar   svysmooth   svystandardize
svytable    svytotal    svyttest    svyvar
## Population total of enroll variable (number of students enrolled)
## 3.6 million students
svytotal(~ enroll, srs_design)
         total     SE
enroll 3621074 169520

## Population mean of enroll variable (number of students enrolled)
## estimated mean school size 585
svymean(~ enroll, srs_design)
       mean   SE
enroll  585 27.4