【问题标题】:R Help! chisquare test救命!卡方检验
【发布时间】:2021-03-15 03:36:40
【问题描述】:

我有一个看起来像这样的数据集

我正在运行卡方检验以查看是否...

  1. 在之前和之后观察到的所有颜色的频率存在显着差异。
  2. 之前的黄色和之后的蓝色在频率上有显着差异
  3. 如果之前的黄色、蓝色和橙色的频率明显低于或高于之后。

我应该如何在 R 中做到这一点?我只是添加所有颜色来制作主列吗?

这是我目前所拥有的

colors$combined <-  colors$yellow + colors$blue + colors$red + colors$orange + colors$purple


x1 <- chisq.test(colors$combined,colors$before/after)
x1

【问题讨论】:

    标签: r statistics chi-squared statistical-test


    【解决方案1】:
    dat=data.frame(red=c(1,2,0,1,2,0),
                   yellow=c(2,1,2,2,1,2),
                   blue=c(1,2,2,1,1,2),
                   orange=c(2,2,0,0,1,1),
                   purple=c(2,2,1,1,1,1),
                   when=c(rep("before", 4), "after", "after"))
    library(dplyr)
    tab=dat %>%
      group_by(when) %>%
      summarize(across(red:purple, mean)) %>%
      select(-when)
    chisq.test(as.matrix(tab))
        Pearson's Chi-squared test
    
    data:  as.matrix(tab)
    X-squared = 0.075374, df = 4, p-value = 0.9993
    

    不,前后颜色没有显着差异。

    t.test(c(2,1,2,2), c(1,2))
    

    之前的黄色和之后的蓝色没有显着差异。

    t.test(c(2,1,2,2), c(1,2))
    

    前后黄色无显着差异。

    t.test(c(1,2,2,1), c(1,2))
    

    前后蓝色无显着差异。

    t.test(c(2,2,0,0), c(1,1))
    

    橙色前后没有显着差异。

    【讨论】:

    • 谢谢你,你是对的!我应该做一个 t.test 而不是卡方。
    猜你喜欢
    • 2023-02-01
    • 1970-01-01
    • 2023-02-17
    • 2021-06-16
    • 2020-12-01
    • 2021-12-29
    • 2012-03-08
    • 2017-01-03
    相关资源
    最近更新 更多