是否有用于多组拟合优度卡方检验的 R 函数?

发布于 2025-01-15 23:13:55 字数 1264 浏览 2 评论 0原文

S.giganteus <- matrix(c(0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1, 6, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 7, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 1, 4, 1, 0, 0), ncol = 7, byrow = T)
colnames (S.giganteus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (S.giganteus) <- c("feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", "jan")
S.giganteus <- as.table(S.giganteus)

P.melanotus <- matrix(c(0, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 4, 7, 6, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 2, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 4, 1, 1, 0, 0, 0, 0, 0, 3, 5, 0, 0, 0, 0, 0, 3, 8, 1, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0))
colnames (P.melanotus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (P.melanotus) <- c("feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", "jan")
P.melanotus <- as.table(P.melanotus)

我不知道这是否可能,但我想做多项拟合优度卡方检验。换句话说,我想将一个月内不同阶段的S.giganteus个体的比例与P.melanotus的实际个体数量进行比较。 由于抽样工作的差异以及因此组大小的不平等,我无法进行正常的卡方检验。 我希望避免每月单独进行测试,以减少出现 I 类错误的可能性。 我不知道从哪里开始,也不知道这是否可能,因为我在网上找不到任何东西。当然,我也愿意接受其他选择。

S.giganteus <- matrix(c(0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1, 6, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 7, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 6, 6, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 1, 4, 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 1, 4, 1, 0, 0), ncol = 7, byrow = T)
colnames (S.giganteus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (S.giganteus) <- c("feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", "jan")
S.giganteus <- as.table(S.giganteus)

P.melanotus <- matrix(c(0, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 4, 7, 6, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 2, 0, 0, 0, 0, 0, 1, 2, 1, 0, 0, 0, 0, 4, 1, 1, 0, 0, 0, 0, 0, 3, 5, 0, 0, 0, 0, 0, 3, 8, 1, 0, 0, 0, 0, 0, 3, 1, 0, 0, 0))
colnames (P.melanotus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (P.melanotus) <- c("feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec", "jan")
P.melanotus <- as.table(P.melanotus)

I do not know if this is even possible but I would like to do a multinomial goodness of fit chi-squared test. In other words, I would e.g. like to compare the proportions of S.giganteus individuals at different stages in a month to the actual number of individuals from P.melanotus.
I can't do a normal Chi-squared test because of differences in sampling effort and therefore unequal group sizes.
I would like to avoid testing each month individually to reduce my chances of a type I error.
I have no clue where to start or even if this is possible because I can't find anything online. I'm also open to other options of course.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眼角的笑意。 2025-01-22 23:13:55

我不确定此内容的目标是什么,但这就是我发现的。我确实想说,我不确定你所说的不均匀的组大小是什么意思,因为两者都是 12 x 7。

S.giganteus <- matrix(c(0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1, 6, 0, 0, 0, 
                        0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 7, 0, 0, 0, 0, 0,
                        0, 6, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 6, 
                        6, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 1, 
                        4, 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 1, 4, 
                         1, 0, 0), ncol = 7, byrow = T)
colnames (S.giganteus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (S.giganteus) <- c("feb", "mar", "apr", "may", "jun", "JUL", 
                            "aug", "sep", "oct", "nov", "dec", "jan")
(S.giganteus <- as.table(S.giganteus))

P.melanotus <- matrix(c(0, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 
                        0, 0, 0, 4, 7, 6, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 
                        0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 2, 0, 0, 0, 0, 
                        0, 1, 2, 1, 0, 0, 0, 0, 4, 1, 1, 0, 0, 0, 0, 0, 
                        3, 5, 0, 0, 0, 0, 0, 3, 8, 1, 0, 0, 0, 0, 0, 3, 
                        1, 0, 0, 0), ncol = 7, byrow = T)
colnames (P.melanotus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (P.melanotus) <- c("feb", "mar", "apr", "may", "jun", "JUL", 
                            "aug", "sep", "oct", "nov", "dec", "jan")
(P.melanotus <- as.table(P.melanotus))

然后我应用了卡方-

chisq.test(S.giganteus, P.giganteus)
# 
#   Pearson's Chi-squared test
# 
# data:  S.giganteus
# X-squared = 212.12, df = 66, p-value < 2.2e-16
#  

由于警告 –

警告消息:
在 chisq.test(S.giganteus, P.giganteus) 中:卡方近似可能不正确

我使用了 MC 模拟:

chisq.test(S.giganteus, P.giganteus, simulate.p.value = T)
# 
#   Pearson's Chi-squared test with simulated p-value (based on 2000
#   replicates)
# 
# data:  S.giganteus
# X-squared = 212.12, df = NA, p-value = 0.0004998
# 

I'm not sure what the objective is with this content, but this is what I found. I do want to say that I'm not sure what you mean about uneven group sizes because both come to 12 x 7.

S.giganteus <- matrix(c(0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 1, 6, 0, 0, 0, 
                        0, 0, 2, 2, 0, 0, 0, 0, 0, 1, 7, 0, 0, 0, 0, 0,
                        0, 6, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 6, 
                        6, 0, 0, 0, 0, 0, 0, 2, 3, 0, 0, 0, 0, 0, 0, 1, 
                        4, 0, 0, 0, 0, 0, 0, 4, 2, 0, 0, 0, 0, 0, 1, 4, 
                         1, 0, 0), ncol = 7, byrow = T)
colnames (S.giganteus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (S.giganteus) <- c("feb", "mar", "apr", "may", "jun", "JUL", 
                            "aug", "sep", "oct", "nov", "dec", "jan")
(S.giganteus <- as.table(S.giganteus))

P.melanotus <- matrix(c(0, 0, 0, 0, 4, 1, 0, 0, 0, 0, 0, 0, 6, 0, 0, 0, 
                        0, 0, 0, 4, 7, 6, 0, 0, 0, 0, 0, 0, 8, 0, 0, 0, 
                        0, 0, 0, 5, 0, 0, 0, 0, 0, 0, 7, 2, 0, 0, 0, 0, 
                        0, 1, 2, 1, 0, 0, 0, 0, 4, 1, 1, 0, 0, 0, 0, 0, 
                        3, 5, 0, 0, 0, 0, 0, 3, 8, 1, 0, 0, 0, 0, 0, 3, 
                        1, 0, 0, 0), ncol = 7, byrow = T)
colnames (P.melanotus) <- c("s1", "s2", "s3", "s4", "s5", "s6", "s7")
rownames (P.melanotus) <- c("feb", "mar", "apr", "may", "jun", "JUL", 
                            "aug", "sep", "oct", "nov", "dec", "jan")
(P.melanotus <- as.table(P.melanotus))

Then I applied Chi-squared-

chisq.test(S.giganteus, P.giganteus)
# 
#   Pearson's Chi-squared test
# 
# data:  S.giganteus
# X-squared = 212.12, df = 66, p-value < 2.2e-16
#  

Due to the warning–

Warning message:
In chisq.test(S.giganteus, P.giganteus) : Chi-squared approximation may be incorrect

I used MC simulation:

chisq.test(S.giganteus, P.giganteus, simulate.p.value = T)
# 
#   Pearson's Chi-squared test with simulated p-value (based on 2000
#   replicates)
# 
# data:  S.giganteus
# X-squared = 212.12, df = NA, p-value = 0.0004998
# 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文