Select and list the same parameter from multiple models
JulianGaviriaL opened this issue · 2 comments
JulianGaviriaL commented
I have multiple (>300) models like:
m001 <- lm(Observations ~ Group ,data=r_001)
sm001<-standardize_parameters(m001)
> sm001
# Standardization method: refit
Parameter | Std. Coef. | 95% CI
----------------------------------------
(Intercept) | 0.16 | [-0.41, 0.73]
Grouppre | -0.30 | [-0.90, 0.30]
GenderM | -0.18 | [-0.70, 0.34]
Age | -0.11 | [-0.35, 0.14]
EducationE2 | -0.11 | [-0.78, 0.56]
EducationE3 | 0.13 | [-0.49, 0.74]
sm301<-standardize_parameters(m301)
> sm301
# Standardization method: refit
Parameter | Std. Coef. | 95% CI
----------------------------------------
(Intercept) | 0.16 | [-0.41, 0.73]
Grouppre | 0.38 | [-0.90, 0.60]
GenderM | -0.18 | [-0.70, 0.34]
Age | -0.11 | [-0.35, 0.14]
EducationE2 | -0.11 | [-0.78, 0.56]
EducationE3 | 0.13 | [-0.49, 0.74]
How can I select and list the same parameter (i.e, "Grouppre") from each "sm" object in the environment?
I unsucceed with the following loop:
require(foreach)
output_position <- grep("sm",ls())
all_effects <- foreach(i=output_position,.combine="rbind") %do% {
output <- get(ls()[i])
unlist(output["Grouppre",])
}
rownames(all_effects) <- ls()[output_position]
all_effects
strengejacke commented
The example looks strange, I wonder where the coefficients like age
etc. come from. If you want to keep only specific parameters, use arguments keep
and drop
(see https://easystats.github.io/parameters/reference/model_parameters.default.html).
mattansb commented
m001 <- lm(mpg ~ ., data = mtcars)
m002 <- lm(hp ~ ., data = mtcars)
mod_names <- ls() |> Filter(f = \(x) startsWith(x, "m00"))
mod_list <- lapply(setNames(nm = mod_names), get)
parameters::compare_parameters(mod_list,
keep = "am",
standardize = "refit")
#> Parameter | m001 | m002
#> ------------------------------------------------------
#> am | 0.21 (-0.15, 0.56) | 0.07 (-0.25, 0.38)
#> ------------------------------------------------------
#> Observations | 32 | 32
Created on 2023-12-07 with reprex v2.0.2