I would like to create a table of linear models with all independent variables at the top, and all dependent variables on the left side. This can be done using the tab_model function of the sjPlot package: https://cran.r-project.org/web/packages/sjPlot/vignettes/tab_model_estimates.html.
While the documentation specifies how to get a multi-model table from inputting each model one-by-one (m1, m2, m3 etc), what I have is a purr-derived list of linear models. I searched the documentation and online forums but can't find anything on how to do this. This is an example:
library(sjPlot)
library(sjmisc)
library(sjlabelled)
library(tidyverse)
df <- data.frame(study_id = c(1:20),
leptin = runif(20),
insulin = runif(20),
gene1 = runif(20),
gene2 = runif(20),
age = runif(20, min = 20, max = 45),
sex = sample(c(0,1), size = 20, replace = TRUE))
model_function_covariates_for_table <- function(x,y) {
M1 <- paste0(x, "~", y, "+ age + sex")
M1_fit <- lm(M1, data = df)
return(M1_fit)
}
bioactives <- names(df)[c(2:3)]
genes <- names(df)[c(4:5)]
bioactives <- purrr::set_names(bioactives)
genes <- purrr::set_names(genes)
# Works
m <- model_function_covariates_for_table("leptin", "gene1")
tab_model(m)
# Doesn't work
m <- map(bioactives,
~map(genes, model_function_covariates_for_table, y = .x))
tab_model(m)
Error message:
Error in if (fam.info$is_linear) transform <- NULL else transform <- "exp" :
argument is of length zero
In addition: Warning message:
Could not access model information.
Thanks in advance for any advice.

