如何使用 ldply()-summarise-function 中的 summary-function 来提取 p 值?
示例数据:
(预装数据框“嘌呤霉素”)
library(reshape2)
library(plyr)
Puromycin.m <- melt( Puromycin , id=c("state") )
Puro.models <- dlply( Puromycin.m , .(variable) , glm , formula = state ~ value ,
family = binomial )
我可以用提取的结果构造这个数据框:
ldply( Puro.models , summarise , "n in each model" = length(fitted.values) ,
"Coefficients" = coefficients[2] )
但我不能以同样的方式提取 p 值。我认为这会起作用,但它不会:
ldply( Puro.models , summarise ,
"n in each model" = length(fitted.values) ,
"Coefficients" = coefficients[2],
"P-value" = function(x) summary(x)$coef[2,4] )
我怎样才能将p值提取到该数据框:)请帮忙!