我在R上尝试了一段时间,我似乎无法提取p值(" Pr(> f)的值)"进行levene测试。对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
此外,以类似的方式进行jar测试我无法以同样的方式提取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
感谢您的帮助
答案 0 :(得分:2)
有几种方法。以下是一个可重复的示例:
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
答案 1 :(得分:0)
您还可以使用levene.test
包中的lawstat
功能:
> df<-data.frame(group=c(rep(LETTERS[1],20),rep(LETTERS[2],20)),
value=c(sample(1:10,size=20,replace=T),sample(30:40,size=20,replace=T)))
> df
group value
1 A 8
2 A 4
3 A 8
4 A 3
5 A 2
6 A 3
7 A 4
8 A 5
9 A 8
10 A 6
11 A 1
12 A 4
13 A 9
14 A 7
15 A 8
16 A 4
17 A 2
18 A 10
19 A 8
20 A 7
21 B 40
22 B 37
23 B 39
24 B 30
25 B 30
26 B 30
27 B 34
28 B 39
29 B 40
30 B 34
31 B 30
32 B 33
33 B 32
34 B 39
35 B 36
36 B 37
37 B 35
38 B 39
39 B 34
40 B 34
> library(lawstat)
> levene.test(df$value,df$group,location='median')
modified robust Brown-Forsythe Levene-type test based on the absolute deviations from the median
data: df$value
Test Statistic = 1.7537, p-value = 0.1933
> levene.test(df$value,df$group,location='median')$p.value
[1] 0.1933243
答案 2 :(得分:0)
您还可以编写leveneTest(all.vec,factors)$ F value