R/survey_statistics.r
survey_corr.Rd
Calculate correlation from complex survey data. A wrapper
around svyvar
. survey_corr
should always be
called from summarise
. Note this is Pearson's correlation.
survey_corr(
x,
y,
na.rm = FALSE,
vartype = c("se", "ci", "var", "cv"),
level = 0.95,
df = NULL,
...
)
A variable or expression
A variable or expression
A logical value to indicate whether missing values should be dropped
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").
(For vartype = "ci" only) A single number or vector of numbers indicating the confidence level
(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
Ignored
data('api', package = 'survey')
apisrs %>%
as_survey_design(.ids = 1) %>%
summarize(api_corr = survey_corr(x = api00, y = api99))
#> # A tibble: 1 × 2
#> api_corr api_corr_se
#> <dbl> <dbl>
#> 1 0.975 0.00461
apisrs %>%
as_survey_design(.ids = 1) %>%
group_by(sch.wide) %>%
summarize(
api_emer_corr = survey_corr(x = api00, y = emer, na.rm=TRUE, vartype="ci")
)
#> # A tibble: 2 × 4
#> sch.wide api_emer_corr api_emer_corr_low api_emer_corr_upp
#> <fct> <dbl> <dbl> <dbl>
#> 1 No -0.403 -0.583 -0.223
#> 2 Yes -0.398 -0.526 -0.271