Conduct a chi-squared test and produce a contingency table
chi_squared_test(
data = NULL,
iv_name = NULL,
dv_name = NULL,
round_chi_sq_test_stat = 2,
round_p = 3,
sigfigs_proportion = 2,
correct = TRUE,
odds_ratio_ci = 0.95,
round_odds_ratio_ci_limits = 2,
invert = FALSE,
notify_na_count = NULL,
save_as_png = FALSE,
png_name = NULL,
width = 1200,
height = 800,
units = "px",
res = 200,
layout_matrix = NULL
)
a data object (a data frame or a data.table)
name of the independent variable
name of the dependent variable (must be a binary variable)
number of decimal places to which to round the chi-squared test statistic (default = 2)
number of decimal places to which to round the p-value from the chi-squared test (default = 3)
number of significant digits to round to
(for the table of proportions). By default sigfigs_proportion = 2
logical. Should continuity correction be applied? (default = TRUE)
width of the confidence interval for the odds ratio.
Input can be any value less than 1 and greater than or equal to 0.
By default, odds_ratio_ci = 0.95
.
If odds_ratio_ci = TRUE
, the default value of 0.95 will be used.
If odds_ratio_ci = FALSE
, no confidence interval will be estimated
for the odds ratio.
number of decimal places to which to round the limits of the odds ratio's confidence interval (default = 2)
logical. Whether the inverse of the odds ratio (i.e., 1 / odds ratio) should be returned.
if TRUE
, notify how many rows
were removed due to missing values. By default, NA count will be printed
only if there are any NA values.
if save_as_png = TRUE
,
the results will be saved as a PNG file (default = FALSE).
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 of the PNG file (default = 1600)
height of the PNG file (default = 1200)
the units for the width
and height
arguments.
Can be "px"
(pixels), "in"
(inches), "cm"
,
or "mm"
. By default, units = "px"
.
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
The layout argument for arranging section
titles and tables using the grid.arrange
function.
chi_squared_test(data = mtcars, iv_name = "cyl", dv_name = "am")
# if the iv has only two levels, odds ratio will also be calculated
chi_squared_test(data = mtcars, iv_name = "vs", dv_name = "am")
Run the code above in your browser using DataLab