DichotTest: Test for differences in dichotomized numeric variables

View source: R/DichotTest.R

DichotTestR Documentation

Test for differences in dichotomized numeric variables

Description

Dichotomize a variable by > or <= the median value and then perform Fisher's exact test on the resulting contingency table between a grouping variable. This function was formally named OrdinalVarTest.

Usage

DichotTest(
  data,
  id_var = NULL,
  group_var,
  tst_vars,
  GCS_compare = 7,
  rep_meas_sum_func = "median",
  check_n_percents = FALSE,
  test_use = "proportion",
  yates = TRUE,
  correct_var = NULL,
  include_eq = TRUE,
  compare_less_than = FALSE,
  alt_split = NULL
)

Arguments

data

the input data frame

id_var

The identifying variable per observation (e.g., patient number). Defaults to NULL

group_var

the variable to group by

tst_vars

a vector of variables to dichotomize by their median and test

GCS_compare

if parameter happens to be the Glasgow Coma Scale, then dichotomize by > 7 since that's apparently already an agreed upon split in the literature. Defaults to 7. This is depreciated; use "alt_split' instead

rep_meas_sum_func

If wind up having multiple observations per id_var, this is the function to summarise the tst_vars per id_var by. Defaults to "median"

check_n_percents

set to TRUE if wish to also obtain a count table with percentages. Defaults to FALSE.

test_use

specify either 'fisher' or 'logistic_regress'

correct_var

if performing a logistic regression, can specify an additional variable to correct for

include_eq

set to FALSE if want to dichotomize by > the median and not >=. Defaults to TRUE

compare_less_than

set to TRUE if want to compare by < or <= the split value instead of the default of > or >=

alt_split

can set an alternate value to dichotomize by instead of the median

Examples

# if have multiple observations per MRN, then can take the median per patient with rep_meas_sum_func="median"
# before doing stats.
out <- DichotTest(data=df, id_var="MRN", group_var="Included_in_Study", tst_vars=c("Admission_GCS", "Age", "ICU_Stay_Len"),
rep_meas_sum_func="median", check_n_percents=TRUE)
# see n(%) tables
out$Age$n_percent
# see contingency table (basically has same counts from n_percent but without the percent)
out$Age$tbl
# this table is used for the fisher test
out$Age$res

kwdoyle/kevtools documentation built on Jan. 4, 2023, 10:32 p.m.