Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

get the results of several regressions in a single dataframe

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)

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

>Solution :

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")
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading