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
)

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?

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
)
# Ordinal scale:
compare2numvars(
  data = mtcars, dep_vars = c("wt", "mpg", "qsec"), indep_var = "am",
  gaussian = FALSE
)
# 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 Oct. 10, 2024, 5:07 p.m.