I want to do liner regression analysis between response variable(y) and predictor variables(for each independently considering variable pindex as confounding variable) and eventually I want to plot the significant predictor variable estimated regression vs the response variable in a ggplot2.
I know the formula how to do liner regression and I can do it for each one by one
( lm(y ~ pindex + predictor, data = surgical)).
For example, for liver and enzyme
# for enzyme modle_enzyme <- lm(y ~ pindex + enzyme_test) enzy <- pred <- broom::tidy(modle_enzyme ) # for liver modle_liver <- lm(y ~ pindex + liver_test) etc for each liver <- broom::tidy(modle_liver ) all <- bind_rows(enzy, liver, ...)
But doing this is really tiresome for large data set.
So I was wondering if some one can show me how to do it using loop function.
The data can be found here
library(olsrr) data( surgical)