For "midimps" collection objects, ggmid() visualizes and compares the importance of component functions across multiple fitted MID models.
Arguments
- object
a "midimps" collection object to be visualized.
- type
the plotting style. One of "barplot", "dotchart", or "series".
- theme
a character string or object defining the color theme. See
color.themefor details.- terms
an optional character vector specifying which terms to display. If
NULL, terms are automatically extracted from the object.- max.nterms
the maximum number of terms to display. Defaults to 15.
- labels
an optional numeric or character vector to specify the model labels. Defaults to the labels found in the object.
- ...
optional parameters passed on to the main layer (e.g.,
geom_col).
Details
This is an S3 method for the ggmid() generic that creates a comparative importance plot from a "midimps" collection object. It visualizes the average contribution of component functions to the fitted MID models, allowing for easy comparison across different models.
The type argument controls the visualization style:
The default, type = "barplot", creates a standard grouped bar plot where the length of each bar represents the overall importance of the term, positioned side-by-side by model label.
The type = "dotchart" option creates a grouped dot plot, offering a clean alternative to the bar plot for visualizing and comparing term importance across models.
The type = "series" option plots the importance trend over the models for each component function.
Examples
data(mtcars, package = "datasets")
# Fit two different models for comparison
mid1 <- interpret(mpg ~ wt + hp + cyl, data = mtcars)
#> 'model' not passed: response variable in 'data' is used
mid2 <- interpret(mpg ~ (wt + hp + cyl)^2, data = mtcars)
#> 'model' not passed: response variable in 'data' is used
# Calculate importance for both models and combine them
imps <- midlist(
"Main Effects" = mid.importance(mid1),
"Interactions" = mid.importance(mid2)
)
# Create a comparative grouped bar plot (default)
ggmid(imps)
# Create a comparative dot chart with a specific theme
ggmid(rev(imps), type = "dotchart", theme = "Okabe-Ito")
# Create a series plot to observe trends across models
ggmid(imps, type = "series")
