Skip to contents

This function computes p-values using Chi-square tests for each variable in vars and grouping variable specified in group

Usage

ana_fn_chisq(
  df,
  vars,
  group,
  correct = FALSE,
  simulate.p.value = FALSE,
  add_statistic = FALSE,
  add_effectsize = FALSE,
  add_residuals = FALSE
)

Arguments

df

data.frame

vars

Vector of variable names

group

Name of grouping variable

correct

(logical) Apply continuity correction (see stats::chisq.test())

simulate.p.value

(logical) Compute p-values by Monte Carlo simulation (see stats::chisq.test())

add_statistic

(logical) Add chi-square to table (default FALSE)

add_effectsize

(logical) Add effect size (Cramer's V) to table (default FALSE)

add_residuals

(logical) Add adjusted standardized residuals (default FALSE)

Value

data.frame with columns Var, p (formatted p-values), and Chi2 (if requested)

Details

If add_residuals is requested, adjusted standardized residuals (from $stdres in the stats::chisq.test() object) are added to the table. Since these residuals follow a normal distribution, they are supplemented with asterisks to indicate significance.

This function should be passed as ana_fn when calling get_desc_table() with a group argument to obtain p-values. If you want to create a custom ana_fn, you should model it after this one.

Examples

if (FALSE) {
df |> ana_fn_chisq("Nationality", "TreatmentGroup")
}