1

I created a small example data set:

value <- rnorm(100, mean = 100, sd = 36)
group <- c(rep(c("A", "B", "C"), 33), "C")
gender <- c(rep(c("M", "F"), 50))  
test <- cbind(value, group, gender)
test <- as.data.table(test)

I want to see if the mean value differs between twoi factors. So i basically want to compare all six means below:

> testSummary <- test %>%
+   group_by(group, gender) %>%
+   get_summary_stats(value, type = "common")
Error in `mutate()`:
ℹ In argument: `data = map(.data$data, .f, ...)`.
Caused by error in `map()`:
ℹ In index: 1.
Caused by error in `get_selected_vars()`:
! Can't subset columns with `value`.
✖ Can't convert from `value` <double> to <integer> due to loss of precision.
Run `rlang::last_error()` to see where the error occurred.
> testSummary
# A tibble: 6 × 12
  group gender variable     n   min   max median   iqr  mean    sd    se    ci
  <dbl>  <dbl> <fct>    <dbl> <dbl> <dbl>  <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1     1      1 value       16  70.1  155.   112.  41.5 112.   28.1  7.03  15.0
2     1      2 value       17  61.4  193.   106.  43.5 105.   34.4  8.33  17.7
3     2      1 value       17  10.2  162.   107.  51.7  98.8  42.7 10.3   21.9
4     2      2 value       16  48.3  179.   102.  63.2 110.   42.4 10.6   22.6
5     3      1 value       17  66.2  165.   109.  22.3 108.   24.5  5.93  12.6
6     3      2 value       17  53.8  182.   115.  35.6 108.   33.1  8.02  17.0

Assuming that my data is not-normally distributed, how can compare if the mean is different in each of the 6 summarised groups?

I though i needed a pairwise comparison, but the functions only take two arguments, so do i need to run the twice? Is there a way to do it in one step?

    Pairwise comparisons using Wilcoxon rank sum test with continuity correction 

data:  as.numeric(test$value) and test$gender 

  F   
M 0.67

P value adjustment method: holm 
> pairwise.wilcox.test(as.numeric(test$value), g = test$group)

    Pairwise comparisons using Wilcoxon rank sum exact test 

data:  as.numeric(test$value) and test$group 

  A    B   
B 0.80 -   
C 0.32 0.30

P value adjustment method: holm 
Nneka
  • 1,764
  • 2
  • 15
  • 39
  • You might need to say more about what you're trying to figure out, and this might end up being more appropriate for [CrossValidated](https://stats.stackexchange.com) ... (A "paired" test occurs when you have matched pairs distributed across different groups, e.g. you measure something on the left and right arms of a bunch of people ... does this describe your setup?) – Ben Bolker Mar 09 '23 at 16:22
  • @BenBolker i am trying to see if stress levels, are different across 3 companies. I also want to know if there are difference between genders – Nneka Mar 09 '23 at 16:34

1 Answers1

0

You could use a Kruskal-Wallis test on the interaction/combination of group and gender: this will, approximately

compare if the mean is different in each of the 6 summarised groups

from Wikipedia,

If the researcher can make the assumptions of an identically shaped and scaled distribution for all groups, except for any difference in medians, then the null hypothesis is that the medians of all groups are equal, and the alternative hypothesis is that at least one population median of one group is different from the population median of at least one other group

data setup

set.seed(101)
value <- rnorm(100, mean = 100, sd = 36)
group <- c(rep(c("A", "B", "C"), 33), "C")
gender <- rep(c("M", "F"), 50)
## DON'T use cbind() here - it will convert `value` to character ...
test <- data.frame(value, group, gender)
kruskal.test(value ~ interaction(group,gender), test)

    Kruskal-Wallis rank sum test

data:  value by interaction(group, gender)
Kruskal-Wallis chi-squared = 7.3207, df = 5, p-value = 0.1979
Ben Bolker
  • 211,554
  • 25
  • 370
  • 453
  • but this tests the overall significance, right? I am interested in the pairwise comparisons – Nneka Mar 09 '23 at 18:41