Skip to content

Major revision#1

Merged
patrickthoral merged 25 commits into
mainfrom
revision
Feb 26, 2026
Merged

Major revision#1
patrickthoral merged 25 commits into
mainfrom
revision

Conversation

@patrickthoral

Copy link
Copy Markdown
Owner

Improve analyses based on review

Consolidate and DRY feature-importance logic into a single feature_importance() handler that supports both methods (standardized_coefficients and maximum_utility_contribution) and model types (binary, multinomial). Add feature_importance_all() to run across groups, add wrappers standardized_coefficients() and maximum_utility_contribution() that accept modeltype and group, and improve coefficient parsing (including multinomial alternatives). Change read/write paths to use inst/extdata layout and write outputs to extdata/feature_importance/<method>/<modeltype>/<group>.csv. Also improve console printing and computation of standardized coefficients and max utility contributions.
Rewrite plot_relative_importance to handle multiple groups and model types (binary + multinomial). Reads data from extdata, joins human-readable criteria, and builds separate ggplots for binary (single bars) and multinomial (patterned grouped bars via ggpattern), saving PNG/SVG to extdata/figures/<modeltype>/. Returns a nested list of plots and emits simple progress messages. Also removes the now-unneeded coefficient_to_variable helper and consolidates file/path handling.
Rewrite plot_group_comparison to support binary and multinomial model types and return a list of ggplots. Key changes: switch saved figure paths to extdata/figures, restructure loops to iterate over model types and comparisons, load data via fs::path and per-model feature importance files, extract/normalize coefficient variable names (including multinomial alternatives), join feature importance and Wald results, add facetting for multinomial alternatives, compute and draw significance annotations per model type, save PNG/SVG into model-specific subfolders, and return all generated plots. Also update roxygen docs to indicate a list of ggplots is returned.
Introduce run_linearity_tests() (R) to assess functional form of multi-level ordered covariates. The function creates level dummies and quadratic terms, fits linear, quadratic and level-specific (dummy) binomial GLMs, performs likelihood-ratio and Wald tests, extracts level-specific effects, and builds diagnostic plots and a gt summary table. Reads human-readable labels from extdata/model_criteria.xlsx and saves plots (PNG/SVG) and an HTML diagnostics file under extdata/linearity. Returns a list containing the gt summary_table and the combined plot dashboard.
Replace CSV output with a styled gt table saved as HTML. create_criteria_table() now reads model_criteria.xlsx using a package extdata path, renames levels to Level 0–3, constructs a gt table with row groups, styling and spacing, hides helper columns, saves the result to inst/extdata/tables/table_criteria.html (gtsave) and returns the gt object. Removed the previous CSV export and deleted the old table_criteria.csv file.
Rewrite create_model_weights_tables in R/tables.R to support both binary and multinomial model types, process groups programmatically, and produce per-group and combined "across groups" gt tables. Changes include: reading data from extdata/apollo/<binary|multinomial>, improved parsing of coefficient names, calculation and formatting of 95% CIs and p-values, group/row ordering, alternative labeling for multinomial models, conditional cell styling (color swatches, bold for significance), and returning a list of gt tables instead of a single table. Also update output paths to inst/extdata/tables/<binary|multinomial>/ and add generated HTML table assets (model_weights_across_groups.html and other table files) for binary and multinomial outputs. Misc: rename display label 'aggregate' -> 'All participants' and add progress messages.
Refactor compare_models to loop over model types ('binary' and 'multinomial') and comparisons, updating fs::path_package calls to load RDS models per model type. Compute Wald statistics and p-values for each coefficient, print results, and write per-comparison CSVs to inst/extdata/wald/<modeltype> with descriptive column names. Also move existing CSV fixtures into inst/extdata/wald/binary and add new multinomial CSV fixtures.
Implement pooled interaction model workflow and Wald tests to compare coefficients between groups. Adds exported functions fit_pooled_models, fit_pooled_interaction_binary, fit_pooled_interaction_multinomial and wald_interaction which: pool group data, add group dummy, configure Apollo controls/parameters, define probability functions with interaction terms, estimate models, and save outputs. Also add precomputed model artifacts (estimates, iterations, .rds and .txt outputs) under inst/extdata/apollo/pooled for binary and multinomial comparisons (aumc_vs_olvg and intensivists_vs_fellows). Includes examples and basic formatting/annotation of Wald test results (per-coefficient and joint tests).
Refactor create_group_comparison_table to generate tables for both binary and multinomial models. Read wald CSVs from model-specific subfolders, extract coefficient/alternative names with tidyr::extract, join human-readable criteria, and include an "alternative" column for multinomial results. Build and format gt tables with appropriate spanners, annotations, footnotes, and column widths, save separate HTML outputs per model type, and return a list of gt tables (was a single table). Update function documentation accordingly.
Introduce create_pooled_group_comparison_tables function to R/tables.R. The new function generates gt tables comparing subgroup coefficients from pooled Apollo interaction models (binary and multinomial), runs wald_interaction for predefined comparisons (Amsterdam UMC vs. OLVG and Intensivists vs. Fellows), formats rows/spanners/footnotes, handles multinomial alternatives, saves HTML outputs to extdata/tables/<modeltype>/table_pooled_group_comparison.html, and returns a list of the built tables.
Add generated linearity diagnostics assets for ordered covariates under inst/extdata/linearity: an HTML report (linearity_diagnostics.html) summarizing likelihood-ratio and quadratic-term tests, AIC comparisons, and preferred functional forms, plus accompanying plots in PNG and SVG (linearity_plots.png, linearity_plots.svg). These resources support assessment of linear vs non-linear functional forms for covariates (e.g., Age, Frailty, Life expectancy, organ impairments) in model diagnostics.
Introduce plot_pooled_group_comparison() to generate group comparison plots of coefficient weights (Wald test) for binary and multinomial models. The function computes wald_interaction results, reshapes data, builds ggplot2 bar charts with error bars and significance annotations (ggsignif), facets multinomial alternatives, and saves PNG/SVG outputs under the package extdata/figures/<modeltype> directories. Returns a nested list of ggplot objects keyed by model type and group pair.
Add five CSV data files under inst/extdata/feature_importance/maximum_utility_contribution/multinomial: aggregate.csv, aumc.csv, fellows.csv, intensivists.csv, and olvg.csv. Each file contains coefficient-level feature importance for multinomial models (columns: coefficient_name, coef, variable, alternative, max_util_contrib, importance_pct) to support downstream analysis and documentation.
Recompute standardized coefficients for binary datasets (updated sd_y and std_coef) and add new multinomial standardized coefficient CSVs. Modified files: inst/extdata/feature_importance/standardized_coefficients/binary/{aggregate,aumc,fellows,intensivists,olvg}. Added files: inst/extdata/feature_importance/standardized_coefficients/multinomial/{aggregate,aumc,fellows,intensivists,olvg}. These changes update the scaling (sd_y) used to compute std_coef and include full multinomial alternative-specific coefficient tables.
Add subgroup-specific factor importance SVG/PNG assets and reorganize figure files. New assets added under inst/extdata/figures/binary and inst/extdata/figures/multinomial for aggregate, AUMC, fellows, intensivists and OLVG (SVG + PNG). Moved/renamed the aggregate SVG into the binary folder and updated its chart title to "Factor Importance - All Participants". Removed the old top-level factor_importance_aggregate.png. This organizes figure assets by subgroup and updates the aggregate label.
Delete the binary figure at inst/extdata/figures/group_comparison_aumc_olvg.png from the repository
Extract pooled model fitting code into a new file R/pooled.R. The functions fit_pooled_models, fit_pooled_interaction_binary, and fit_pooled_interaction_multinomial were moved out of R/wald.R into their own module.
Replace the previous coefficient conversion assertion with a test that verifies plot_group_comparison() returns two figures (length == 2). This aligns the test with expected plotting behavior and ensures the function produces the correct number of outputs.
Update plot_pooled_group_comparison to save files using the 'pooled_group_comparison_<groups>.<ext>' filename. Rename bundled example figures under inst/extdata/figures/{binary,multinomial} to match the new 'pooled_' prefix (PNG and SVG for aumc_olvg and intensivists_fellows). Keeps saved outputs and example assets consistent for pooled group comparisons.
Add `math-rendering: katex` to the `_pkgdown.yml` template section to enable KaTeX-based rendering of mathematical expressions on the package website. MathML (the default) unfortunately doesn't render complex equations correctly.
Refactor and expand documentation: add several new Rd man pages (pooled models, feature importance variants, linearity tests, wald interaction, etc.), remove obsolete Rd files, and update many existing Rd details and examples.
Update NAMESPACE and required packages to Imports in DESCRIPTION. Refresh renv state.
Enable setup commands in README.md. Add additional usethis::use_package entries and enable devtools/use_devtools. Update workflow examples. Call devtools::install() before building the pkgdown site.
@patrickthoral
patrickthoral merged commit 225c9b9 into main Feb 26, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant