Learn R Programming

capm (version 0.9.1)

SummarySurvey: Summary statistics for sample surveys

Description

Wraps functions for summary statistics from survey package.

Usage

SummarySurvey(design = NULL, variables = NULL, conf.level = 0.95, rnd = 3)

Arguments

design
an output form DesignSurvey function.
variables
character vector with the type of estimate for each variable contained in design (see details).
conf.level
the confidence level required.
rnd
the number of decimal places (round) or significant digits (signif) to be used. If NA, scientific notation is used.

Value

Matrix with survey summaries.

Details

The length of variables must be equal to the length of names(design$variables) (see examples).

References

Lumley, T. (2011). Complex surveys: A guide to analysis using R (Vol. 565). Wiley.

http://oswaldosantos.github.io/capm

Examples

Run this code
# Load data.
data(psu.ssu)
data(survey.data)

##########################################
## Example 1 (two-stage cluster design) ##
## General estimates                    ##
##########################################

# Specify the two-stage cluster design.
design <- DesignSurvey(sample = survey.data, psu.ssu = psu.ssu,
                       psu.col = 2, ssu.col = 1, psu.2cd = 20)

# Look at the variables contained in the survey design
names(design$variables)

# Specify the type of estimate for each variable
variables <- c("total", "prop", "mean", rep("prop", 2),
               "total", rep("prop", 8))

# Make sure you specify the correct type of estimate for each variable
cbind(names(design$variables), variables)

# Calculate the summary statistics for the survey.
# Uncomment the following two lines (will take some seconds).
# estimates <- SummarySurvey(design, variables = variables, rnd = 3)

##########################################
## Example 2 (two-stage cluster design) ##
## Sex-specific estimates               ##
##########################################

# Make a copy of the dataset and select some 
# variables of interest.
sample1 <- survey.data[, c(1:4, 6:7, 11)]

# Transform to numeric the "sterilized" variable in order
# to estimate its total.
sample1[, 5] <- as.character(sample1[, 5])
sample1[which(sample1$sterilized == "yes"), 5] <- 1
sample1[which(sample1[, 5] == "no"), 5] <- 0
sample1[, 5] <- as.numeric(sample1[, 5])

# Define a survey design for each sex.
design.sex <- DesignSurvey(sample = sample1, psu.ssu = psu.ssu,
                           psu.col = 2, ssu.col = 1, psu.2cd = 20)
design.f <- subset(design.sex, sex == 'Female')
design.m <- subset(design.sex, sex == 'Male')

# Look at the variables contained in the survey design
names(design.sex$variables)

# Specify the type of estimate for each variable
variables.sex <- c("total", "", "total", "prop", "prop")

# Make sure you specify the correct type of 
# estimate for each variable
cbind(names(design.sex$variables), variables.sex)

# Calculate the summary statistics for the surveys.
# Uncomment the following two lines (will take some seconds).
# estimates.f <- SummarySurvey(design.f, variables.sex, rnd = 3)
# estimates.m <- SummarySurvey(design.m, variables.sex, rnd = 3)

Run the code above in your browser using DataLab