Learn R Programming

survey (version 2.4)

svytable: Contingency tables for survey data

Description

Contingency tables and chisquared tests of association for survey data.

Usage

svytable(formula, design, Ntotal = design$fpc, round = FALSE)
svreptable(formula, design, Ntotal = sum(weights(design, "sampling"))), round = FALSE)
svychisq(formula, design, statistic = c("F",  "Chisq"))

Arguments

formula
Model formula specifying margins for the table (using + only)
design
survey object
statistic
See Details below
Ntotal
A population total or set of population stratum totals to normalise to.
round
Should the table entries be rounded to the nearest integer?

Value

  • The table commands return an xtabs object, svychisq returns a htest object.

Details

The svytable and svreptable function compute a weighted crosstabulation. If the sampling probabilities supplied to svydesign were actual probabilities (rather than relative probabilities) this estimates a full population crosstabulation. Otherwise it estimates only relative proportions and should be normalised to some convenient total such as 100 or 1.0 by specifying the Ntotal argument. If the formula has a left-hand side the mean or sum of this variable rather than the frequency is tabulated

The Ntotal argument can be either a single number or a data frame whose first column is the sampling strata and second column the population size in each stratum. In this second case the svytable command performs `post-stratification': tabulating and scaling to the population within strata and then adding up the strata.

As with other xtabs objects, the output of svytable can be processed by ftable for more attractive display.

svychisq computes first and second-order Rao-Scott corrections to the Pearson chisquared test. The default (statistic="F") is the second-order correction. The p-values are computed with a Satterthwaite approximation to the distribution. The alternative statistic="Chisq" adjusts the Pearson chisquared statistic by a design effect estimate and then compares it to the chisquared distribution it would have under simple random sampling.

At the moment, svychisq works only for 2-dimensional tables.

References

Rao, JNK, Scott, AJ (1984) "On Chi-squared Tests For Multiway Contigency Tables with Proportions Estimated From Survey Data" Annals of Statistics 12:46-60.

Sribney WM (1998) "Two-way contingency tables for survey or clustered data" Stata Technical Bulletin 45:33-49.

See Also

xtabs, svyby for tables of means, medians, etc.

Examples

Run this code
data(api)
  xtabs(~sch.wide+stype, data=apipop)

  dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)
  summary(dclus1)

  svytable(~sch.wide+stype, dclus1)
  svychisq(~sch.wide+stype, dclus1)
  svychisq(~sch.wide+stype, dclus1, statistic="Chisq")

  rclus1 <- as.svrepdesign(dclus1)
  svreptable(~sch.wide+stype, rclus1, round=TRUE)

Run the code above in your browser using DataLab