从名为“m”的“lm”对象中提取 R^2 值
summary(m)$r.squared
您始终可以使用该str()
函数查看 R 中对象的结构;在这种情况下你想要str(summary(m))
但是,尚不清楚您要在这里完成什么。lm()
在您指定 的函数的公式参数中selectionArray ~ 0
,这没有意义有两个原因:1)如前所述,公式右侧的 0 对应于一个模型,其中您的预测变量是一个零向量和无法定义与该预测变量对应的 beta 系数。2) 你的结果 selectionArray 是一个矩阵。据我所知,lm()
没有设置为具有多个结果。
您是否尝试测试 selectionArray 的每一列与 0 不同的重要性?如果是这样,任何至少有一次成功 (1) 的列都与 0 列显着不同。如果您对每列中成功概率的置信区间感兴趣,请使用以下代码。请注意,这不会针对多重比较进行调整。
首先让我们从一个玩具示例开始来演示这个概念
v1 <- rbinom(100,size=1,p=.25)
#create a vector, length 100,
#where each entry corresponds to the
#result of a bernoulli trial with probability p
binom.test(sum(v1), n=length(v1), p = 0)
##let's pretend we didn't just generate v1 ourselves,
##we can use binom.test to determine the 95% CI for p
#now in terms of what you want to do...
#here's a dataset that might be something like yours:
selectionArray <- sapply(runif(10), FUN=function(.p) rbinom(100,size=1,p=.p))
#I'm just generating 10 vectors from a binomial distribution
#where each entry corresponds to 1 trial and each column
#has a randomly generated p between 0 and 1
#using a for loop
#run a binomial test on each column, store the results in binom.test.results
binom.test.results <- list()
for(i in 1:ncol(selectionArray)){
binom.test.results[[i]] <- binom.test(sum(selectionArray[,i]),
n=nrow(selectionArray), p=0)
}
#for loops are considered bad programming in r, so here's the "right" way to do it:
binom.test.results1 <- lapply(as.data.frame(selectionArray), function(.v){
binom.test(sum(.v), n=nrow(selectionArray), p = 0)
})
#using str() on a single element of binom.test.result will help you
#identify what results you'd like to extract from each test