survey_ratio

0th

Percentile

Calculate the ratio and its variation using survey methods

Calculate ratios from complex survey data. A wrapper around svyratio. survey_ratio should always be called from summarise.

Usage
survey_ratio(numerator, denominator, na.rm = FALSE, vartype = c("se",
  "ci", "var", "cv"), level = 0.95, deff = FALSE, df = NULL,
  .svy = current_svy(), ...)
Arguments
numerator

The numerator of the ratio

denominator

The denominator of the ratio

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

deff

A logical value to indicate whether the design effect should be returned.

df

(For vartype = "ci" only) A numeric value indicating the degrees of freedom for t-distribution. The default (NULL) uses degf, but Inf is the usual survey package's default (except in svyciprop.

.svy

A tbl_svy object. When called from inside a summarize function the default automatically sets the survey to the current survey.

...

Ignored

Aliases
  • survey_ratio
Examples
# NOT RUN {
library(survey)
data(api)

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

dstrata %>%
  summarise(enroll = survey_ratio(api00, api99, vartype = c("ci", "cv")))

dstrata %>%
  group_by(awards) %>%
  summarise(api00 = survey_ratio(api00, api99))

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

# Note that the default degrees of freedom in srvyr is different from
# survey, so your confidence intervals might not exactly match. To
# replicate survey's behavior, use df = Inf
dstrata %>%
  summarise(srvyr_default = survey_total(api99, vartype = "ci"),
            survey_defualt = survey_total(api99, vartype = "ci", df = Inf))

comparison <- survey::svytotal(~api99, dstrata)
confint(comparison) # survey's default
confint(comparison, df = survey::degf(dstrata)) # srvyr's default

# }
Documentation reproduced from package srvyr, version 0.3.5, License: GPL-2 | GPL-3

Community examples

Looks like there are no examples yet.