survey_cor_matrix: Create a correlation matrix from survey data with summary...

View source: R/cor_tables.R

survey_cor_matrixR Documentation

Create a correlation matrix from survey data with summary statistics

Description

This function wraps jtools::svycor() so that it works in a srvyr-pipeline, runs bootstrapped significance-tests and calculates weighted summary statistics. Only numeric variables are included in the result.

Usage

survey_cor_matrix(svy_df, var_names)

Arguments

svy_df

A survey object created with the survey or srvyr package. Only numeric variables will be included in the result.

var_names

Named character vector to rename variables to - most helpful if return is to be passed to some print function

Value

A correlation matrix list in the format provided by jtools::svycor() with the addition of a desc-element with means and standard deviations of the variables.

Examples

## Not run: 
if (requireNamespace("survey") & requireNamespace("srvyr")) {
library(survey)
library(srvyr)
data(api)
dstrat <- apistrat %>% as_survey_design(1, strata = stype, fpc = fpc, weight = pw)

var_names <- c(meals = "Share subsidized meals", ell = "English language learners",
              growth = "Performance Change")

# Print correlation matrix
survey_cor_matrix(dstrat, var_names)
}

## End(Not run)

LukasWallrich/rNuggets documentation built on Aug. 26, 2022, 11:03 a.m.