Min. 1st Qu. Median Mean 3rd Qu. Max.
11.9 81.4 147.6 204.9 270.7 1391.7
Since we model with interactions later, the latter VIF are relevant for us. Given that they are very high (c.f. median and max), we would have no hope of finding any significant results in the full interaction model. Therefore, we will first perfom a variable selection, to reduce the VIF and enable us to find significant effects.
All Interactions: Mediators ~ (GIS)^2
In [7]:
Code: Print Coef Table
# Elegant function to create coefficient tables from model summarieslibrary(dplyr)
Attaching package: 'dplyr'
The following objects are masked from 'package:stats':
filter, lag
The following objects are masked from 'package:base':
intersect, setdiff, setequal, union
Code: Print Coef Table
library(tidyr)library(knitr)library(purrr)#' Create a formatted coefficient table from model summary list#' #' @param model_summaries List of model summaries (e.g., output from lapply(models, summary))#' @param sig_threshold Significance threshold for bold formatting (default: 0.001)#' @param covariate_order Optional vector specifying order of covariates#' @return Formatted table with models as columns and covariates as rowscreate_coef_table <-function(model_summaries, sig_threshold =0.001, covariate_order =NULL) {# Extract and format coefficients for all models format_model_coef <-function(coef_matrix, model_name) { estimates <- coef_matrix[, "Estimate"] p_values <- coef_matrix[, "Pr(>|t|)"]# Format with significance stars (common notation) formatted_coef <-sapply(seq_along(estimates), function(i) { est_str <-sprintf("%.3f", estimates[i]) stars <-case_when( p_values[i] <0.001~"***", p_values[i] <0.01~"**", p_values[i] <0.05~"*", p_values[i] <0.1~".",TRUE~"" )paste0(est_str, stars) })tibble(Model = model_name,Covariate =rownames(coef_matrix),Coefficient = formatted_coef ) }# Process all models and create wide table coef_list <-map(model_summaries, coef) results_table <-map2_dfr(coef_list, names(coef_list), format_model_coef) %>%pivot_wider(names_from = Model, values_from = Coefficient, values_fill ="")# Apply covariate orderingif (is.null(covariate_order)) {# Default: Intercept first, then alphabetical all_covariates <-unique(results_table$Covariate) covariate_order <-c("(Intercept)", sort(all_covariates[all_covariates !="(Intercept)"])) }# Filter and reorder covariates results_table <- results_table %>%filter(Covariate %in% covariate_order) %>%slice(match(covariate_order, Covariate))kable(results_table, format ="pipe",align =c("l", rep("c", ncol(results_table) -1)))}