chi_squared_test_pairwise: Chi-squared test, pairwise

View source: R/chi_squared_test_pairwise.R

chi_squared_test_pairwiseR Documentation

Chi-squared test, pairwise

Description

Conducts a chi-squared test for every possible pairwise comparison with Bonferroni correction

Usage

chi_squared_test_pairwise(
  data = NULL,
  iv_name = NULL,
  dv_name = NULL,
  focal_dv_value = NULL,
  contingency_table = TRUE,
  contingency_table_sigfigs = 2,
  percent_and_total = FALSE,
  percentages_only = NULL,
  counts_only = NULL,
  sigfigs = 3,
  chi_sq_test_stats = FALSE,
  correct = TRUE,
  save_as_png = FALSE,
  png_name = NULL,
  width = 2000,
  height = 800,
  units = "px",
  res = 200,
  layout_matrix = NULL
)

Arguments

data

a data object (a data frame or a data.table)

iv_name

name of the independent variable (must be a categorical variable)

dv_name

name of the dependent variable (must be a binary variable)

focal_dv_value

focal value of the dependent variable whose frequencies will be calculated (i.e., the value of the dependent variable that will be considered a "success" or a result of interest)

contingency_table

If contingency_table = TRUE or if contingency_table = "percentages", the percentage of each binary value within each group will be printed. If contingency_table = "counts", a table of frequencies will be printed. If contingency_table = FALSE, no contingency table will be printed.

contingency_table_sigfigs

number of significant digits that the contingency table's percentage values should be rounded to (default = 2)

percent_and_total

logical. If percent_and_total = TRUE, tabulate percentages of the focal DV value and a total count of the two values in DV. By default percent_and_total = FALSE

percentages_only

tabulate percentages of the focal DV value only

counts_only

tabulate counts of the focal DV value only

sigfigs

number of significant digits to round to

chi_sq_test_stats

if chi_sq_test_stats = TRUE, chi-squared test statistic and degrees of freedom will be included in the pairwise comparison data.table.

correct

logical. Should continuity correction be applied? (default = TRUE)

save_as_png

if save_as_png = TRUE, the results will be saved as a PNG file (default = FALSE).

png_name

name of the PNG file to be saved. By default, the name will be "chi_sq_" followed by a timestamp of the current time. The timestamp will be in the format, jan_01_2021_1300_10_000001, where "jan_01_2021" would indicate January 01, 2021; 1300 would indicate 13:00 (i.e., 1 PM); and 10_000001 would indicate 10.000001 seconds after the hour.

width

width of the PNG file (default = 2000)

height

height of the PNG file (default = 800)

units

the units for the width and height arguments. Can be "px" (pixels), "in" (inches), "cm", or "mm". By default, units = "px".

res

The nominal resolution in ppi which will be recorded in the png file, if a positive integer. Used for units other than the default. By default, res = 200

layout_matrix

The layout argument for arranging section titles and tables using the grid.arrange function.

Examples

chi_squared_test_pairwise(data = mtcars, iv_name = "vs", dv_name = "am")
chi_squared_test_pairwise(data = mtcars, iv_name = "vs", dv_name = "am",
percentages_only = TRUE)
# using 3 mtcars data sets combined
chi_squared_test_pairwise(
data = rbind(mtcars, rbind(mtcars, mtcars)),
iv_name = "cyl", dv_name = "am")
# include the total counts
chi_squared_test_pairwise(
data = rbind(mtcars, rbind(mtcars, mtcars)),
iv_name = "cyl", dv_name = "am", percent_and_total = TRUE)
# display counts
chi_squared_test_pairwise(
data = rbind(mtcars, rbind(mtcars, mtcars)),
iv_name = "cyl", dv_name = "am", contingency_table = "counts")

jinkim3/kim documentation built on Feb. 26, 2025, 10:03 a.m.