在单个数据范围内获取几个回归的结果

发布于 2025-01-23 20:54:09 字数 876 浏览 2 评论 0原文

我有一个像这样的数据框架,有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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

唱一曲作罢 2025-01-30 20:54:09

您并没有真正给我们一个可重现的例子,但是我猜想将conf.int = true添加到您的tidy() call将执行您想要的(默认名称为conf.lowconf.high,您可以将调用添加到Rename(如果需要))。

我使工作流程“ pipier”变得有趣(但您的方式很好)。可能有一点选择所需的东西,或者可能将.id =参数添加到map_dfr(无法说没有MCVE )。

model_results <- (
 names(table)[4:14]
   %>% set_names()
   %>% map(~ reformulate(c(., "strata(matching)"), response = "status"))
   %>% map(clogit, data = table)
   %>% map_dfr(tidy, conf.int = TRUE, .id = "column")
)

You haven't really given us a reproducible example, but I'm going to guess that adding conf.int = TRUE to your tidy() call will do what you want (the default names are conf.low and conf.high, you can add a call to rename 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 to map_dfr (can't tell without a MCVE).

model_results <- (
 names(table)[4:14]
   %>% set_names()
   %>% map(~ reformulate(c(., "strata(matching)"), response = "status"))
   %>% map(clogit, data = table)
   %>% map_dfr(tidy, conf.int = TRUE, .id = "column")
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文