T_hss_chisq: Runs chi-squared test on selected variables

View source: R/T_hss_chisq.R

T_hss_chisqR Documentation

Runs chi-squared test on selected variables

Description

This functions runs chi-squared significance tests for one or more variables in a dataframe, with a single cross-variable. Variable names are passed as a character vector containing one or more variable names. hss_chisq_formatted returns a formatted character string containing a verbose description of the p-value. This verbose output is used in formatted data tables.

Usage

T_hss_chisq(df, var, group, full = FALSE, multi = FALSE)

T_hss_chisq_formatted(df, var, group)

Arguments

df

The dataframe containing the variable(s) of interest

var

The names of the variable(s) of interest. Accepts a single value or a character vector containing multiple variable names.

group

The grouping (or disaggregation) variable.

full

TRUE/FALSE if the full results should be returned. Set to FALSE by default, returning only the p.value.

multi

Set to FALSE if used for a 'select-one' question. Set to TRUE if used for a 'select-multiple question to look up the corresponding response options.

Value

A vector containing the results of the chi-squared test for the selected variables. If full is set to TRUE this will be a list, otherwise an atomic numeric vector. For hss_chisq_formatted the output is a character vector.

Examples

# Create dummy dictionary
dict_var <- dummy_var
dict_val <- dummy_val
# Calculte p-value for chi-squared test on a 'select-one' question.
hss_chisq(dummydata, "migr_nr", "gender")

# Calculate p-value for chi-squared test on a 'select-multiple' question.
hss_chisq(dummydata, "migr_why_all", "gender", multi = TRUE)

# Chi-squared test with full output
hss_chisq(dummydata, "migr_nr", full = TRUE)

# Formatted output
hss_chisq_formatted(dummydata, "migr_nr", "gender")

RenRMT/hsstools documentation built on April 14, 2025, 7:10 p.m.