cd_compare(): defaults + window-vs-window p-value (#20, #43)#73
Merged
Conversation
Stale Rd regenerations from earlier .R-file edits. No source change — just devtools::document() catching up so subsequent runs don't surface noise. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Wire the de-facto framing both regional vignettes have settled on
into the function signature so first-time users get a sensible
answer without supplying both windows. Roxygen documents the why —
cumulative-impact comparison ('how much warmer is the recent
decade') vs rate-of-change (cd_trend's job), with 1951–1980 as
the WMO-style standard normal reference.
Toy example_catalog only spans 1951:1960 so the in-Rd examples
keep explicit windows; a comment in the example block points users
at the live-catalog defaults.
Fixes #20
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
New `test` argument (default "t") emits a p_value column on the output. `test = "t"` runs Welch's two-sample t-test on the annual values in each window; `test = "wilcox"` runs Mann-Whitney U; `test = NULL` skips the test entirely and drops the column. Rows where either window has < 8 non-NA years get `p_value = NA` and a single batched warning naming the affected variable/period rows (no per-row warning spam). The window-vs-window p-value answers a different question than the cd_trend Mann-Kendall test: "do the two windows differ" vs "is there a monotonic trend across the full series." Step changes and U-shapes can produce significant window differences without monotonic trends, and vice versa. Vignettes will report both p-values side-by-side in Phase 3. Roxygen documents the independence assumption; for series with strong autocorrelation the t-test is mildly anti-conservative — the Wilcoxon alternative is more robust to non-Gaussian tails but shares the independence assumption. Fixes #43 Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ettes Both vignettes: - Compare-recipe chunk now shows bare `cd::cd_compare(ts)` — defaults (2015:2025 vs 1951:1980, Welch t) carry the call. Cleaner cd showcase; reader sees the recipe in 1 line. - Compare-table chunk recomputes `cmp` from cached `ts` so the new `p_value` column flows through without re-running the heavy precompute scripts. The cached `regional` predates #43 so doesn't have the column. - Table swaps the synthesized Mann-Kendall `trend_p` proxy for the real window-vs-window `Δ p (windows)` (Welch). `Trend p (75-yr)` stays alongside — different question, both belong. - One-paragraph narrative reframes the two p-values: "do the windows differ?" (window p) vs "is there a monotonic ramp?" (trend p). Step changes vs gradual ramps read differently. `data-raw/<vignette>_vignette_data.R` updated so the next precompute run uses cd_compare defaults. Both vignettes render clean locally with both column headers present in the rendered HTML. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Repo pattern: NEWS + DESCRIPTION bump lands as a separate 'Release v0.X.Y' commit on main post-merge, driven by /gh-pr-merge. The branch itself stays release-prep clean. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The cumulative-impact comparison (mean(2015-2025) - mean(1951-1980))
is the headline number this package produces — it was buried 300+
lines down between Snowpack and Spatial Pattern, and titled with
methodological framing ('Recent vs Pre-warming') rather than
something that telegraphs the answer.
Two changes in both vignettes:
- Rename: 'Recent vs Pre-warming' -> 'Recent Decade vs Pre-Warming
Reference'. Adds 'decade' + 'reference' so the heading reads as
a comparison label rather than a methods stub.
- Reorder: place directly after Trends, before Daytime Highs and
Overnight Lows. Trends still introduces the 1951-1980 reference
and the two-test framing the table relies on, then the headline
cumulative number lands; DTR / Snowpack / Spatial Pattern read
as drill-down on the headline rather than a long detour before it.
Both vignettes render clean; new heading visible in HTML, old
heading absent.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two tightly coupled
cd_compare()improvements landed togetheron one branch (issue #20 explicitly says "Tightly coupled with
#43; both should land together"):
window_a = 2015:2025,window_b = 1951:1980— the framing both regional vignettes had settled on (recent
decade vs WMO-style standard normal). First-time users get a
sensible answer with
cd::cd_compare(ts).test = "t"argument runs Welch two-samplet-test on the annual values within each window and emits a
p_valuecolumn.test = "wilcox"runs Mann-Whitney U;test = NULLskips the test and drops the column. Rows whereeither window has < 8 non-NA years get
p_value = NAand asingle batched warning naming affected variable/period rows.
Independence-between-years assumption documented in roxygen.
Default is
test = "t"so output gains the column by default —hence minor bump (
0.2.8→0.3.0) at merge.Why two p-values
The Mann-Kendall p-value from
cd_trend()was being spliced intothe vignette comparison table as a proxy for "is this window
shift real?" — but the MK test answers a different question
("monotonic trend across the full series?"). Step changes /
U-shapes can produce significant Δ p (windows) with non-significant
trend p, and vice versa. Both vignettes now show both p-values
side-by-side: Δ p (windows) + Trend p (75-yr). The
narrative reframes the two-test framing in one paragraph.
Vignette wiring
cd::cd_compare(ts)—defaults carry the call. Cleaner cd showcase.
cmpfrom the cachedtssothe new
p_valuecolumn flows through without re-running theheavy precompute scripts (the cached
regional$cmppredatesthis PR).
data-raw/<vignette>_vignette_data.Rupdated for next refresh.Test plan
devtools::test()→ 181 PASS / 0 FAIL (12 cd_compare testsincluding step-change → tiny p, iid noise → large p,
wilcox,NULL→ original 6-col schema, < 8-year guardfires once with warning, multi-variable per-row p-values)
lintr::lint_package()clean (no new lints fromcd_compare; pre-existing
.datapronoun + vignette captionlength unchanged)
Δ p (windows)andTrend p (75-yr)column headersFixes #20
Fixes #43
Relates to NewGraphEnvironment/sred-2025-2026#23
🤖 Generated with Claude Code