Compare sample means

compare_means(
  dataset,
  var1,
  var2,
  samples = "independent",
  alternative = "two.sided",
  conf_lev = 0.95,
  comb = "",
  adjust = "none",
  test = "t",
  data_filter = "",
  envir = parent.frame()
)

Arguments

dataset

Dataset

var1

A numeric variable or factor selected for comparison

var2

One or more numeric variables for comparison. If var1 is a factor only one variable can be selected and the mean of this variable is compared across (factor) levels of var1

samples

Are samples independent ("independent") or not ("paired")

alternative

The alternative hypothesis ("two.sided", "greater" or "less")

conf_lev

Span of the confidence interval

comb

Combinations to evaluate

adjust

Adjustment for multiple comparisons ("none" or "bonf" for Bonferroni)

test

t-test ("t") or Wilcox ("wilcox")

data_filter

Expression entered in, e.g., Data > View to filter the dataset in Radiant. The expression should be a string (e.g., "price > 10000")

envir

Environment to extract data from

Value

A list of all variables defined in the function as an object of class compare_means

Details

See https://radiant-rstats.github.io/docs/basics/compare_means.html for an example in Radiant

See also

summary.compare_means to summarize results

plot.compare_means to plot results

Examples

compare_means(diamonds, "cut", "price") %>% str()
#> List of 18 #> $ dat_summary: tibble [5 × 7] (S3: tbl_df/tbl/data.frame) #> ..$ cut : Factor w/ 5 levels "Fair","Good",..: 1 2 3 4 5 #> ..$ mean : num [1:5] 4505 4130 3960 4369 3470 #> ..$ n : int [1:5] 101 275 677 771 1176 #> ..$ n_missing: int [1:5] 0 0 0 0 0 #> ..$ sd : num [1:5] 3750 3730 3896 4237 3827 #> ..$ se : num [1:5] 373 225 150 153 112 #> ..$ me : num [1:5] 740 443 294 300 219 #> $ res :'data.frame': 10 obs. of 10 variables: #> ..$ group1 : chr [1:10] "Fair" "Fair" "Fair" "Fair" ... #> ..$ group2 : chr [1:10] "Good" "Very Good" "Premium" "Ideal" ... #> ..$ t.value : num [1:10] 0.86 1.356 0.337 2.658 0.631 ... #> ..$ p.value : num [1:10] 0.39078 0.17723 0.73666 0.00895 0.5283 ... #> ..$ df : num [1:10] 177 134 136 119 529 ... #> ..$ ci_low : num [1:10] -485 -250 -661 264 -360 ... #> ..$ ci_high : num [1:10] 1235 1340 933 1806 701 ... #> ..$ cis_low : num [1:10] 0 0 0 0 0 0 0 0 0 0 #> ..$ cis_high: num [1:10] 0 0 0 0 0 0 0 0 0 0 #> ..$ sig_star: chr [1:10] "" "" "" "**" ... #> $ cmb :'data.frame': 10 obs. of 2 variables: #> ..$ group1: chr [1:10] "Fair" "Fair" "Fair" "Fair" ... #> ..$ group2: chr [1:10] "Good" "Very Good" "Premium" "Ideal" ... #> $ levs : chr [1:5] "Fair" "Good" "Very Good" "Premium" ... #> $ not_vary : chr(0) #> $ cname : chr "cut" #> $ df_name : chr "diamonds" #> $ vars : chr "cut, price" #> $ dataset : tibble [3,000 × 2] (S3: tbl_df/tbl/data.frame) #> ..$ variable: Factor w/ 5 levels "Fair","Good",..: 5 3 3 5 4 5 5 4 3 2 ... #> ..$ values : int [1:3000] 580 650 630 706 1080 3082 3328 4229 1895 3546 ... #> ..- attr(*, "description")= chr "## Diamond prices\n\nPrices of 3,000 round cut diamonds\n\n### Description\n\nA dataset containing the prices a"| __truncated__ #> $ var1 : chr "cut" #> $ var2 : chr "price" #> $ samples : chr "independent" #> $ alternative: chr "two.sided" #> $ conf_lev : num 0.95 #> $ comb : chr "" #> $ adjust : chr "none" #> $ test : chr "t" #> $ data_filter: chr "" #> - attr(*, "class")= chr [1:2] "compare_means" "list"