R/modelling.R
    align_coefs.RdExtracts and aligns the fixed-effect estimates from a list of fitted model objects,
returning them in a single tidy data frame with consistent columns for easy comparison.
Works with a mix of model types such as lm, glm, gls, lmer, etc.
For models without p-values (e.g., lmer), the function computes approximate
Wald statistics and two-sided normal p-values.
align_coefs(models)A named list of fitted model objects. Each element should be a
model that can be passed to broom::tidy().
A tibble with columns:
The name of the model (from the list).
The term name (coefficient).
The estimated coefficient.
The standard error.
The Wald statistic (estimate / std.error).
Two-sided normal p-value.
# Example using the built-in CO2 dataset
data(CO2)
# Fit models
lm_fit  <- lm(uptake ~ conc + Type + Treatment, data = CO2)
glm_fit <- glm(uptake ~ conc + Type + Treatment, family = Gamma(identity), data = CO2)
# Combine estimates
models_list <- list(lm = lm_fit, glm = glm_fit)
result <- align_coefs(models_list)
print(result)
#> # A tibble: 8 × 6
#>   model term             estimate std.error statistic  p.value
#>   <chr> <chr>               <dbl>     <dbl>     <dbl>    <dbl>
#> 1 lm    (Intercept)       29.3      1.54        19.0  2.08e-31
#> 2 lm    conc               0.0177   0.00230      7.72 2.87e-11
#> 3 lm    TypeMississippi  -12.7      1.35        -9.37 1.67e-14
#> 4 lm    Treatmentchilled  -6.86     1.35        -5.08 2.46e- 6
#> 5 glm   (Intercept)       28.5      1.70        16.8  6.84e-28
#> 6 glm   conc               0.0193   0.00253      7.62 4.47e-11
#> 7 glm   TypeMississippi  -12.0      1.38        -8.70 3.36e-13
#> 8 glm   Treatmentchilled  -7.22     1.28        -5.65 2.40e- 7