Skip to contents

Compare Means Between Groups

Usage

compare_means_between_groups(
  data,
  var1,
  var2,
  variable,
  grouping_variable,
  groups,
  test = "Welch",
  input = "wide",
  output = "console"
)

Arguments

data

data

var1

variable 1

var2

variable 2

variable

variable

grouping_variable

Group

groups

Specify groups from grouping variable

test

Default: "Welch", choose between "student" and "Welch"

input

Default: "wide", choose between "long" and "wide". "wide" requires data var1 var2. "long" requires data, variable, grouping_variable groups

output

Default: "console" - prints output in console and returns tibble invisibly.

Value

results

Examples


# Wide data - default
data_wide <- data.frame(A = c(4, 2, 5, 3, 6, 2, 5),
                        B = c(5, 2, 1, 2, 1, 3, 2))

compare_means_between_groups(data_wide, var1 = A, var2 = B)
#> 
#> ── Welch Two Sample t-test ─────────────────────────────────────────────────────
#>   term          value  
#>   mean_of_A      3.86  
#>   mean_of_B      2.29  
#>   t              1.99  
#>   df             11.8  
#>   p_value      0.0707  
#>   ci_level       0.95  
#>   lower_ci     -0.156  
#>   upper_ci        3.3  

# Long data
data_long <- data_wide |> tibble::rowid_to_column("id") |>
  tidyr::pivot_longer(cols = -id, names_to = "group", values_to = "variable")

compare_means_between_groups(data_long, variable = variable,
                             grouping_variable = group, groups = c("A", "B"), input = "long")
#> 
#> ── Welch Two Sample t-test ─────────────────────────────────────────────────────
#>   term          value  
#>   mean_of_A      3.86  
#>   mean_of_B      2.29  
#>   t              1.99  
#>   df             11.8  
#>   p_value      0.0707  
#>   ci_level       0.95  
#>   lower_ci     -0.156  
#>   upper_ci        3.3