【问题标题】:Program a conditional based on aov() result根据 aov() 结果编写条件
【发布时间】:2018-11-26 12:57:24
【问题描述】:

我有一个包含许多因子水平的数据集。每个因素都有一个左侧和右侧,并且因素/侧面组合有多个条目。所以它看起来像这样:

Factor_type             Side       Value
factor1                 L           134
factor1                 R           112
factor2                 L           166
factor2                 R            72

我遍历每个因素并执行aov()analysis:

factorset <- c("factor1", "factor2", "factor3")
for(f in factorset){
  x <- mydata %>% filter(Factor_type == f) #creates a dataset of only desired factor

  a <- aov(data = x, formula = Value ~ Side)

我想知道如何/是否可以根据 aov 分析创建条件。本质上:

if(a == IS SIGNIFICANT){
    ggplot(x, aes(x = Side, y = Value)+geom_boxplot()

}

【问题讨论】:

  • 你试过总结吗?如果您在 aov 结果中使用摘要,则输出之一是 p.value。

标签: r statistics anova


【解决方案1】:

看玩具例子。我会生成一些数据

> x<-gl(5,5)
> y<-rnorm(25)

然后运行aov:

> a<-aov(y~x)

summaryPr(&gt;F) 列中显示 p 值:

 > summary(a)
            Df Sum Sq Mean Sq F value Pr(>F)
 x            4  1.834  0.4584   0.519  0.722
 Residuals   20 17.651  0.8825               

您可以通过以下方式直接访问它:

> summary(a)[[1]][1,5]
[1] 0.722432

所以,你的代码是:

if(summary(a)[[1]][1,5]<0.05){
    ggplot(x, aes(x = Side, y = Value)+geom_boxplot()
}

【讨论】:

  • 很棒的解释。我不知道为什么我不认为输出是一个表格。
猜你喜欢
  • 1970-01-01
  • 2022-10-14
  • 1970-01-01
  • 2014-05-17
  • 2023-03-10
  • 2020-08-28
  • 1970-01-01
  • 2021-12-24
  • 2018-12-27
相关资源
最近更新 更多