non-parametric manova in R

113 views Asked by At

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 
1

There are 1 answers

1
Ben Bolker On

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