Learn R Programming

srvyr (version 0.1.1)

survey_total: Calculate the total and its variation using survey methods

Description

Calculate totals from complex survey data. A wrapper around svytotal. survey_total should always be called from summarise.

Usage

survey_total(x = NULL, na.rm = FALSE, vartype = c("se", "ci", "var",
  "cv"), level = 0.95, ...)

Arguments

x
A variable or expression, or empty
na.rm
A logical value to indicate whether missing values should be dropped
vartype
Report variability as one or more of: standard error ("se", default), confidence interval ("ci"), variance ("var") or coefficient of variation ("cv").
level
A single number or vector of numbers indicating the confidence level
...
Ignored

Examples

Run this code
library(survey)
data(api)

dstrata <- apistrat %>%
  as_survey_design(strata = stype, weights = pw)

dstrata %>%
  summarise(enroll = survey_total(enroll),
            tot_meals = survey_total(enroll * meals / 100, vartype = c("ci", "cv")))

dstrata %>%
  group_by(awards) %>%
  summarise(api00 = survey_total(enroll))

# Leave x empty to calculate the total in each group
dstrata %>%
  group_by(awards) %>%
  summarise(pct = survey_total())

# level takes a vector for multiple levels of confidence intervals
dstrata %>%
  summarise(enroll = survey_total(enroll, vartype = "ci", level = c(0.95, 0.65)))

Run the code above in your browser using DataLab