compare2numvars: Comparison for columns of numbers for 2 groups

View source: R/tests.R

compare2numvarsR Documentation

Comparison for columns of numbers for 2 groups

Description

compare2numvars computes either t_var_test or wilcox.test, depending on parameter gaussian. Descriptive statistics, depending on distribution, are reported as well.

Usage

compare2numvars(
  data,
  dep_vars,
  indep_var,
  gaussian,
  round_p = 3,
  round_desc = 2,
  range = FALSE,
  rangesep = " ",
  pretext = FALSE,
  mark = FALSE,
  n = FALSE,
  add_n = FALSE,
  singleline = TRUE,
  indentor = "     ",
  ci = FALSE,
  n_boot = 10^4
)

Arguments

data

name of dataset (tibble/data.frame) to analyze.

dep_vars

vector of column names for independent variables.

indep_var

name of grouping variable, has to translate to 2 groups. If more levels are encountered, an error is produced.

gaussian

logical specifying normal or ordinal values.

round_p

level for rounding p-value.

round_desc

number of significant digits for rounding of descriptive stats.

range

include min/max?

rangesep

text between statistics and range or other elements.

pretext

for function formatP.

mark

for function formatP.

n

create columns for n per group?

add_n

add n to descriptive statistics. Will automatically be set to TRUE, if singleline = FALSE and n = TRUE to keep it for the long table format.

singleline

Put all group levels in a single line (default) or below each other.

indentor

Optional text element to indent descriptivestats when using singleline = FALSE. Defaults to " ".

ci

Computes lower and upper confidence limits for the estimated mean/median, based on bootstrapping.

n_boot

Number of bootstrap samples for confidence limits.

Value

A tibble with variable names, descriptive statistics, and p-value, number of rows is number of dep_vars.

Examples

# Assuming Normal distribution:
compare2numvars(
  data = mtcars, dep_vars = c("wt", "mpg", "qsec"), indep_var = "am",
  gaussian = TRUE
)
compare2numvars(
  data = mtcars, dep_vars = c("wt", "mpg", "qsec"), indep_var = "am",
  gaussian = TRUE, singleline = FALSE
)
# Ordinal scale:
compare2numvars(
  data = mtcars, dep_vars = c("wt", "mpg", "qsec"), indep_var = "am",
  gaussian = FALSE, add_n = TRUE, range = TRUE
)
# If dependent variable has more than 2 levels, consider fct_lump:
mtcars |> dplyr::mutate(gear=factor(gear) |> forcats::fct_lump_n(n=1)) |> 
compare2numvars(dep_vars="wt",indep_var="gear",gaussian=TRUE)


wrappedtools documentation built on June 8, 2025, 10:58 a.m.