Calculate quantiles from complex survey data. A wrapper around oldsvyquantile, which is a version of the function from before version 4.1 of the survey package, available for backwards compatibility. survey_old_quantile and survey_old_median should always be called from summarise. See Thomas Lumley's blogpost <https://notstatschat.rbind.io/2021/07/20/what-s-new-in-the-survey-package/> for more details.

survey_old_quantile(
  x,
  quantiles,
  na.rm = FALSE,
  vartype = c("se", "ci", "var", "cv"),
  level = 0.95,
  q_method = "linear",
  f = 1,
  interval_type = c("Wald", "score", "betaWald", "probability", "quantile"),
  ties = c("discrete", "rounded"),
  df = NULL,
  ...
)

survey_old_median(
  x,
  na.rm = FALSE,
  vartype = c("se", "ci"),
  level = 0.95,
  q_method = "linear",
  f = 1,
  interval_type = c("Wald", "score", "betaWald", "probability", "quantile"),
  ties = c("discrete", "rounded"),
  df = NULL,
  ...
)

Arguments

x

A variable or expression

quantiles

A vector of quantiles to calculate

na.rm

A logical value to indicate whether missing values should be dropped

vartype

NULL to report no variability (default), otherwise one or more of: standard error ("se") confidence interval ("ci") (variance and coefficient of variation not available).

level

A single number indicating the confidence level (only one level allowed)

q_method

See "method" in approxfun

f

See approxfun

interval_type

See oldsvyquantile

ties

See oldsvyquantile

df

A number indicating the degrees of freedom for t-distribution. The default, Inf uses the normal distribution (matches the survey package). Also, has no effect for type = "betaWald".

...

Ignored

Examples

library(survey)
data(api)

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

dstrata %>%
  summarise(api99 = survey_old_quantile(api99, c(0.25, 0.5, 0.75)),
            api00 = survey_old_median(api00, vartype = c("ci")))
#> # A tibble: 1 × 9
#>   api99_q25 api99_q50 api99_q75 api99_q25_se api99_q50_se api99_q75_se api00
#>       <dbl>     <dbl>     <dbl>        <dbl>        <dbl>        <dbl> <dbl>
#> 1      525.       631      727.         12.5         18.4         17.9  667.
#> # ℹ 2 more variables: api00_low <dbl>, api00_upp <dbl>

dstrata %>%
  group_by(awards) %>%
  summarise(api00 = survey_old_median(api00))
#> # A tibble: 2 × 3
#>   awards api00 api00_se
#>   <fct>  <dbl>    <dbl>
#> 1 No      641.     23.4
#> 2 Yes     671.     18.8