[英]R - use of ddply to extract p value from an ANOVA
I am stuck on a bit of analysis using the ddply function. 我被困在使用ddply函数的分析上。
The dataframe ( long.format
) structure is as follows: 数据帧(
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 ...
I have used ddply to perform anova of $variable across $tertile using $value as follows: 我已经使用ddply使用$ value跨$ tertile执行$ variable的变量方差分析,如下所示:
aovfun <- function(x) aov(tertile~value,x)
y <- ddply(long.format, .(variable), aovfun)
The subsequent database gives me the intercept and slope but is there way i can extract individual P values as well? 后续的数据库为我提供了截距和斜率,但是有没有办法我也可以提取单个P值?
I have attached a code for an example data.frame as below: 我已为以下示例数据附加了代码:
tertile = rep(1L:3L,9) 三分位= rep(1L:3L,9)
age=rnorm(9,60,5) 年龄= RNORM(9,60,5)
ht=rnorm(9,157,10) HT = RNORM(9,157,10)
wt=rnorm(9,70,5) 重量= RNORM(9,70,5)
df <- data.frame(tertile,age,ht,wt) df <-data.frame(tertile,age,ht,wt)
long.format <- melt(df,id=c("tertile")) long.format <-melt(df,id = c(“ tertile”))
Try: 尝试:
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.