Skip to content

Fix Mean Citedness tab: outcome classification, denominators, caching - #4

Open
LukasWallrich wants to merge 3 commits into
mainfrom
audit/mean-citedness
Open

Fix Mean Citedness tab: outcome classification, denominators, caching#4
LukasWallrich wants to merge 3 commits into
mainfrom
audit/mean-citedness

Conversation

@LukasWallrich

Copy link
Copy Markdown
Contributor

Part of a repo audit. The Mean Citedness tab disagreed with the rest of the dashboard about which studies count as successful/failed:

  • Outcome classification: render_impact_factor.R used exact string equality (== "successful"), silently dropping variant labels ("success", "failure", "successful || success", "statistically successful but flawed", …) that the frontend's classifyOutcome() catches. The R script now uses a faithful port of that JS function, so all tabs agree. Effect on the committed data: n_success 921→970 (+49), n_failed 826→851 (+25).
  • Percentage denominator: success/failure percentages divided by n_total, which includes ~20 unclassifiable rows ("na", "uninformative", "descriptive only"). The R script now emits n_classified and the frontend divides by it.
  • Dead "Inconclusive" category: the token never occurs in the data, so the stat and histogram series were permanently zero; removed from R output and the chart (the classifier still recognizes the label should it ever appear).
  • Tab reload churn: the tab re-fetched the JSON and re-rendered both Plotly charts on every visit; it now caches like the Authorship Overlap tab, and the GAM scatter jitter is computed once per load so points no longer jump on re-renders/theme toggles.
  • run_fect.R (dormant): the t=−1 reference row is now built from an existing emfx row instead of rbinding a 5-column data.frame that errors on column mismatch.

data/impact_factor_data.json was regenerated locally with the fixed script (R + mgcv); CI regenerates weekly. node --check passes on app.js.

🤖 Generated with Claude Code

LukasWallrich and others added 2 commits July 18, 2026 23:50
R (scripts/render_impact_factor.R):
- Port the frontend classifyOutcome() fuzzy logic to an R helper
  classify_outcome() and use it for overview counts, histogram bins,
  and GAM subset/binary coding. Previously the R script used exact
  string equality (outcome == "successful"), dropping label variants
  ("success", "failure", "successful || success", "statistically
  successful but flawed", etc.), so tabs disagreed.
- Emit n_classified (successful/failed/mixed) so percentages divide by
  the classified set, not n_total (which includes ~20
  uninformative/descriptive rows and understated the rates).
- Drop the dead "inconclusive" category (no label maps to it) from the
  overview and histogram output.

Frontend (assets/app.js):
- Divide Mean Citedness percentages by n_classified.
- Remove the always-zero Inconclusive series from the distribution chart.
- Guard loadMeanCitedness with window._mcData so the tab fetches and
  renders once, matching the Authorship Overlap tab.
- Compute GAM scatter jitter once per data load (window._mcJitter) so
  points no longer jump on every re-render.

scripts/run_fect.R:
- Build the t=-1 reference row from an existing emfx row so it carries
  all columns (extras NA-filled), instead of rbinding a 5-column
  data.frame that mismatched and errored under the tryCatch.

Regenerated impact_factor_data.json: successful 921->970, failed
826->851 (mixed unchanged), reflecting the recovered variants.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
The guard checked window._mcData but nothing assigned it, so the tab
still re-fetched on every visit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…light fetch

Cached tab visits now return immediately (charts persist in the DOM;
theme toggles re-render via _rerenderAllCharts). An in-flight flag
prevents duplicate fetches from rapid tab switching, reset in finally
so a failed load can be retried.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@LukasWallrich

Copy link
Copy Markdown
Contributor Author

Codex review (gpt, read-only): REQUEST_CHANGES — the statistics were verified clean; two caching findings, both addressed:

  1. Medium — cached tab visits still re-rendered both Plotly charts (the guard called renderMcCharts instead of returning; theme toggles already re-render via _rerenderAllCharts). ✅ Fixed: cached path now returns immediately.
  2. Low — concurrent tab activations could issue duplicate fetches while the first request was in flight. ✅ Fixed: _mcLoading in-flight flag, reset in finally so a failed load can retry.

Codex verified everything else in detail: the R classifier is a faithful port (including not robust → other, robustness challenge → failed, exact replicated → successful, NA/empty → other); GAM subset and binary coding correct; regenerated counts reconcile (970+851+500 = 2,321 of 2,341; n_model 1,821 = 970+851); the histogram's 12 "missing" classified rows are the intended OMC≥20 axis crop; all JSON field names match the frontend reads; jitter stable across theme re-renders; and the run_fect.R reference-row fix is safe.

(Also fixed during self-review before codex ran: the original guard checked window._mcData but never assigned it.)

@LukasWallrich

Copy link
Copy Markdown
Contributor Author

Codex re-verified the caching fixes: _mcData assigned after parse, cached/in-flight activations return immediately, _mcLoading always cleared in finally so failed loads stay retryable, and theme toggles still re-render via _rerenderAllCharts. FIXES_OK.

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