【发布时间】:2019-06-13 20:52:09
【问题描述】:
我在大约 700,000 列上重复 lm 函数。我正在使用 apply 函数在我的数据中的列上重复 lm 。然后我需要提取所有 pvalues。当我打印 lm 函数的摘要时,pvalue 列在 Pr(>|t|) 下。
我曾尝试使用pvals <- sapply(result,"[[", "p.value"),但结果为 NULL。
这是现在打印 3 列的 lm 摘要的代码(我正在使用较小的文件进行测试)。
result <- apply(dat4[,-c(1:27)], 2, function(x) {
summary(lm(x ~ total + age + female + diagnosis_MDD + diagnosis_BP))
})
result
这只是一列的输出:
$cg05451842
Call:
lm(formula = x ~ total + age + female + diagnosis_MDD + diagnosis_BP)
Residuals:
Min 1Q Median 3Q Max
-0.008621 -0.002647 0.001077 0.002979 0.006320
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.658e-02 3.428e-03 7.753 1.72e-09
total -3.603e-04 1.007e-03 -0.358 0.7224
age -1.123e-04 6.765e-05 -1.659 0.1049
female 7.997e-04 1.268e-03 0.631 0.5318
diagnosis_MDD -3.487e-03 1.534e-03 -2.273 0.0285
diagnosis_BP -1.692e-03 1.586e-03 -1.067 0.2926
Signif. codes: 0 0.001 0.01 0.05 0.1 1
Residual standard error: 0.004242 on 40 degrees of freedom
Multiple R-squared: 0.1723, Adjusted R-squared: 0.06879
F-statistic: 1.665 on 5 and 40 DF, p-value: 0.1654
【问题讨论】: