在单个数据范围内获取几个回归的结果
我有一个像这样的数据框架,有10列酒精(从酒精1到酒精10),
ID Status matching Alcohol1 Alcohol2
1 1 1 1 0
2 0 1 0 1
3 0 2 0 1
4 1 2 0 0
我有许多逻辑回归模型,可以使用酒精柱作为解释变量运行。我创建了一个执行此功能的函数。
现在,我想在一个数据框架中总结我所有模型的结果。 我需要我的估计系数,我的95%置信区间的下限,上限和PVALUE。我设法获得了我的估计系数和PVALUE,但我无法获得置信区间(或差异也适合)(通常是通过摘要获得的)
是我使用的功能:
library(broom)
library(purrr)
f1 <- function(column) {
tidy(clogit(
as.formula(
paste("status ~", column, "+ strata(matching)")),
data = table
))
}
model_results <- map_dfr(
set_names(names(table)[4:14]),
f1
)
预期的结果将是某种东西像这样,
term estimate lower.95 upper.95 pvalue
Alcohol1
Alcohol2
…
谢谢您的帮助
I have a dataframe like this one, with 10 columns Alcohol (from alcohol1 to alcohol10)
ID Status matching Alcohol1 Alcohol2
1 1 1 1 0
2 0 1 0 1
3 0 2 0 1
4 1 2 0 0
I have many logistic regression models to run using the alcohol columns as explanatory variables. I have created a function that performs this.
And now I would like to summarize the results of all my models in one data frame.
I need my estimated coefficient, the lower bound of my 95% confidence interval, the upper bound and the pvalue. I managed to get my estimated coefficient and the pvalue but I can't get the confidence interval (or the variance which would also fit) (which is normally obtained with a summary)
Here are the functions I used:
library(broom)
library(purrr)
f1 <- function(column) {
tidy(clogit(
as.formula(
paste("status ~", column, "+ strata(matching)")),
data = table
))
}
model_results <- map_dfr(
set_names(names(table)[4:14]),
f1
)
The expected result would be something like this
term estimate lower.95 upper.95 pvalue
Alcohol1
Alcohol2
…
thank you in advance for the help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您并没有真正给我们一个可重现的例子,但是我猜想将
conf.int = true
添加到您的tidy()
call将执行您想要的(默认名称为conf.low
和conf.high
,您可以将调用添加到Rename
(如果需要))。我使工作流程“ pipier”变得有趣(但您的方式很好)。可能有一点
选择
所需的东西,或者可能将.id =
参数添加到map_dfr
(无法说没有MCVE )。You haven't really given us a reproducible example, but I'm going to guess that adding
conf.int = TRUE
to yourtidy()
call will do what you want (the default names areconf.low
andconf.high
, you can add a call torename
if you want).I made the workflow "pipier" for fun (but your way is perfectly fine). There might be a little bit of
select
stuff required, or possibly adding a.id =
argument tomap_dfr
(can't tell without a MCVE).