Learn R Programming

survey (version 2.8-1)

svyby: Survey statistics on subsets

Description

Compute survey statistics on subsets of a survey defined by factors.

Usage

svyby(formula, by, design, FUN, ..., keep.var = FALSE, keep.names = TRUE)

Arguments

formula
A formula specifying the variables to pass to FUN
by
A formula specifying factors that define subsets, or a list of factors.
design
A svydesign or svrepdesign object
FUN
A function taking a formula and survey design object as its first two arguments.
...
Other arguments to FUN
keep.var
If FUN returns a svystat object, extract standard errors from it
keep.names
Define row names based on the subsets

Value

  • A data frame showing the factors and the results of FUN

See Also

svytable and ftable.svystat for contingency tables, ftable.svyby for pretty-printing of svyby

Examples

Run this code
data(api)
dclus1<-svydesign(id=~dnum, weights=~pw, data=apiclus1, fpc=~fpc)

svyby(~api99, ~stype, dclus1, svymean)
svyby(~api99, ~stype, dclus1, svyquantile, quantiles=0.5)
svyby(~api99, list(school.type=apiclus1$stype), dclus1, svymean)
svyby(~api99+api00, ~stype+sch.wide, dclus1, svymean, keep.var=TRUE)

rclus1<-as.svrepdesign(dclus1)

svyby(~api99, ~stype, rclus1, svrepmean)
svyby(~api99, ~stype, rclus1, svrepquantile, quantiles=0.5)
svyby(~api99, list(school.type=apiclus1$stype), rclus1, svrepmean)
svyby(~api99+api00, ~stype+sch.wide, rclus1, svrepmean, keep.var=TRUE)

Run the code above in your browser using DataLab