View source: R/survey_statistics.r
survey_quantile | R Documentation |
Calculate quantiles from complex survey data. A wrapper
around svyquantile
. survey_quantile
and
survey_median
should always be called from summarise
.
survey_quantile(
x,
quantiles,
na.rm = FALSE,
vartype = c("se", "ci", "var", "cv"),
level = 0.95,
interval_type = c("mean", "beta", "xlogit", "asin", "score", "quantile"),
qrule = c("math", "school", "shahvaish", "hf1", "hf2", "hf3", "hf4", "hf5", "hf6",
"hf7", "hf8", "hf9"),
df = NULL,
...
)
survey_median(
x,
na.rm = FALSE,
vartype = c("se", "ci", "var", "cv"),
level = 0.95,
interval_type = c("mean", "beta", "xlogit", "asin", "score", "quantile"),
qrule = c("math", "school", "shahvaish", "hf1", "hf2", "hf3", "hf4", "hf5", "hf6",
"hf7", "hf8", "hf9"),
df = NULL,
...
)
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. Otherwise one or more of: standard error ("se", the default), confidence interval ("ci"), variance ("var") or coefficient of variation ("cv"). |
level |
A single number indicating the confidence level (only one level allowed). Note that this may effect estimated standard errors (see |
interval_type |
See |
qrule |
See |
df |
A number indicating the degrees of freedom for t-distribution. The default, NULL, uses the design degrees of freedom (matches the survey package). |
... |
Ignored |
Note that the behavior of these functions has changed in srvyr version 1.1,
but the old functions are still (currently) supported as
survey_old_quantile
and survey_old_median
if you need
to replicate the old results. For more details about what has changed, see
Thomas Lumley's blog post on the changes, available here:
<https://notstatschat.rbind.io/2021/07/20/what-s-new-in-the-survey-package/>
library(survey)
data(api)
dstrata <- apistrat %>%
as_survey_design(strata = stype, weights = pw)
dstrata %>%
summarise(api99 = survey_quantile(api99, c(0.25, 0.5, 0.75)),
api00 = survey_median(api00, vartype = c("ci")))
dstrata %>%
group_by(awards) %>%
summarise(api00 = survey_median(api00))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.