variable-importance-ranking-and-interpretation
Summary
Ranks and visualizes metabolite importance in random forest classification models to identify which compounds discriminate between experimental groups. This skill extracts feature importance scores from a fitted random forest model and generates publication-ready plots, enabling interpretation of which metabolites drive group separation in metabolomics datasets.
When to use
After fitting a random forest classifier to metabolomics count data with a binary or multiclass grouping variable (e.g., treatment, genotype, disease status), use this skill to identify which metabolites are most predictive of group membership and to communicate their relative importance in a figure.
When NOT to use
- Input random forest model was not fitted to metabolomics count data or was trained on pre-aggregated/collapsed features rather than individual metabolites.
- Grouping variable is continuous (e.g., pH, age in years) rather than categorical; random forest importance is designed for classification tasks, not regression.
- Dataset has extreme class imbalance or very few samples per group, making importance scores unreliable due to instability in tree construction.
Inputs
- randomForest model object (output from Omu's random_forest wrapper function)
- Metabolomics count data (c57_nos2KO_mouse_countDF or equivalent count matrix)
- Metadata with grouping factor (e.g., Treatment, Grouped column from c57_nos2KO_mouse_metadata)
Outputs
- ggplot2 object showing ranked metabolite importance scores
- Variable importance ranking (metabolite names and scores)
- Publication-ready visualization customizable with ggplot2 themes
How to apply
Call the plot_variable_importance function on the random forest model object returned by the Omu random_forest wrapper. This function extracts variable importance scores (which measure the decrease in impurity, typically Gini importance, across all splits in the forest) and produces a ggplot2 object ranking metabolites by importance. The resulting plot can be customized with standard ggplot2 themes (e.g., theme_bw) to remove gridlines or adjust aesthetics. Importance scores reflect the average discriminative power of each metabolite across all trees; metabolites with higher scores contributed more to correct classification. Inspect the top-ranked metabolites to identify which compounds or metabolite classes best separate your experimental groups.
Related tools
- randomForest (Underlying R package that implements the random forest algorithm; Omu's random_forest wrapper calls randomForest with default hyperparameters and returns a model object containing importance scores.) — https://cran.r-project.org/web/packages/randomForest/
- ggplot2 (Produces the variable importance plot as a ggplot2 object, allowing customization with themes, coordinate flips, and geom modifications.) — https://ggplot2.tidyverse.org/
- Omu (R package containing the random_forest wrapper function and plot_variable_importance function that extract and visualize variable importance from randomForest models applied to metabolomics data.) — https://github.com/connor-reid-tiffany/Omu
Examples
model <- random_forest(count_data=c57_nos2KO_mouse_countDF, metadata=c57_nos2KO_mouse_metadata, response='Metabolite', grouping='Treatment'); plot_variable_importance(model) + theme_bw() + theme(panel.grid=element_blank())
Evaluation signals
- Variable importance plot displays all metabolites ranked by importance score in descending order; top metabolites should correspond to compounds known to differ between experimental groups.
- Importance scores are non-negative and sum to a total reflecting the model's discriminative power; verify no scores are NaN or Inf.
- Plot is a ggplot2 object that responds to ggplot2 theme functions (e.g., theme_bw); custom themes can be applied without error.
- Random forest model accuracy or out-of-bag error rate is reasonable (better than random guessing) on the grouping variable; poor model performance indicates importance scores may be uninformative.
- Top-ranked metabolites, when manually inspected in the original count data, show visibly different distributions or mean abundance across groups.
Limitations
- Variable importance scores depend on default randomForest hyperparameters (mtry, ntree, etc.) documented in the randomForest package; changing these parameters may alter rankings.
- Importance is biased toward high-cardinality features in some implementations; metabolites with many unique values may receive inflated importance scores.
- Importance does not measure effect size or biological significance; a metabolite can rank high while having a small log-fold-change between groups.
- No built-in statistical significance test for importance scores; practitioners should consider permutation testing or cross-validation to assess ranking stability.
- Omu's documentation does not specify the exact importance metric (Gini, permutation, etc.) used by the random_forest wrapper, making it difficult to reproduce or compare with other implementations.
Evidence
- [other] Extract variable importance: "Generate a variable importance plot using plot_variable_importance on the random forest model object, which produces a ggplot2 object"
- [other] Customize with ggplot2: "customize with ggplot2 themes as desired (e.g., theme_bw, remove gridlines)"
- [other] Random forest wrapper in Omu: "Omu has a function,
random_forest, which is a wrapper built around the function randomForest from the R package randomForest"
- [other] ggplot2 compatibility: "The figure is a ggplot2 object, so it is compatible with any ggplot2 themes"
- [other] Model output structure: "Extract the returned random forest model object and associated metadata from the wrapper output"
1---2name: variable-importance-ranking-and-interpretation3description: Use when after fitting a random forest classifier to metabolomics count data with a binary or multiclass grouping variable (e.4license: CC-BY-4.05---67# variable-importance-ranking-and-interpretation89## Summary1011Ranks and visualizes metabolite importance in random forest classification models to identify which compounds discriminate between experimental groups. This skill extracts feature importance scores from a fitted random forest model and generates publication-ready plots, enabling interpretation of which metabolites drive group separation in metabolomics datasets.1213## When to use1415After fitting a random forest classifier to metabolomics count data with a binary or multiclass grouping variable (e.g., treatment, genotype, disease status), use this skill to identify which metabolites are most predictive of group membership and to communicate their relative importance in a figure.1617## When NOT to use1819- Input random forest model was not fitted to metabolomics count data or was trained on pre-aggregated/collapsed features rather than individual metabolites.20- Grouping variable is continuous (e.g., pH, age in years) rather than categorical; random forest importance is designed for classification tasks, not regression.21- Dataset has extreme class imbalance or very few samples per group, making importance scores unreliable due to instability in tree construction.2223## Inputs2425- randomForest model object (output from Omu's random_forest wrapper function)26- Metabolomics count data (c57_nos2KO_mouse_countDF or equivalent count matrix)27- Metadata with grouping factor (e.g., Treatment, Grouped column from c57_nos2KO_mouse_metadata)2829## Outputs3031- ggplot2 object showing ranked metabolite importance scores32- Variable importance ranking (metabolite names and scores)33- Publication-ready visualization customizable with ggplot2 themes3435## How to apply3637Call the plot_variable_importance function on the random forest model object returned by the Omu random_forest wrapper. This function extracts variable importance scores (which measure the decrease in impurity, typically Gini importance, across all splits in the forest) and produces a ggplot2 object ranking metabolites by importance. The resulting plot can be customized with standard ggplot2 themes (e.g., theme_bw) to remove gridlines or adjust aesthetics. Importance scores reflect the average discriminative power of each metabolite across all trees; metabolites with higher scores contributed more to correct classification. Inspect the top-ranked metabolites to identify which compounds or metabolite classes best separate your experimental groups.3839## Related tools4041- **randomForest** (Underlying R package that implements the random forest algorithm; Omu's random_forest wrapper calls randomForest with default hyperparameters and returns a model object containing importance scores.) — https://cran.r-project.org/web/packages/randomForest/42- **ggplot2** (Produces the variable importance plot as a ggplot2 object, allowing customization with themes, coordinate flips, and geom modifications.) — https://ggplot2.tidyverse.org/43- **Omu** (R package containing the random_forest wrapper function and plot_variable_importance function that extract and visualize variable importance from randomForest models applied to metabolomics data.) — https://github.com/connor-reid-tiffany/Omu4445## Examples4647```48model <- random_forest(count_data=c57_nos2KO_mouse_countDF, metadata=c57_nos2KO_mouse_metadata, response='Metabolite', grouping='Treatment'); plot_variable_importance(model) + theme_bw() + theme(panel.grid=element_blank())49```5051## Evaluation signals5253- Variable importance plot displays all metabolites ranked by importance score in descending order; top metabolites should correspond to compounds known to differ between experimental groups.54- Importance scores are non-negative and sum to a total reflecting the model's discriminative power; verify no scores are NaN or Inf.55- Plot is a ggplot2 object that responds to ggplot2 theme functions (e.g., theme_bw); custom themes can be applied without error.56- Random forest model accuracy or out-of-bag error rate is reasonable (better than random guessing) on the grouping variable; poor model performance indicates importance scores may be uninformative.57- Top-ranked metabolites, when manually inspected in the original count data, show visibly different distributions or mean abundance across groups.5859## Limitations6061- Variable importance scores depend on default randomForest hyperparameters (mtry, ntree, etc.) documented in the randomForest package; changing these parameters may alter rankings.62- Importance is biased toward high-cardinality features in some implementations; metabolites with many unique values may receive inflated importance scores.63- Importance does not measure effect size or biological significance; a metabolite can rank high while having a small log-fold-change between groups.64- No built-in statistical significance test for importance scores; practitioners should consider permutation testing or cross-validation to assess ranking stability.65- Omu's documentation does not specify the exact importance metric (Gini, permutation, etc.) used by the random_forest wrapper, making it difficult to reproduce or compare with other implementations.6667## Evidence6869- [other] Extract variable importance: "Generate a variable importance plot using plot_variable_importance on the random forest model object, which produces a ggplot2 object"70- [other] Customize with ggplot2: "customize with ggplot2 themes as desired (e.g., theme_bw, remove gridlines)"71- [other] Random forest wrapper in Omu: "Omu has a function, ```random_forest```, which is a wrapper built around the function ```randomForest``` from the R package randomForest"72- [other] ggplot2 compatibility: "The figure is a ggplot2 object, so it is compatible with any ggplot2 themes"73- [other] Model output structure: "Extract the returned random forest model object and associated metadata from the wrapper output"