简体   繁体   English

有没有更好的方法在 R 中进行 3 路方差分析?

[英]Is there a better way to conduct a 3 way ANOVA in R?

Right now I am working with my own dataset very similar to the example at https://www.datanovia.com/en/lessons/anova-in-r/ specifically the Three-Way ANOVA section.现在我正在使用我自己的数据集,该数据集与https://www.datanovia.com/en/lessons/anova-in-r/的示例非常相似,特别是三向方差分析部分。 The code is well laid out, but when I get to the section for visualization using boxplots, I run into an unexpected error.代码的布局很好,但是当我进入使用箱线图进行可视化的部分时,我遇到了一个意外错误。

headache %>%
  group_by(gender, risk, treatment) %>%
  get_summary_stats(pain_score, type = "mean_sd")

In their code, they assign y as pain score, but for me, I get Error in:在他们的代码中,他们将 y 指定为疼痛评分,但对我来说,我得到错误:

FUN (x[[i]],...): object "pain_score" not found

As such, I can't get the plot they make or move farther into analysis.因此,我无法获得他们制造的 plot 或进一步进行分析。

  bxp <- ggboxplot(
  headache, x = "treatment", y = "pain_score", 
  color = "risk", palette = "jco", facet.by = "gender"
  )
bxp

All of the packages I have are up to date, I'm not seeing any errors in my code.我拥有的所有软件包都是最新的,我的代码中没有看到任何错误。 I've tried other variables in my data set and the same issue, and when I change it to mean, I just get the line, not the box plot.我在我的数据集中尝试了其他变量和相同的问题,当我将其更改为表示时,我只是得到了这条线,而不是框 plot。 If anyone has some input, it would be much appreciated!!如果有人有一些意见,将不胜感激!

Its working perfectly alright, You also didn't mention the libraries in your code.它工作得很好,你也没有在你的代码中提到这些库。 Its hard to help if you don't provide all the complete information.如果您不提供所有完整信息,则很难提供帮助。 In any case someone wants to reproduce this.无论如何,有人想重现这一点。

Please run the below, It should work at your end.请运行以下命令,它应该在您的最后工作。 The error you are getting suggests that you might have either mistakenly removed the column, or data is corrupt in your session.您收到的错误表明您可能错误地删除了该列,或者 session 中的数据已损坏。

Here is the complete working code:这是完整的工作代码:

library(tidyverse)
library(rstatix)
library(ggpubr)

data("headache", package = "datarium")

headache %>%
  group_by(gender, risk, treatment) %>%
  get_summary_stats(pain_score, type = "mean_sd")


bxp <- ggboxplot(
  headache, x = "treatment", y = "pain_score", 
  color = "risk", palette = "jco", facet.by = "gender"
)
bxp

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM