Skip to contents

Calculates the interquartile range from complex survey data. A wrapper for taking differences of svyquantile at 0.25 and 0.75 quantiles, and meant to be called from within srvyr::summarise.

Usage

survey_IQR(x, na.rm = TRUE)

Arguments

x

A variable or expression

na.rm

logical, if TRUE missing values are removed

Value

a vector of interquartile ranges

Author

Tom Elliott

Examples

library(survey)
library(srvyr)
#> 
#> Attaching package: ‘srvyr’
#> The following object is masked from ‘package:stats’:
#> 
#>     filter
data(api)

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

dstrata %>%
    summarise(api99_iqr = survey_IQR(api99))
#> # A tibble: 1 × 1
#>   api99_iqr
#>       <dbl>
#> 1       202