terraproof 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -2
  3. package/bin/terraproof.js +4 -0
  4. package/dist/router/apply.js +147 -0
  5. package/dist/router/classify.js +111 -0
  6. package/dist/router/explain.js +9 -0
  7. package/dist/router/index.js +272 -0
  8. package/dist/router/resolve.js +239 -0
  9. package/dist/router/score.js +60 -0
  10. package/dist/router/types.js +1 -0
  11. package/dist/router/validate.js +81 -0
  12. package/instructions/engineering.md +14 -0
  13. package/instructions/security.md +14 -0
  14. package/instructions/simplicity.md +13 -0
  15. package/package.json +65 -4
  16. package/routing/DOMAIN_ROUTING.md +161 -0
  17. package/routing/ROUTER_DESIGN.md +173 -0
  18. package/routing/SKILL_MANIFEST.md +86 -0
  19. package/routing/checks.json +121 -0
  20. package/routing/collections.json +47 -0
  21. package/routing/registry.json +2211 -0
  22. package/routing/rules.json +64 -0
  23. package/skills/accuracy-assessment/SKILL.md +213 -0
  24. package/skills/accuracy-assessment/UPSTREAM.md +7 -0
  25. package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
  26. package/skills/accuracy-assessment/skill.json +103 -0
  27. package/skills/brainstorming/SKILL.md +250 -0
  28. package/skills/brainstorming/UPSTREAM.md +29 -0
  29. package/skills/brainstorming/scripts/frame-template.html +213 -0
  30. package/skills/brainstorming/scripts/helper.js +167 -0
  31. package/skills/brainstorming/scripts/server.cjs +723 -0
  32. package/skills/brainstorming/scripts/start-server.sh +209 -0
  33. package/skills/brainstorming/scripts/stop-server.sh +120 -0
  34. package/skills/brainstorming/skill.json +73 -0
  35. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  36. package/skills/brainstorming/visual-companion.md +299 -0
  37. package/skills/crs-and-units/SKILL.md +200 -0
  38. package/skills/crs-and-units/UPSTREAM.md +7 -0
  39. package/skills/crs-and-units/skill.json +74 -0
  40. package/skills/design-postgis-tables/SKILL.md +494 -0
  41. package/skills/design-postgis-tables/UPSTREAM.md +21 -0
  42. package/skills/design-postgis-tables/skill.json +90 -0
  43. package/skills/gdal/SKILL.md +125 -0
  44. package/skills/gdal/UPSTREAM.md +22 -0
  45. package/skills/gdal/references/gdal-recipes.md +103 -0
  46. package/skills/gdal/skill.json +66 -0
  47. package/skills/geomaster/README.md +105 -0
  48. package/skills/geomaster/SKILL.md +366 -0
  49. package/skills/geomaster/UPSTREAM.md +21 -0
  50. package/skills/geomaster/references/advanced-gis.md +376 -0
  51. package/skills/geomaster/references/big-data.md +363 -0
  52. package/skills/geomaster/references/code-examples.md +531 -0
  53. package/skills/geomaster/references/coordinate-systems.md +364 -0
  54. package/skills/geomaster/references/core-libraries.md +273 -0
  55. package/skills/geomaster/references/data-sources.md +330 -0
  56. package/skills/geomaster/references/gis-software.md +369 -0
  57. package/skills/geomaster/references/industry-applications.md +420 -0
  58. package/skills/geomaster/references/machine-learning.md +462 -0
  59. package/skills/geomaster/references/programming-languages.md +456 -0
  60. package/skills/geomaster/references/remote-sensing.md +370 -0
  61. package/skills/geomaster/references/scientific-domains.md +416 -0
  62. package/skills/geomaster/references/specialized-topics.md +428 -0
  63. package/skills/geomaster/references/troubleshooting.md +439 -0
  64. package/skills/geomaster/skill.json +157 -0
  65. package/skills/geopandas/SKILL.md +250 -0
  66. package/skills/geopandas/UPSTREAM.md +22 -0
  67. package/skills/geopandas/references/crs-management.md +231 -0
  68. package/skills/geopandas/references/data-io.md +323 -0
  69. package/skills/geopandas/references/data-structures.md +207 -0
  70. package/skills/geopandas/references/geometric-operations.md +262 -0
  71. package/skills/geopandas/references/spatial-analysis.md +294 -0
  72. package/skills/geopandas/references/visualization.md +230 -0
  73. package/skills/geopandas/scripts/_common.py +605 -0
  74. package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
  75. package/skills/geopandas/scripts/export_plan.py +305 -0
  76. package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
  77. package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
  78. package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
  79. package/skills/geopandas/scripts/vector_inventory.py +140 -0
  80. package/skills/geopandas/skill.json +116 -0
  81. package/skills/geoparquet-validation/SKILL.md +125 -0
  82. package/skills/geoparquet-validation/UPSTREAM.md +24 -0
  83. package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
  84. package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
  85. package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
  86. package/skills/geoparquet-validation/skill.json +71 -0
  87. package/skills/geospatial-data-discovery/SKILL.md +49 -0
  88. package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
  89. package/skills/geospatial-data-discovery/skill.json +51 -0
  90. package/skills/geospatial-frontend/SKILL.md +86 -0
  91. package/skills/geospatial-frontend/UPSTREAM.md +23 -0
  92. package/skills/geospatial-frontend/references/design-system.md +283 -0
  93. package/skills/geospatial-frontend/references/user-preferences.md +96 -0
  94. package/skills/geospatial-frontend/skill.json +87 -0
  95. package/skills/geozarr/SKILL.md +244 -0
  96. package/skills/geozarr/UPSTREAM.md +21 -0
  97. package/skills/geozarr/skill.json +97 -0
  98. package/skills/networkx/SKILL.md +440 -0
  99. package/skills/networkx/UPSTREAM.md +22 -0
  100. package/skills/networkx/references/algorithms.md +384 -0
  101. package/skills/networkx/references/generators.md +385 -0
  102. package/skills/networkx/references/graph-basics.md +284 -0
  103. package/skills/networkx/references/io.md +457 -0
  104. package/skills/networkx/references/visualization.md +531 -0
  105. package/skills/networkx/skill.json +93 -0
  106. package/skills/raster-processing/SKILL.md +222 -0
  107. package/skills/raster-processing/UPSTREAM.md +7 -0
  108. package/skills/raster-processing/skill.json +81 -0
  109. package/skills/sar-basics/SKILL.md +202 -0
  110. package/skills/sar-basics/UPSTREAM.md +7 -0
  111. package/skills/sar-basics/references/calibration-lut.md +98 -0
  112. package/skills/sar-basics/skill.json +97 -0
  113. package/skills/satellite-preprocessing/SKILL.md +241 -0
  114. package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
  115. package/skills/satellite-preprocessing/skill.json +84 -0
  116. package/skills/scientific-visualization/SKILL.md +285 -0
  117. package/skills/scientific-visualization/UPSTREAM.md +25 -0
  118. package/skills/scientific-visualization/assets/color_palettes.py +263 -0
  119. package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
  120. package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
  121. package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
  122. package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
  123. package/skills/scientific-visualization/references/color_palettes.md +227 -0
  124. package/skills/scientific-visualization/references/journal_requirements.md +169 -0
  125. package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
  126. package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
  127. package/skills/scientific-visualization/references/sources.md +76 -0
  128. package/skills/scientific-visualization/scripts/_common.py +136 -0
  129. package/skills/scientific-visualization/scripts/export_plan.py +493 -0
  130. package/skills/scientific-visualization/scripts/figure_export.py +642 -0
  131. package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
  132. package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
  133. package/skills/scientific-visualization/scripts/style_presets.py +501 -0
  134. package/skills/scientific-visualization/scripts/style_preview.py +232 -0
  135. package/skills/scientific-visualization/skill.json +95 -0
  136. package/skills/spectral-indices/SKILL.md +235 -0
  137. package/skills/spectral-indices/UPSTREAM.md +7 -0
  138. package/skills/spectral-indices/skill.json +88 -0
  139. package/skills/stac-and-cloud-access/SKILL.md +209 -0
  140. package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
  141. package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
  142. package/skills/stac-and-cloud-access/skill.json +98 -0
  143. package/skills/statistical-analysis/SKILL.md +446 -0
  144. package/skills/statistical-analysis/UPSTREAM.md +24 -0
  145. package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
  146. package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
  147. package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
  148. package/skills/statistical-analysis/references/reporting_standards.md +482 -0
  149. package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
  150. package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
  151. package/skills/statistical-analysis/skill.json +127 -0
  152. package/skills/systematic-debugging/SKILL.md +283 -0
  153. package/skills/systematic-debugging/UPSTREAM.md +28 -0
  154. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  155. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  156. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  157. package/skills/systematic-debugging/find-polluter.sh +72 -0
  158. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  159. package/skills/systematic-debugging/skill.json +88 -0
  160. package/skills/time-series-and-change/SKILL.md +217 -0
  161. package/skills/time-series-and-change/UPSTREAM.md +7 -0
  162. package/skills/time-series-and-change/references/change-methods.md +42 -0
  163. package/skills/time-series-and-change/skill.json +116 -0
  164. package/skills/vector-quality/SKILL.md +204 -0
  165. package/skills/vector-quality/UPSTREAM.md +7 -0
  166. package/skills/vector-quality/skill.json +82 -0
  167. package/skills/verification/SKILL.md +120 -0
  168. package/skills/verification/UPSTREAM.md +31 -0
  169. package/skills/verification/skill.json +67 -0
  170. package/skills/writing-plans/SKILL.md +171 -0
  171. package/skills/writing-plans/UPSTREAM.md +23 -0
  172. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  173. package/skills/writing-plans/skill.json +80 -0
  174. package/sources/SOURCES.md +374 -0
  175. package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
  176. package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
  177. package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
  178. package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
  179. package/third_party/superpowers/LICENSE +21 -0
  180. package/third_party/superpowers/NOTICE.md +17 -0
  181. package/third_party/timescale-pg-aiguide/LICENSE +176 -0
  182. package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
@@ -0,0 +1,446 @@
1
+ ---
2
+ name: statistical-analysis
3
+ description: Guided statistical analysis for research data - test selection, assumption checking, effect sizes, power analysis, Bayesian alternatives, and APA-formatted reporting. Use whenever a user wants to compare groups, test a hypothesis, analyze experimental or survey data, check statistical assumptions, compute required sample sizes, or write up results - even if they never name a specific test. Covers t-tests, ANOVA, chi-square, correlation, regression, non-parametric and Bayesian methods. For low-level model APIs, see the statsmodels and pymc skills.
4
+ license: MIT license
5
+ metadata:
6
+ version: "1.1"
7
+ skill-author: K-Dense Inc.
8
+ ---
9
+
10
+ # Statistical Analysis
11
+
12
+ ## Overview
13
+
14
+ Conduct hypothesis tests (t-tests, ANOVA, chi-square), regression, correlation, and Bayesian analyses with systematic assumption checking, effect sizes, and APA-style reporting. The goal is an analysis a reviewer could not tear apart: the right test, verified assumptions, honest effect sizes, and a complete write-up.
15
+
16
+ ## When to Use This Skill
17
+
18
+ Use this skill when:
19
+ - Conducting statistical hypothesis tests (t-tests, ANOVA, chi-square, non-parametric)
20
+ - Performing regression or correlation analyses
21
+ - Running Bayesian statistical analyses
22
+ - Checking statistical assumptions and diagnostics
23
+ - Calculating effect sizes and conducting power analyses
24
+ - Reporting statistical results in APA format
25
+ - Analyzing experimental or observational data for research
26
+
27
+ ---
28
+
29
+ ## Installation
30
+
31
+ Use **uv** to install the libraries used in this skill. Pin versions in production; unpinned installs are fine for exploration.
32
+
33
+ ```bash
34
+ # Core frequentist stack (Python 3.10+; 3.12+ recommended for latest SciPy/ArviZ)
35
+ uv pip install "pingouin>=0.6" "scipy>=1.11" "statsmodels>=0.14.6" pandas matplotlib seaborn
36
+
37
+ # Bayesian modeling (PyMC 5 + ArviZ)
38
+ uv pip install "pymc>=5.0" "arviz>=1.0"
39
+ ```
40
+
41
+ **Compatibility notes (verified against pingouin 0.6.1, statsmodels 0.14.6, arviz 1.2, 2026):**
42
+
43
+ - **Pingouin 0.6.0** renamed output columns to remove special characters: `p_val`, `cohen_d`, `CI95`, `p_unc` (previously `p-val`, `cohen-d`, `CI95%`, `p-unc` in 0.5.x). Examples below use the current names; if stuck on 0.5.x, use the hyphenated forms.
44
+ - **statsmodels + SciPy**: use `statsmodels>=0.14.6` with `scipy>=1.11` to avoid `_lazywhere` import errors on SciPy 1.16+.
45
+ - **ArviZ 1.x**: `az.summary()` now defaults to **89% intervals** (`eti89` columns) and the width parameter is `ci_prob` (not `hdi_prob`). To report a conventional 95% credible interval, pass `az.summary(trace, ci_prob=0.95)`.
46
+ - **One-sided Bayes Factors are gone from Pingouin**: `pg.ttest(..., alternative='greater')` silently drops the `BF10` column, and `pg.bayesfactor_ttest` raises on one-sided alternatives. For one-sided Bayesian tests, use PyMC directly (compute the posterior probability of the directional hypothesis) or JASP/R's BayesFactor.
47
+
48
+ For model-specific APIs (OLS, GLM, ARIMA), see the **statsmodels** skill. For PyMC workflows, see the **pymc** skill.
49
+
50
+ ---
51
+
52
+ ## Analysis Workflow
53
+
54
+ Every sound analysis follows the same arc. Skipping steps is how analyses end up retracted, so work through them in order and say what you did at each one.
55
+
56
+ 1. **Frame the question before touching the data.** State the hypothesis, the outcome and predictor variables, and the design (independent vs. paired, number of groups). Commit to a planned test now — choosing the test after peeking at results is p-hacking, even when done innocently.
57
+ 2. **Inspect the data.** Per group: n, mean, SD, median, missing values. Plot the raw data (histograms or box plots) before any test. Unequal group sizes, missingness, floor/ceiling effects, and outliers all change what test is appropriate — surface them to the user rather than silently working around them.
58
+ 3. **Select the test** using the quick reference below, or `references/test_selection_guide.md` for designs beyond the basics (counts, time-to-event, reliability, factorial).
59
+ 4. **Check assumptions** with `scripts/assumption_checks.py`. If an assumption fails, switch to the remedial test (table below) and report both the plan and the change.
60
+ 5. **Run the test** and always compute the effect size alongside it — a p-value says an effect exists; the effect size says whether anyone should care.
61
+ 6. **Report** using the APA templates below, including descriptives, exact statistics, effect sizes with CIs, and the assumption checks performed.
62
+
63
+ If the user only needs one step (e.g., "how many participants do I need?"), jump straight to that section — but still confirm the design assumptions the calculation rests on.
64
+
65
+ ---
66
+
67
+ ## Test Selection Guide
68
+
69
+ ### Quick Reference: Choosing the Right Test
70
+
71
+ Use `references/test_selection_guide.md` for comprehensive guidance (counts, survival, reliability, factorial designs). Quick reference:
72
+
73
+ **Comparing Two Groups:**
74
+ - Independent, continuous, normal → Independent t-test
75
+ - Independent, continuous, non-normal → Mann-Whitney U test
76
+ - Paired, continuous, normal → Paired t-test
77
+ - Paired, continuous, non-normal → Wilcoxon signed-rank test
78
+ - Binary outcome → Chi-square or Fisher's exact test
79
+
80
+ **Comparing 3+ Groups:**
81
+ - Independent, continuous, normal → One-way ANOVA
82
+ - Independent, continuous, non-normal → Kruskal-Wallis test
83
+ - Paired, continuous, normal → Repeated measures ANOVA
84
+ - Paired, continuous, non-normal → Friedman test
85
+
86
+ **Relationships:**
87
+ - Two continuous variables → Pearson (normal) or Spearman correlation (non-normal)
88
+ - Continuous outcome with predictor(s) → Linear regression
89
+ - Binary outcome with predictor(s) → Logistic regression
90
+
91
+ **Bayesian Alternatives:**
92
+ All tests have Bayesian versions providing direct probability statements about hypotheses, Bayes Factors quantifying evidence, and the ability to support the null. See `references/bayesian_statistics.md`.
93
+
94
+ ---
95
+
96
+ ## Assumption Checking
97
+
98
+ **Always check assumptions before interpreting test results**, and report the checks — reviewers look for them.
99
+
100
+ Use the bundled `scripts/assumption_checks.py` module. Run Python from the skill directory (`skills/statistical-analysis/`) or add `scripts/` to `sys.path`:
101
+
102
+ ```python
103
+ from assumption_checks import comprehensive_assumption_check
104
+
105
+ # Outliers + normality (per group) + homogeneity of variance, with plots
106
+ results = comprehensive_assumption_check(
107
+ data=df,
108
+ value_col='score',
109
+ group_col='group', # Optional: for group comparisons
110
+ alpha=0.05
111
+ )
112
+ ```
113
+
114
+ For targeted checks, import individual functions:
115
+
116
+ ```python
117
+ from assumption_checks import (
118
+ check_normality, # Shapiro-Wilk + Q-Q plot + histogram
119
+ check_normality_per_group,
120
+ check_homogeneity_of_variance, # Levene's test + box plots
121
+ check_linearity, # scatter + residual plot for simple regression
122
+ check_regression_diagnostics, # full OLS diagnostics (see Regression below)
123
+ detect_outliers # IQR or z-score methods
124
+ )
125
+
126
+ result = check_normality(data=df['score'], name='Test Score', alpha=0.05, plot=True)
127
+ print(result['interpretation'])
128
+ print(result['recommendation'])
129
+ ```
130
+
131
+ ### What to Do When Assumptions Are Violated
132
+
133
+ **Normality violated:**
134
+ - Mild violation + n > 30 per group → Proceed with parametric test (robust)
135
+ - Moderate violation → Use non-parametric alternative
136
+ - Severe violation → Transform data or use non-parametric test
137
+
138
+ **Homogeneity of variance violated:**
139
+ - For t-test → Use Welch's t-test (`pg.ttest` applies it automatically with `correction='auto'`)
140
+ - For ANOVA → Use Welch's ANOVA (`pg.welch_anova`) or Brown-Forsythe
141
+ - For regression → Use robust standard errors or weighted least squares
142
+
143
+ **Linearity violated (regression):**
144
+ - Add polynomial terms, transform variables, or use non-linear models / GAM
145
+
146
+ Formal tests get oversensitive as n grows: for n ≥ 100, weigh the Q-Q plot more heavily than the Shapiro-Wilk p-value. See `references/assumptions_and_diagnostics.md` for comprehensive guidance.
147
+
148
+ ---
149
+
150
+ ## Running Statistical Tests
151
+
152
+ Primary libraries:
153
+ - **pingouin**: user-friendly tests that return effect sizes by default — prefer it for standard tests
154
+ - **scipy.stats**: core statistical tests
155
+ - **statsmodels**: regression, diagnostics, power analysis
156
+ - **pymc** + **arviz**: Bayesian modeling and diagnostics
157
+
158
+ ### T-Test with Complete Reporting
159
+
160
+ ```python
161
+ import pingouin as pg
162
+
163
+ # correction='auto' applies Welch's correction when variances are unequal
164
+ result = pg.ttest(group_a, group_b, correction='auto')
165
+
166
+ # Pingouin >= 0.6 column names
167
+ t_stat = result['T'].values[0]
168
+ df = result['dof'].values[0]
169
+ p_value = result['p_val'].values[0]
170
+ cohens_d = result['cohen_d'].values[0]
171
+ ci_lower, ci_upper = result['CI95'].values[0] # CI for the mean difference
172
+
173
+ print(f"t({df:.0f}) = {t_stat:.2f}, p = {p_value:.3f}, d = {cohens_d:.2f}")
174
+ ```
175
+
176
+ ### ANOVA with Post-Hoc Tests
177
+
178
+ ```python
179
+ import pingouin as pg
180
+
181
+ aov = pg.anova(dv='score', between='group', data=df, detailed=True)
182
+ print(aov)
183
+
184
+ # Effect size: partial eta-squared
185
+ eta_p2 = aov['np2'].values[0]
186
+
187
+ # If significant, conduct post-hoc tests (Tukey HSD controls family-wise error)
188
+ if aov['p_unc'].values[0] < 0.05:
189
+ posthoc = pg.pairwise_tukey(dv='score', between='group', data=df)
190
+ print(posthoc) # includes Hedges' g per pair
191
+ ```
192
+
193
+ ### Linear Regression with Diagnostics
194
+
195
+ ```python
196
+ import statsmodels.api as sm
197
+ from assumption_checks import check_regression_diagnostics
198
+
199
+ X = sm.add_constant(X_predictors) # Add intercept
200
+ model = sm.OLS(y, X).fit()
201
+ print(model.summary())
202
+
203
+ # 4-panel residual plot + Shapiro-Wilk, Breusch-Pagan, Durbin-Watson, VIF
204
+ diag = check_regression_diagnostics(model)
205
+ print(diag['interpretation'])
206
+ print(diag['vif'])
207
+
208
+ # If heteroscedasticity was flagged, report robust standard errors instead
209
+ robust = model.get_robustcov_results('HC3')
210
+ ```
211
+
212
+ ### Bayesian T-Test
213
+
214
+ ```python
215
+ import pymc as pm
216
+ import arviz as az
217
+ import numpy as np
218
+
219
+ with pm.Model() as model:
220
+ # Priors
221
+ mu1 = pm.Normal('mu_group1', mu=0, sigma=10)
222
+ mu2 = pm.Normal('mu_group2', mu=0, sigma=10)
223
+ sigma = pm.HalfNormal('sigma', sigma=10)
224
+
225
+ # Likelihood
226
+ y1 = pm.Normal('y1', mu=mu1, sigma=sigma, observed=group_a)
227
+ y2 = pm.Normal('y2', mu=mu2, sigma=sigma, observed=group_b)
228
+
229
+ # Derived quantity
230
+ diff = pm.Deterministic('difference', mu1 - mu2)
231
+
232
+ trace = pm.sample(2000, tune=1000)
233
+
234
+ # ArviZ 1.x defaults to 89% intervals; request 95% explicitly for reporting
235
+ print(az.summary(trace, var_names=['difference'], ci_prob=0.95))
236
+
237
+ # Direct probability statement (this is what one-sided questions become)
238
+ prob_greater = np.mean(trace.posterior['difference'].values > 0)
239
+ print(f"P(mu1 > mu2 | data) = {prob_greater:.3f}")
240
+
241
+ # ArviZ 1.x removed az.plot_posterior; use plot_dist (on 0.x, plot_posterior still works)
242
+ az.plot_dist(trace, var_names=['difference'], ci_prob=0.95)
243
+ ```
244
+
245
+ Scale priors to the data (e.g., `sigma=10` suits outcomes with SD near 10; use the observed SD as a guide) and state the priors in the report.
246
+
247
+ ---
248
+
249
+ ## Effect Sizes
250
+
251
+ **Effect sizes quantify magnitude; p-values only indicate existence.** Report one for every test. See `references/effect_sizes_and_power.md` for the full guide.
252
+
253
+ ### Quick Reference: Common Effect Sizes
254
+
255
+ | Test | Effect Size | Small | Medium | Large |
256
+ |------|-------------|-------|--------|-------|
257
+ | T-test | Cohen's d | 0.20 | 0.50 | 0.80 |
258
+ | ANOVA | η²_p | 0.01 | 0.06 | 0.14 |
259
+ | Correlation | r | 0.10 | 0.30 | 0.50 |
260
+ | Regression | R² | 0.02 | 0.13 | 0.26 |
261
+ | Chi-square | Cramér's V | 0.07 | 0.21 | 0.35 |
262
+
263
+ Benchmarks are conventions, not laws — a "small" effect can matter enormously (drug side effects) and a "large" one can be trivial. Interpret in context.
264
+
265
+ ### Calculating Effect Sizes
266
+
267
+ Pingouin returns effect sizes with its tests (`cohen_d` from `pg.ttest`, `np2` from `pg.anova`, `hedges` from `pg.pairwise_tukey`; `r` from `pg.corr` is already an effect size).
268
+
269
+ ### Confidence Intervals for Effect Sizes
270
+
271
+ Report a CI for the effect size to show its precision. Use `pg.compute_esci` (note: `pg.compute_effsize_from_t` returns only the point estimate — it does **not** return a CI):
272
+
273
+ ```python
274
+ import pingouin as pg
275
+
276
+ d = pg.compute_effsize(group_a, group_b, eftype='cohen')
277
+ ci_lower, ci_upper = pg.compute_esci(stat=d, nx=len(group_a), ny=len(group_b),
278
+ eftype='cohen', confidence=0.95)
279
+ print(f"d = {d:.2f}, 95% CI [{ci_lower:.2f}, {ci_upper:.2f}]")
280
+ ```
281
+
282
+ ---
283
+
284
+ ## Power Analysis
285
+
286
+ ### A Priori Power Analysis (Study Planning)
287
+
288
+ Determine required sample size before data collection:
289
+
290
+ ```python
291
+ from statsmodels.stats.power import tt_ind_solve_power, FTestAnovaPower
292
+
293
+ # T-test: What n per group is needed to detect d = 0.5?
294
+ n_required = tt_ind_solve_power(
295
+ effect_size=0.5,
296
+ alpha=0.05,
297
+ power=0.80,
298
+ ratio=1.0,
299
+ alternative='two-sided'
300
+ )
301
+ print(f"Required n per group: {n_required:.0f}")
302
+
303
+ # One-way ANOVA: What n is needed to detect Cohen's f = 0.25?
304
+ # Notes: the parameter is k_groups; effect_size is Cohen's f (f = sqrt(eta2/(1-eta2)));
305
+ # and solve_power returns the TOTAL sample size, not n per group.
306
+ import math
307
+ anova_power = FTestAnovaPower()
308
+ n_total = anova_power.solve_power(
309
+ effect_size=0.25,
310
+ k_groups=3,
311
+ alpha=0.05,
312
+ power=0.80
313
+ )
314
+ print(f"Required total N: {math.ceil(n_total)} ({math.ceil(n_total / 3)} per group)")
315
+ ```
316
+
317
+ ### Sensitivity Analysis (Post-Study)
318
+
319
+ Determine what effect size the study could detect:
320
+
321
+ ```python
322
+ # With n=50 per group, what effect could we detect at 80% power?
323
+ detectable_d = tt_ind_solve_power(
324
+ effect_size=None, # Solve for this
325
+ nobs1=50,
326
+ alpha=0.05,
327
+ power=0.80,
328
+ ratio=1.0,
329
+ alternative='two-sided'
330
+ )
331
+ print(f"Study could detect d >= {detectable_d:.2f}")
332
+ ```
333
+
334
+ **Note**: Post-hoc "observed power" (computing power from the observed effect) is circular and misleading — it is a deterministic function of the p-value. If a study is done and someone asks about power, run a sensitivity analysis instead.
335
+
336
+ See `references/effect_sizes_and_power.md` for detailed guidance.
337
+
338
+ ---
339
+
340
+ ## Reporting Results
341
+
342
+ Follow `references/reporting_standards.md` for APA style. Every report needs:
343
+
344
+ 1. **Descriptive statistics**: M, SD, n for all groups/variables
345
+ 2. **Test statistics**: Test name, statistic, df, exact p-value (`p = .034`, not `p < .05`; use `p < .001` only below .001)
346
+ 3. **Effect sizes**: With confidence intervals
347
+ 4. **Assumption checks**: Which tests were run, results, and actions taken
348
+ 5. **All planned analyses**: Including non-significant findings — omitting them is cherry-picking
349
+
350
+ ### Example Report Templates
351
+
352
+ #### Independent T-Test
353
+
354
+ ```
355
+ Group A (n = 48, M = 75.2, SD = 8.5) scored significantly higher than
356
+ Group B (n = 52, M = 68.3, SD = 9.2), t(98) = 3.82, p < .001, d = 0.77,
357
+ 95% CI [0.36, 1.18], two-tailed. Assumptions of normality (Shapiro-Wilk:
358
+ Group A W = 0.97, p = .18; Group B W = 0.96, p = .12) and homogeneity
359
+ of variance (Levene's F(1, 98) = 1.23, p = .27) were satisfied.
360
+ ```
361
+
362
+ #### One-Way ANOVA
363
+
364
+ ```
365
+ A one-way ANOVA revealed a significant main effect of treatment condition
366
+ on test scores, F(2, 147) = 8.45, p < .001, η²_p = .10. Post hoc
367
+ comparisons using Tukey's HSD indicated that Condition A (M = 78.2,
368
+ SD = 7.3) scored significantly higher than Condition B (M = 71.5,
369
+ SD = 8.1, p = .002, d = 0.87) and Condition C (M = 70.1, SD = 7.9,
370
+ p < .001, d = 1.07). Conditions B and C did not differ significantly
371
+ (p = .52, d = 0.18).
372
+ ```
373
+
374
+ #### Multiple Regression
375
+
376
+ ```
377
+ Multiple linear regression was conducted to predict exam scores from
378
+ study hours, prior GPA, and attendance. The overall model was significant,
379
+ F(3, 146) = 45.2, p < .001, R² = .48, adjusted R² = .47. Study hours
380
+ (B = 1.80, SE = 0.31, β = .35, t = 5.78, p < .001, 95% CI [1.18, 2.42])
381
+ and prior GPA (B = 8.52, SE = 1.95, β = .28, t = 4.37, p < .001,
382
+ 95% CI [4.66, 12.38]) were significant predictors, while attendance was
383
+ not (B = 0.15, SE = 0.12, β = .08, t = 1.25, p = .21, 95% CI [-0.09, 0.39]).
384
+ Multicollinearity was not a concern (all VIF < 1.5).
385
+ ```
386
+
387
+ #### Bayesian Analysis
388
+
389
+ ```
390
+ A Bayesian independent samples t-test was conducted using weakly
391
+ informative priors (Normal(0, 10) for group means). The posterior
392
+ distribution indicated that Group A scored higher than Group B
393
+ (M_diff = 6.8, 95% credible interval [3.2, 10.4]), with a 99.8%
394
+ posterior probability that Group A's mean exceeded Group B's mean.
395
+ Convergence diagnostics were satisfactory (all R-hat < 1.01, ESS > 1000).
396
+ ```
397
+
398
+ If a non-parametric test was used, report medians rather than means, the U/W/H statistic, and a rank-based effect size (e.g., rank-biserial correlation, returned by `pg.mwu` as `RBC`).
399
+
400
+ ---
401
+
402
+ ## Bayesian Statistics
403
+
404
+ Consider Bayesian approaches when:
405
+ - You have prior information to incorporate
406
+ - You want direct probability statements about hypotheses ("there is a 95% probability the effect lies in this interval")
407
+ - Sample size is small or data collection is sequential (no correction needed for optional stopping)
408
+ - You need to quantify evidence *for* the null hypothesis
409
+ - The model is complex (hierarchical structure, missing data)
410
+
411
+ See `references/bayesian_statistics.md` for prior specification, Bayes Factors, credible intervals, hierarchical models, and convergence checking (R-hat < 1.01, sufficient ESS, posterior predictive checks).
412
+
413
+ ---
414
+
415
+ ## Bundled Resources
416
+
417
+ ### References (`references/`)
418
+
419
+ - **test_selection_guide.md**: Decision tree covering group comparisons, relationships, counts, time-to-event, agreement/reliability, and categorical analysis
420
+ - **assumptions_and_diagnostics.md**: Detailed guidance on checking and handling assumption violations
421
+ - **effect_sizes_and_power.md**: Calculating, interpreting, and reporting effect sizes; power analysis
422
+ - **bayesian_statistics.md**: Priors, Bayes Factors, credible intervals, hierarchical models, diagnostics
423
+ - **reporting_standards.md**: APA-style reporting guidelines with worked examples
424
+
425
+ ### Scripts (`scripts/`)
426
+
427
+ - **assumption_checks.py**: Automated assumption checking with visualizations
428
+ - `comprehensive_assumption_check()`: outliers + normality + variance homogeneity in one call
429
+ - `check_normality()`, `check_normality_per_group()`: Shapiro-Wilk with Q-Q plots
430
+ - `check_homogeneity_of_variance()`: Levene's test with box plots
431
+ - `check_regression_diagnostics()`: 4-panel residual plots + Shapiro-Wilk, Breusch-Pagan, Durbin-Watson, VIF for fitted OLS models
432
+ - `check_linearity()`, `detect_outliers()`
433
+
434
+ ---
435
+
436
+ ## Statistical Integrity
437
+
438
+ These are the practices that keep an analysis defensible. They matter because the most common statistical failures are not computational errors — they are silent flexibility (testing until something works) and selective reporting.
439
+
440
+ 1. **Distinguish confirmatory from exploratory.** State the planned analysis before running it; label anything discovered along the way as exploratory.
441
+ 2. **Don't shop for significance.** If the planned test is non-significant, that is the result. Trying alternative tests, subgroups, or outlier-removal schemes until p < .05 invalidates the p-value.
442
+ 3. **Correct for multiple comparisons** when running families of tests (Tukey HSD for post-hoc ANOVA; Holm or Benjamini-Hochberg FDR for other families) and say which correction was used.
443
+ 4. **A non-significant result is not evidence of no effect.** With small n, the study may simply have been underpowered — run a sensitivity analysis, or use a Bayesian analysis / equivalence test to actually quantify support for the null.
444
+ 5. **Statistical significance is not practical importance.** With large n, trivial effects reach p < .001. Lead the interpretation with the effect size.
445
+ 6. **Understand missing data before dropping rows.** Listwise deletion is only safe when data are missing completely at random; otherwise consider multiple imputation and say what was done.
446
+ 7. **Make it reproducible.** Set random seeds, report library versions for simulation-based methods, and keep the analysis in a runnable script.
@@ -0,0 +1,24 @@
1
+ # Upstream Attribution
2
+
3
+ This skill is derived from the `statistical-analysis` skill in `K-Dense-AI/scientific-agent-skills`.
4
+
5
+ - **Upstream repository:** https://github.com/K-Dense-AI/scientific-agent-skills
6
+ - **Upstream path:** `skills/statistical-analysis/`
7
+ - **License:** MIT (see [third_party/kdense-scientific-agent-skills/LICENSE](../../third_party/kdense-scientific-agent-skills/LICENSE))
8
+ - **Imported commit:** `390f5146bf3c1877cf15636a3dd7b775e4f0f185`
9
+ - **Import date:** 2026-08-25
10
+ - **Local path:** `skills/statistical-analysis/`
11
+
12
+ ## Imported Files
13
+
14
+ - `SKILL.md`
15
+ - `references/` (`assumptions_and_diagnostics.md`, `bayesian_statistics.md`, `effect_sizes_and_power.md`, `reporting_standards.md`, `test_selection_guide.md`)
16
+ - `scripts/` (`assumption_checks.py`)
17
+
18
+ ## Local modifications
19
+
20
+ Initial import:
21
+ - Local behavioral modifications: none (faithful vendoring, byte-for-byte identical to upstream).
22
+ - Upstream evals / tests: Vendored into `tests/upstream/kdense-scientific-agent-skills/statistical-analysis/`.
23
+
24
+ Any future AgentLayer modifications must be documented here.