Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

summarise

Summarise multiple values to a single value.


Description

Summarise multiple values to a single value.

Arguments

.data

tbl A tbl_svy object

...

Name-value pairs of summary functions

.groups

Defaults to "drop_last" in srvyr meaning that the last group is peeled off, but if there are more groups they will be preserved. Other options are "drop", which drops all groups, "keep" which keeps all of them and "rowwise" which converts the object to a rowwise object (meaning calculations will be performed on each row).

.unpack

Whether to "unpack" named data.frame columns. srvyr predates dplyr's support for data.frame columns so it does not treat them the same way by default.

Details

Summarise for tbl_svy objects accepts several specialized functions. Each of the functions a variable (or two, in the case of survey_ratio), from the data.frame and default to providing the measure and its standard error.

The argument vartype can choose one or more measures of uncertainty, se for standard error, ci for confidence interval, var for variance, and cv for coefficient of variation. level specifies the level for the confidence interval.

The other arguments correspond to the analagous function arguments from the survey package.

The available functions from srvyr are:

survey_mean

Calculate the survey mean of the entire population or by groups. Based on svymean.

survey_total

Calculate the survey total of the entire population or by groups. Based on svytotal.

survey_ratio

Calculate the ratio of 2 variables in the entire population or by groups. Based on svyratio.

survey_quantile

Calculate quantiles in the entire population or by groups. Based on svyquantile.

survey_median

Calculate the median in the entire population or by groups. svyquantile.

unweighted

Calculate an unweighted estimate as you would on a regular tbl_df. Based on dplyr's summarise.

Examples

library(survey)
data(api)

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

dstrata %>%
  summarise(api99_mn = survey_mean(api99),
            api00_mn = survey_mean(api00),
            api_diff = survey_mean(api00 - api99))

dstrata_grp <- dstrata %>%
  group_by(stype)

dstrata_grp %>%
  summarise(api99_mn = survey_mean(api99),
            api00_mn = survey_mean(api00),
            api_diff = survey_mean(api00 - api99))

srvyr

'dplyr'-Like Syntax for Summary Statistics of Survey Data

v1.0.1
GPL-2 | GPL-3
Authors
Greg Freedman Ellis [aut, cre], Thomas Lumley [ctb], Tomasz Żółtak [ctb], Ben Schneider [aut, ctb], Pavel N. Krivitsky [ctb]
Initial release
2021-03-28

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.