I've done multiple regression modeling in R using the below script. Now I'm wondering how can I make a table for the coefficients of each model of all models from lm, glm, and rf separately.
all_variables <- names(PaC09c_w20_dat3)
response_variables <- all_variables[c(1:3)]
predictors <- all_variables[-c(1:3)]
lm_model <- lapply(
response_variables,
function(x) lm(reformulate(termlabels = predictors, response = x), data = PaC09c_w20_dat3)
) |>
setNames(response_variables)
glm_model <- lapply(
response_variables,
function(x) glm(reformulate(termlabels = predictors, response = x), data = PaC09c_w20_dat3)
) |>
setNames(response_variables)
rf_ranger <- lapply(
response_variables,
function(x) ranger(reformulate(termlabels = predictors, response = x), data = PaC09c_w20_dat3, importance="impurity")
) |>
setNames(response_variables)
save.image(file="PaC09c_w20_Reg.RData")
Input data looks like (Original Table is very large),
head(PaC09c_w20_dat3)
EE87865ln1 EE87866ln1 EE87895ln1 blood_vessel_w20 adrenal_gland_w20 bone_element_w20 bronchus_w20
<dbl> <dbl> <dbl> <dbl> <dbl> <dbl> <dbl>
1 0.00391 0.00326 0.00332 0 0 1 0
2 0.00139 0.00116 0.00132 0 0 0 0
3 0.00360 0.00270 0.00469 1 1 0 1
4 0.00323 0.00348 0.00339 0 0 1 0
5 0.00323 0.00330 0.00382 0 1 0 0
6 0.00278 0.00208 0.00214 0 0 1 0
The expected output would look like this,
EE87865_lmcof EE87866_lmcof
blood_vessel_w20 6.332633e-06 5.916615e-06
adrenal_gland_w20 -2.159470e-06 -2.399176e-06
bone_element_w20 8.578804e-06 8.106153e-06
bronchus_w20 -2.956291e-05 -2.152231e-05