compare2numvars: Comparison for columns of numbers for 2 groups

Description Usage Arguments Value Examples

View source: R/tests.R

Description

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

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
# 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 %>% mutate(gear=factor(gear) %>% fct_lump_n(n=1)) %>% 
compare2numvars(dep_vars="wt",indep_var="gear",gaussian=TRUE)

wrappedtools documentation built on Sept. 6, 2021, 5:08 p.m.