Skip to content

varPro Phase 3: gg_udependent — dependency graph for uvarpro fits#86

Merged
ehrlinger merged 16 commits into
mainfrom
feat/varpro-phase3-gg-udependent
May 21, 2026
Merged

varPro Phase 3: gg_udependent — dependency graph for uvarpro fits#86
ehrlinger merged 16 commits into
mainfrom
feat/varpro-phase3-gg-udependent

Conversation

@ehrlinger
Copy link
Copy Markdown
Owner

Summary

  • Adds gg_udependent(): tidy extractor wrapping varPro::get.beta.entropy() + varPro::sdependent() on a uvarpro fit. Returns \$edges, \$nodes, \$graph (igraph), and a provenance attribute.
  • Adds plot.gg_udependent(): ggraph network renderer with edge width/opacity by dependency strength, node colour by signal status, configurable layout ("fr", "kk", "stress", etc.).
  • Adds print, summary, autoplot S3 companions (in shared method files per project convention).
  • Moves igraph from Suggests: to Imports: (required by importFrom in NAMESPACE).
  • Adds ggraph to Suggests:.
  • Bumps version to 2.7.3.9004.

Test plan

  • All test_gg_udependent.R tests pass (806 pass, 11 skip — ggraph/vdiffr skips expected)
  • devtools::check(args='--as-cran') returns 0 errors, 0 warnings, 0 notes
  • CI passes on all platforms
  • vdiffr snapshots recorded on platform with ggraph installed

🤖 Generated with Claude Code

ehrlinger and others added 14 commits May 20, 2026 20:12
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Implements gg_udependent() to extract cross-variable dependency graphs
from uvarpro fits via get.beta.entropy/sdependent, with full tidy
edges/nodes/igraph output, provenance attribute, and S3 companions.
25 tests pass (1 skip: ggraph not installed in dev env).

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…igraph usage and degree semantics

- print.gg_udependent, print.summary.gg_udependent → R/print_methods.R
- summary.gg_udependent → R/summary_methods.R
- autoplot.gg_udependent → R/autoplot_methods.R (calls plot() not plot.gg_udependent directly)
- Add @note to gg_udependent roxygen block documenting igraph:: call-site pattern
- Expand @return $nodes description with directed/undirected degree semantics
- Add inline comment near deg_vec computation explaining out-degree vs total-degree choice

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Adds plot.gg_udependent S3 method rendering variable dependency graphs
via ggraph; empty-graph guard fires before ggraph check so it works
without ggraph installed. 26 pass, 3 skip (ggraph not installed), 0 fail.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…le snapshots

- igraph moved from Suggests to Imports (required by importFrom in NAMESPACE)
- plot.gg_udependent example wrapped in requireNamespace("ggraph") guard
- @importFrom igraph added to gg_udependent.R; misleading @note removed
- Stale vdiffr snapshots deleted by devtools::test() cleanup

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Rename single-letter `A` -> `adj_mat` (object_name_linter)
- Remove trailing blank line (trailing_blank_lines_linter)
- Fix undirected igraph mode: 'undirected' -> 'max' (igraph >= 1.6.0
  requires symmetric matrix for mode='undirected'; 'max' symmetrises)
- Move gg_udependent vdiffr tests from test_gg_udependent.R into
  test_snapshots.R under the VDIFFR_RUN_TESTS='true' guard, matching
  the package convention and preventing CI failures on first-run new
  snapshots

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@codecov
Copy link
Copy Markdown

codecov Bot commented May 21, 2026

Codecov Report

❌ Patch coverage is 83.07692% with 33 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.39%. Comparing base (6e64c20) to head (661a388).

Files with missing lines Patch % Lines
R/plot.gg_udependent.R 65.45% 19 Missing ⚠️
R/gg_udependent.R 88.79% 13 Missing ⚠️
R/print_methods.R 91.66% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main      #86      +/-   ##
==========================================
- Coverage   86.62%   86.39%   -0.23%     
==========================================
  Files          36       38       +2     
  Lines        2826     3021     +195     
==========================================
+ Hits         2448     2610     +162     
- Misses        378      411      +33     
Files with missing lines Coverage Δ
R/autoplot_methods.R 85.71% <100.00%> (+1.09%) ⬆️
R/summary_methods.R 92.10% <100.00%> (+0.61%) ⬆️
R/print_methods.R 89.58% <91.66%> (+0.29%) ⬆️
R/gg_udependent.R 88.79% <88.79%> (ø)
R/plot.gg_udependent.R 65.45% <65.45%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

pkgdown fails with 'topics missing from index' when exported functions
are not listed in _pkgdown.yml reference section.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new varPro Phase 3 feature to ggRandomForests for extracting and visualizing cross-variable dependency structure from varPro::uvarpro fits, including an igraph-backed data object, ggraph plotting, S3 companions, documentation, and tests.

Changes:

  • Introduces gg_udependent() to compute a dependency graph ($edges, $nodes, $graph) plus a provenance attribute from a uvarpro fit.
  • Adds plot.gg_udependent() (ggraph renderer) and S3 companions (print, summary, autoplot) + corresponding documentation/NAMESPACE updates.
  • Updates dependencies/tests/metadata (Imports/Suggests, NEWS, pkgdown reference, snapshot tests).

Reviewed changes

Copilot reviewed 13 out of 48 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
tests/testthat/test_snapshots.R Adds vdiffr snapshot cases for gg_udependent (guarded by env var + ggraph).
tests/testthat/test_gg_udependent.R New unit + smoke tests for gg_udependent structure, provenance, S3 methods, and plotting behavior.
tests/testthat/_snaps/snapshots/gg-vimp-survival-rfsrc.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-vimp-regression-rfsrc.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-vimp-regression-rf.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-vimp-classification-rfsrc.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-vimp-classification-rf.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-varpro-default.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-varpro-conditional.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-roc-classification-rfsrc.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-roc-classification-rf.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-rfsrc-regression-rf.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-partial-varpro-mortality.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-partial-varpro-continuous.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-partial-varpro-categorical.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-error-survival-rfsrc.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-error-regression-rfsrc.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-error-regression-rf.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-error-classification-rfsrc.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-brier-survival-overall.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-brier-survival-envelope.svg Removes an existing vdiffr baseline snapshot (SVG).
tests/testthat/_snaps/snapshots/gg-brier-survival-crps.svg Removes an existing vdiffr baseline snapshot (SVG).
R/summary_methods.R Adds summary.gg_udependent() implementation.
R/print_methods.R Adds print.gg_udependent() and print.summary.gg_udependent().
R/plot.gg_udependent.R New ggraph-based plot method for gg_udependent.
R/gg_udependent.R New extractor computing dependency adjacency, edges/nodes, and igraph object.
R/autoplot_methods.R Adds autoplot.gg_udependent() delegating to plot().
NEWS.md Documents the new gg_udependent() feature and dependency update.
NAMESPACE Registers S3 methods and imports required functions (igraph, varPro, ggplot2).
man/summary.gg.Rd Adds alias/usage entry for summary.gg_udependent.
man/print.gg.Rd Adds aliases/usages for print.gg_udependent and print.summary.gg_udependent.
man/plot.gg_udependent.Rd New Rd page for plot.gg_udependent.
man/gg_udependent.Rd New Rd page for gg_udependent.
man/autoplot.gg.Rd Adds alias/usage for autoplot.gg_udependent.
dev/plans/2026-05-20-varpro-phase3-gg-udependent-design.md Adds design document for Phase 3 implementation.
DESCRIPTION Bumps version, moves igraph to Imports, adds ggraph to Suggests.
_pkgdown.yml Adds gg_udependent and plot.gg_udependent to reference index.
Files not reviewed (5)
  • man/autoplot.gg.Rd: Language not supported
  • man/gg_udependent.Rd: Language not supported
  • man/plot.gg_udependent.Rd: Language not supported
  • man/print.gg.Rd: Language not supported
  • man/summary.gg.Rd: Language not supported
Comments suppressed due to low confidence (1)

R/gg_udependent.R:116

  • Edge weights are currently assigned as imp_mat[i, j] using the (from, to) ordering returned by igraph. For directed = FALSE, this can produce weights that are below the threshold (or otherwise inconsistent) when the undirected edge exists due to the reverse direction. For undirected graphs, compute the edge weight from both directions (e.g., max/mean of I[i,j] and I[j,i]) so the reported/visualised strength matches the edge selection logic.
  ## ---- Build tidy edge data frame with raw weights -------------------------
  edge_df <- igraph::as_data_frame(g, what = "edges")
  if (nrow(edge_df) > 0L) {
    edge_df$weight <- mapply(
      function(i, j) imp_mat[i, j],
      edge_df[[1L]], edge_df[[2L]]
    )

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread R/gg_udependent.R
Comment thread R/summary_methods.R Outdated
Comment thread R/print_methods.R Outdated
Comment thread R/plot.gg_udependent.R Outdated
Comment thread tests/testthat/test_snapshots.R
… guard, snapshots

Undirected adjacency/weights (R/gg_udependent.R):
- Symmetrise adj_mat with pmax(adj_mat, t(adj_mat)) for directed=FALSE
  so edge existence matches max(I[i,j], I[j,i]) before igraph build;
  mode can now be "undirected" (no longer requires "max" workaround)
- Use max(I[i,j], I[j,i]) as edge weight for undirected graphs
- Set igraph::E(g)$weight in the extractor (order-insensitive key for
  undirected) so the plot method never needs to recompute them

Plot weight backfill (R/plot.gg_udependent.R):
- Make legacy backfill order-insensitive for undirected graphs via
  pmin/pmax key matching (guards objects saved before weight was stored)

summary API (R/summary_methods.R):
- Rewrite summary.gg_udependent() to use .summary_skel() returning
  c("summary.gg_udependent","summary.gg"), consistent with all other
  summary.gg_*() methods; body carries edges/nodes/threshold lines

print guard (R/print_methods.R):
- Add NULL-safe provenance fallback in print.gg_udependent()
- Replace print.summary.gg_udependent() body with NextMethod() to
  delegate to print.summary.gg() which renders the skel format

Snapshots (tests/testthat/_snaps/):
- Restore 30 SVG baselines from origin/main that were absent from the
  branch and appeared as deletions in the PR diff

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ehrlinger ehrlinger merged commit 4c64eed into main May 21, 2026
15 checks 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.

2 participants