我正在使用 R 的一个名为 rstatix 的包,并且尝试使用函数 anova_test 执行方差分析测试。我的数据看起来像这样。
\nstructure(\n list(\n Cat = c(\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mel",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Mem",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men",\n "Men"\n ),\n count = c(\n 66L,\n 107L,\n 185L,\n 207L,\n 203L,\n 121L,\n 41L,\n 71L,\n 147L,\n 131L,\n 38L,\n 58L,\n 175L,\n 53L,\n 76L,\n 16L,\n 154L,\n 128L,\n 27L,\n 74L,\n 85L,\n 122L,\n 51L,\n 113L,\n 182L,\n 184L,\n 92L,\n 13L,\n 151L,\n 54L,\n 174L,\n 146L,\n 192L,\n 153L,\n 138L,\n 42L,\n 116L,\n 8L,\n 148L,\n 109L,\n 129L,\n 96L,\n 179L,\n 25L,\n 418L,\n 212L,\n 358L,\n 307L,\n 240L,\n 400L,\n 22L,\n 396L,\n 211L,\n 372L,\n 30L,\n 73L,\n 176L,\n 59L,\n 128L,\n 341L\n ),\n Word = c(\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA,\n NA\n ),\n type_pro = c(\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM",\n "EM"\n ),\n total = c(\n 3,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 1,\n 0,\n 0,\n 2,\n 3,\n 0,\n 3,\n 2,\n 1,\n 0,\n 0,\n 1,\n 2,\n 3,\n 1,\n 4,\n 5,\n 5,\n 2,\n 2,\n 2,\n 3,\n 3,\n 5,\n 4,\n 4,\n 3,\n 3,\n 4,\n 4,\n 4,\n 4,\n 4,\n 0,\n 0,\n 0,\n 2,\n 0,\n 0,\n 0,\n 0,\n 0,\n 0,\n 1,\n 0,\n 0,\n 0,\n 1,\n 0,\n 0,\n 0,\n 0,\n 0\n )\n ),\n row.names = c(NA, -60L),\n groups = structure(\n list(\n Cat = c("Mel", "Mem", "Men"),\n .rows = structure(\n list(1:20,\n 21:40, 41:60),\n ptype = integer(0),\n class = c("vctrs_list_of",\n "vctrs_vctr", "list")\n )\n ),\n row.names = c(NA, -3L),\n class = c("tbl_df",\n "tbl", "data.frame"),\n .drop = TRUE\n ),\n class = c("grouped_df",\n "tbl_df", "tbl", "data.frame")\n)\nRun Code Online (Sandbox Code Playgroud)\n问题是我总是收到这个错误。
\nanova_test(total~Cat)\nError: Problem with `mutate()` input `data`.\n\xe2\x9c\x96 Can't subset columns that don't exist.\n\xe2\x9c\x96 Column `Cat` doesn't exist.\n\xe2\x84\xb9 Input `data` is `map(.data$data, .f, ...)`.\nRun `rlang::last_error()` to see where the error occurred.\nRun Code Online (Sandbox Code Playgroud)\n如果您看到我的数据,则 Cat 列存在。所以我不明白这个错误。
\n如果有人能帮助我那就太好了。
\n问题是您的数据是按分组进行分组的,Cat因此每个组都看不到该Cat值。您需要取消数据分组
lol %>%
ungroup() %>%
anova_test(total~Cat)
Run Code Online (Sandbox Code Playgroud)