0

I did run a logistic regression model fit in R for some dataset. I can see the Coefficients per predictor via summary(model_fit), but now I need to store them in a data frame. Below are my values how I see them via summary.

Coefficients:
                             Estimate Std. Error z value Pr(>|z|)  
(Intercept)                -4.387e+00  2.734e+00  -1.605   0.1086  
GDP_PER_CAP                -6.888e-05  3.870e-05  -1.780   0.0751 .
CO2_PER_CAP                 1.816e-01  7.255e-02   2.503   0.0123 *
PERC_ACCESS_ELECTRICITY    -5.973e-03  1.291e-02  -0.463   0.6437  
ATMS_PER_1E5               -5.749e-03  8.181e-03  -0.703   0.4822  
PERC_INTERNET_USERS        -2.146e-02  2.106e-02  -1.019   0.3083  
SCIENTIFIC_ARTICLES_PER_YR  3.319e-05  1.650e-05   2.011   0.0443 *
PERC_FEMALE_SECONDARY_EDU   1.559e-01  6.428e-02   2.426   0.0153 *
PERC_FEMALE_LABOR_FORCE    -1.265e-02  1.470e-02  -0.860   0.3896  
PERC_FEMALE_PARLIAMENT     -4.802e-02  2.087e-02  -2.301   0.0214 *

dataframe <- dataframe0 %>%
  mutate(EQUAL_PAY = relevel(factor(EQUAL_PAY), "YES"))

set.seed(1)
trn_index = createDataPartition(y = dataframe$EQUAL_PAY, p = 0.80, list = FALSE)
trn_equalpay = dataframe[trn_index, ]
tst_equalpay = dataframe[-trn_index, ]

equalpay_lgr = train(EQUAL_PAY ~ .-EQUAL_WORK -COUNTRY, method = "glm",
               family = binomial(link = "logit"), data = trn_equalpay,
               trControl = trainControl(method = 'cv', number = 10))

???? coefficients <- summary(equalpay_lgr)
kath
  • 7,624
  • 17
  • 32
Willem
  • 1
  • 3

1 Answers1

0

You should definitely check out the broom package, which does lots of stuff like this. You can find an introduction to that package here.

For your question, the solution is tidy from broom. Using the example from the link above:

library(broom)
tidy(lmfit)

## # A tibble: 2 x 5
##   term        estimate std.error statistic  p.value
##   <chr>          <dbl>     <dbl>     <dbl>    <dbl>
## 1 (Intercept)    37.3      1.88      19.9  8.24e-19
## 2 wt             -5.34     0.559     -9.56 1.29e-10

As you can see, tidy returns a tibble (a type of data frame) that contains a column estimate. This is the coefficient you're looking for.

A. Stam
  • 2,148
  • 14
  • 29