survey_corr: Calculate correlation and its variation using survey methods

View source: R/survey_statistics.r

survey_corrR Documentation

Calculate correlation and its variation using survey methods

Description

Calculate correlation from complex survey data. A wrapper around svyvar. survey_corr should always be called from summarise. Note this is Pearson's correlation.

Usage

survey_corr(
  x,
  y,
  na.rm = FALSE,
  vartype = c("se", "ci", "var", "cv"),
  level = 0.95,
  df = NULL,
  ...
)

Arguments

x

A variable or expression

y

A variable or expression

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

(For vartype = "ci" only) A single number or vector of numbers indicating the confidence level

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

...

Ignored

Examples

data('api', package = 'survey')

apisrs %>%
  as_survey_design(.ids = 1) %>%
  summarize(api_corr = survey_corr(x = api00, y = api99))

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")
  )

srvyr documentation built on Sept. 11, 2024, 8:43 p.m.