R-使用ddply从ANOVA中提取p值

时间:2014-08-08 14:35:30

标签: r

我使用ddply函数进行了一些分析。

数据帧(long.format)结构如下:

'data.frame':   2058 obs. of  3 variables:
 $ tertile : Factor w/ 3 levels "1","2","3": 2 1 3 2 2 3 1 1 1 1 ...
 $ variable: Factor w/ 21 levels "age","ht","wt",..: 1 1 1 1 1 1 1 1 1 1 ...
 $ value   : num  57 57 65 58 59 56 63 63 68 58 ...

我使用ddply使用$ value在$ tertile中执行$ variable的anova,如下所示:

aovfun <- function(x)  aov(tertile~value,x)
y <- ddply(long.format, .(variable), aovfun)

随后的数据库给出了截距和斜率,但是我是否可以提取单个P值?

我附加了一个示例data.frame的代码,如下所示:

tertile = rep(1L:3L,9)

年龄= RNORM(9,60,5)

HT = RNORM(9,157,10)

重量= RNORM(9,70,5)

df&lt; - data.frame(tertile,age,ht,wt)

long.format&lt; - melt(df,id = c(&#34; tertile&#34;))

1 个答案:

答案 0 :(得分:1)

尝试:

 aovfun <- function(x) aov(value~tertile,x)
 ddply(long.format, .(variable), 
       function(x) summary.aov(aovfun(x))[[1]][["Pr(>F)"]])[,-3]

 #  variable         V1
 #1      age 0.06676654
 #2       ht 0.23854030
 #3       wt 0.88039549
相关问题