compare2numvars | R Documentation |
compare2numvars
computes either t_var_test or wilcox.test,
depending on parameter gaussian. Descriptive statistics, depending on distribution,
are reported as well.
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
)
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? |
A tibble with variable names, descriptive statistics, and p-value, number of rows is number of dep_vars.
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.