gpt4 book ai didi

r - Levene 检验提取 p 值?

转载 作者:行者123 更新时间:2023-11-28 20:30:36 27 4
gpt4 key购买 nike

我已经在 R 上尝试了一段时间,但我似乎无法提取用于 levene 测试的 p 值(“Pr(>f) 的值)”。对 R 进行统计测试的常用方法是在测试命令末尾加上 $p.value。然而,这似乎不适用于 Levene 测试,如下所示:

> leveneTest(all.vec,factors)
Levene's Test for Homogeneity of Variance (center = median)
Df F value Pr(>F)
group 3 8.9261 6.982e-06 ***
2607
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
> leveneTest(all.vec,factors)$p.value
NULL

此外,对于 jarque bera 测试,我无法以类似的方式提取 p.value

> jarque.bera.test(lg.day.ret.vec)

Jarque Bera Test

data: lg.day.ret.vec
X-squared = 63087.83, df = 2, p-value < 2.2e-16

> jarque.bera.test(lg.day.ret.vec)$p.value
X-squared
0

感谢帮助

最佳答案

有几种方法。这是一个可重现的示例:

library("car")
test <- with(Moore, leveneTest(conformity, fcategory))

首先,查看返回对象的结构,因为它通常会告诉您正在玩什么:

str(test)

这给出:

> str(test)
Classes ‘anova’ and 'data.frame': 2 obs. of 3 variables:
$ Df : int 2 42
$ F value: num 0.046 NA
$ Pr(>F) : num 0.955 NA
- attr(*, "heading")= chr "Levene's Test for Homogeneity of Variance (center = median)"

我们看到该对象是一个数据框,p 值位于第 3 列。因此,以下任何一项都将提取数据

test[,3]          # pull out the entire 3rd column
test[1,3] # pull out only the none NA p-value
test$`Pr(>F)` # pull out the P-value column by name
test$`Pr(>F)`[1] # as above, but then take only the 1st element

对于上面的例子,这些给出了:

> test[,3]
[1] 0.9550975 NA
> test[1,3]
[1] 0.9550975
> test$`Pr(>F)`
[1] 0.9550975 NA
> test$`Pr(>F)`[1]
[1] 0.9550975

关于r - Levene 检验提取 p 值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28597487/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com