从名为“M”
summary(m)$r.squared
你总是可以通过使用str()
功能查看R中的物体的结构的“LM”对象提取R^2值;在这种情况下,你想str(summary(m))
但是,目前还不清楚你在这里要完成什么。在lm()
函数的公式参数中指定selectionArray ~ 0
,这是没有意义的,原因有两个:1)如前面暗示的,公式右侧的0对应于一个模型,其中预测变量是无法定义与此预测器对应的零和β系数。 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