R中的非参数Manova

gzszwxb4  于 2023-03-10  发布在  其他
关注(0)|答案(1)|浏览(142)

我创建了一个小的示例数据集:

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)

我想看看两个因子之间的平均值是否不同。所以我基本上想比较下面所有六个平均值:

> 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

假设我的数据呈非正态分布,如果6个汇总组的平均值不同,如何进行比较?
我想我需要一个成对比较,但是函数只接受两个参数,所以我需要运行两次吗?有没有办法一步完成?

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
1tuwyuhd

1tuwyuhd1#

您可以在组和性别的交互/组合上使用Kruskal-Wallis test:这将大约
比较6个总结组中各组的平均值是否不同
从维基百科,
如果研究人员可以假设所有组的分布形状和比例相同,但中位数不同,则零假设是所有组的中位数相等,备择假设是一个组的至少一个总体中位数与至少另一个组的总体中位数不同

数据设置

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

相关问题