Creates a chi.squared test table for multiple dependent variables

nice_chi_test_table(
  dv,
  iv,
  data,
  conditions = levels(factor(iv))[1:2],
  ref_levels = 2,
  labels = NULL,
  nice_p = TRUE,
  digits = 2,
  order = "12",
  label_attr = TRUE,
  type = "html",
  ...
)

chi_test_table(...)

Arguments

dv

A data frame with the dependent variables or a character vector when argument data is set.

iv

A data frame or vector with the independent variable or a character if argument data is set.

data

A data frame.

conditions

A character vector of length two with the names of the two conditions. Defaults to the first two levels of the independent variable 'iv' if applicable.

ref_levels

Vector with the reference level for each dependent variable. Values are repeated if length of levels vector is smaller than number dependent variables.

labels

A character vector of length two with labels for the dependent variables.

nice_p

If TRUE, p values are printed in a nice format.

digits

Number of digits for rounding mean and sd values

order

Either "12" or "21" depicting whether group two is compared to group one or vice versa.

label_attr

If TRUE, variable names are taken from a label attribute.

type

Either "df" for data frame or "html" for html table.

...

Further arguments passed to nice_table()

Value

A data.frame or an html table

Examples

set.seed(123)
dat <- data.frame(
  gender = factor(rbinom(100, 1, 0.3), labels = c("male", "female")),
  glasses = factor(rbinom(100, 1, 0.3), labels = c("no", "yes")),
  sen = factor(rbinom(100, 1, 0.5), labels = c("no_sen", "sen"))
 )
chi_test_table(
  c("gender", "glasses"), "sen", data = dat, 
  ref_levels = c("male", "no")
)
Table
Chi-squared test
Variable Level
Proportion
X²(1) p
n
no_sen sen Difference no_sen sen
gender male 0.65 0.77 0.12 1.14 .290 52 48
glasses no 0.65 0.83 0.18 3.30 .070 52 48
Note. One degree of freedom for all tests.