regression and plotting regression

@mattwarkentin solution is really nice and concise. I would follow his way. But, if you like to do a bit more primitive way using for loop, you can try as follows.

pre1<-setdiff(names(surgical), c("y", "pindex"))
mod_dres<-NULL
for (j in pre1) {
  model  <- lm(y  ~  pindex + get(j), data = surgical)
  bmodel <- pred <- broom::tidy(model)
  bmodel$term[3]<-j
  mod_dres<-rbind(mod_dres,bmodel)
}

mod_dres
#> # A tibble: 21 x 5
#>    term        estimate std.error statistic     p.value
#>    <chr>          <dbl>     <dbl>     <dbl>       <dbl>
#>  1 (Intercept)  -328.      241.      -1.36  0.180      
#>  2 pindex          9.23      2.82     3.27  0.00191    
#>  3 bcs            77.1      29.7      2.60  0.0123     
#>  4 (Intercept)  -792.      206.      -3.84  0.000341   
#>  5 pindex         10.2       2.27     4.49  0.0000410  
#>  6 enzyme_test    11.0       1.81     6.08  0.000000152
#>  7 (Intercept)  -206.      162.      -1.27  0.211      
#>  8 pindex          4.67      2.53     1.84  0.0709     
#>  9 liver_test    223.       40.0      5.58  0.000000935
#> 10 (Intercept)   267.      310.       0.861 0.393      
#> # … with 11 more rows
1 Like