terraproof 0.0.0-stage → 0.4.1

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,649 @@
1
+ # Effect Sizes and Power Analysis
2
+
3
+ This document provides guidance on calculating, interpreting, and reporting effect sizes, as well as conducting power analyses for study planning.
4
+
5
+ ## Why Effect Sizes Matter
6
+
7
+ 1. **Statistical significance ≠ practical significance**: p-values only tell if an effect exists, not how large it is
8
+ 2. **Sample size dependent**: With large samples, trivial effects become "significant"
9
+ 3. **Interpretation**: Effect sizes provide magnitude and practical importance
10
+ 4. **Meta-analysis**: Effect sizes enable combining results across studies
11
+ 5. **Power analysis**: Required for sample size determination
12
+
13
+ **Golden rule**: ALWAYS report effect sizes alongside p-values.
14
+
15
+ ---
16
+
17
+ ## Effect Sizes by Analysis Type
18
+
19
+ ### T-Tests and Mean Differences
20
+
21
+ #### Cohen's d (Standardized Mean Difference)
22
+
23
+ **Formula**:
24
+ - Independent groups: d = (M₁ - M₂) / SD_pooled
25
+ - Paired groups: d = M_diff / SD_diff
26
+
27
+ **Interpretation** (Cohen, 1988):
28
+ - Small: |d| = 0.20
29
+ - Medium: |d| = 0.50
30
+ - Large: |d| = 0.80
31
+
32
+ **Context-dependent interpretation**:
33
+ - In education: d = 0.40 is typical for successful interventions
34
+ - In psychology: d = 0.40 is considered meaningful
35
+ - In medicine: Small effect sizes can be clinically important
36
+
37
+ **Python calculation**:
38
+ ```python
39
+ import pingouin as pg
40
+ import numpy as np
41
+
42
+ # Independent t-test with effect size
43
+ result = pg.ttest(group1, group2, correction=False)
44
+ cohens_d = result['cohen_d'].values[0]
45
+ # (pingouin 0.6.0 renamed columns; on 0.5.x use 'p-val', 'cohen-d', 'CI95%', 'p-unc')
46
+
47
+ # Manual calculation
48
+ mean_diff = np.mean(group1) - np.mean(group2)
49
+ pooled_std = np.sqrt((np.var(group1, ddof=1) + np.var(group2, ddof=1)) / 2)
50
+ cohens_d = mean_diff / pooled_std
51
+
52
+ # Paired t-test
53
+ result = pg.ttest(pre, post, paired=True)
54
+ cohens_d = result['cohen_d'].values[0]
55
+ ```
56
+
57
+ **Confidence intervals for d**:
58
+ ```python
59
+ import pingouin as pg
60
+
61
+ # compute_effsize_from_t returns only the point estimate;
62
+ # get the CI separately with compute_esci
63
+ d = pg.compute_effsize(group1, group2, eftype='cohen')
64
+ ci = pg.compute_esci(stat=d, nx=len(group1), ny=len(group2),
65
+ eftype='cohen', confidence=0.95)
66
+ ```
67
+
68
+ ---
69
+
70
+ #### Hedges' g (Bias-Corrected d)
71
+
72
+ **Why use it**: Cohen's d has slight upward bias with small samples (n < 20)
73
+
74
+ **Formula**: g = d × correction_factor, where correction_factor = 1 - 3/(4df - 1)
75
+
76
+ **Python calculation**:
77
+ ```python
78
+ # pg.ttest output has no Hedges' g column; compute it directly
79
+ hedges_g = pg.compute_effsize(group1, group2, eftype='hedges')
80
+ ```
81
+
82
+ **Use Hedges' g when**:
83
+ - Sample sizes are small (n < 20 per group)
84
+ - Conducting meta-analyses (standard in meta-analysis)
85
+
86
+ ---
87
+
88
+ #### Glass's Δ (Delta)
89
+
90
+ **When to use**: When one group is a control with known variability
91
+
92
+ **Formula**: Δ = (M₁ - M₂) / SD_control
93
+
94
+ **Use cases**:
95
+ - Clinical trials (use control group SD)
96
+ - When treatment affects variability
97
+
98
+ ---
99
+
100
+ ### ANOVA
101
+
102
+ #### Eta-squared (η²)
103
+
104
+ **What it measures**: Proportion of total variance explained by factor
105
+
106
+ **Formula**: η² = SS_effect / SS_total
107
+
108
+ **Interpretation**:
109
+ - Small: η² = 0.01 (1% of variance)
110
+ - Medium: η² = 0.06 (6% of variance)
111
+ - Large: η² = 0.14 (14% of variance)
112
+
113
+ **Limitation**: In multi-factor designs each effect's η² shrinks as other factors are added (classical η² values sum to ≤ 1.0 by construction); it is partial η² that can sum to > 1.0 across factors
114
+
115
+ **Python calculation**:
116
+ ```python
117
+ import pingouin as pg
118
+
119
+ # One-way ANOVA (detailed=True is required for the SS column)
120
+ aov = pg.anova(dv='value', between='group', data=df, detailed=True)
121
+ eta_squared = aov['SS'][0] / aov['SS'].sum()
122
+
123
+ # Or read pingouin's np2 column, which is PARTIAL eta-squared:
124
+ partial_eta_sq = aov['np2'][0]
125
+ # np2 coincides with classical eta-squared only for one-way (single-factor) designs
126
+ ```
127
+
128
+ ---
129
+
130
+ #### Partial Eta-squared (η²_p)
131
+
132
+ **What it measures**: Proportion of variance explained by factor, excluding other factors
133
+
134
+ **Formula**: η²_p = SS_effect / (SS_effect + SS_error)
135
+
136
+ **Interpretation**: Same benchmarks as η²
137
+
138
+ **When to use**: Multi-factor ANOVA (standard in factorial designs)
139
+
140
+ **Limitation**: Across factors, partial η² values can sum to > 1.0 — they are not additive shares of total variance
141
+
142
+ **Python calculation**:
143
+ ```python
144
+ aov = pg.anova(dv='value', between=['factor1', 'factor2'], data=df)
145
+ # pingouin reports partial eta-squared by default
146
+ partial_eta_sq = aov['np2']
147
+ ```
148
+
149
+ ---
150
+
151
+ #### Omega-squared (ω²)
152
+
153
+ **What it measures**: Less biased estimate of population variance explained
154
+
155
+ **Why use it**: η² overestimates effect size; ω² provides better population estimate
156
+
157
+ **Formula**: ω² = (SS_effect - df_effect × MS_error) / (SS_total + MS_error)
158
+
159
+ **Interpretation**: Same benchmarks as η², but typically smaller values
160
+
161
+ **Python calculation**:
162
+ ```python
163
+ def omega_squared(aov_table):
164
+ ss_effect = aov_table.loc[0, 'SS']
165
+ ss_total = aov_table['SS'].sum()
166
+ ms_error = aov_table.loc[aov_table.index[-1], 'MS'] # Residual MS
167
+ df_effect = aov_table.loc[0, 'DF']
168
+
169
+ omega_sq = (ss_effect - df_effect * ms_error) / (ss_total + ms_error)
170
+ return omega_sq
171
+ ```
172
+
173
+ ---
174
+
175
+ #### Cohen's f
176
+
177
+ **What it measures**: Effect size for ANOVA (analogous to Cohen's d)
178
+
179
+ **Formula**: f = √(η² / (1 - η²))
180
+
181
+ **Interpretation**:
182
+ - Small: f = 0.10
183
+ - Medium: f = 0.25
184
+ - Large: f = 0.40
185
+
186
+ **Python calculation**:
187
+ ```python
188
+ eta_squared = 0.06 # From ANOVA
189
+ cohens_f = np.sqrt(eta_squared / (1 - eta_squared))
190
+ ```
191
+
192
+ **Use in power analysis**: Required for ANOVA power calculations
193
+
194
+ ---
195
+
196
+ ### Correlation
197
+
198
+ #### Pearson's r / Spearman's ρ
199
+
200
+ **Interpretation**:
201
+ - Small: |r| = 0.10
202
+ - Medium: |r| = 0.30
203
+ - Large: |r| = 0.50
204
+
205
+ **Important notes**:
206
+ - r² = coefficient of determination (proportion of variance explained)
207
+ - r = 0.30 means 9% shared variance (0.30² = 0.09)
208
+ - Consider direction (positive/negative) and context
209
+
210
+ **Python calculation**:
211
+ ```python
212
+ import pingouin as pg
213
+
214
+ # Pearson correlation with CI
215
+ result = pg.corr(x, y, method='pearson')
216
+ r = result['r'].values[0]
217
+ ci = result['CI95'].values[0] # pingouin 0.6.0 renamed CI95% to CI95
218
+
219
+ # Spearman correlation
220
+ result = pg.corr(x, y, method='spearman')
221
+ rho = result['r'].values[0]
222
+ ```
223
+
224
+ ---
225
+
226
+ ### Regression
227
+
228
+ #### R² (Coefficient of Determination)
229
+
230
+ **What it measures**: Proportion of variance in Y explained by model
231
+
232
+ **Interpretation**:
233
+ - Small: R² = 0.02
234
+ - Medium: R² = 0.13
235
+ - Large: R² = 0.26
236
+
237
+ **Context-dependent**:
238
+ - Physical sciences: R² > 0.90 expected
239
+ - Social sciences: R² > 0.30 considered good
240
+ - Behavior prediction: R² > 0.10 may be meaningful
241
+
242
+ **Python calculation**:
243
+ ```python
244
+ from sklearn.metrics import r2_score
245
+ import statsmodels.api as sm
246
+
247
+ # Using statsmodels (add_constant adds the intercept column)
248
+ model = sm.OLS(y, sm.add_constant(X)).fit()
249
+ r_squared = model.rsquared
250
+ adjusted_r_squared = model.rsquared_adj
251
+
252
+ # Manual
253
+ r_squared = 1 - (SS_residual / SS_total)
254
+ ```
255
+
256
+ ---
257
+
258
+ #### Adjusted R²
259
+
260
+ **Why use it**: R² artificially increases when adding predictors; adjusted R² penalizes model complexity
261
+
262
+ **Formula**: R²_adj = 1 - (1 - R²) × (n - 1) / (n - k - 1)
263
+
264
+ **When to use**: Always report alongside R² for multiple regression
265
+
266
+ ---
267
+
268
+ #### Standardized Regression Coefficients (β)
269
+
270
+ **What it measures**: Effect of one-SD change in predictor on outcome (in SD units)
271
+
272
+ **Interpretation**: Similar to Cohen's d
273
+ - Small: |β| = 0.10
274
+ - Medium: |β| = 0.30
275
+ - Large: |β| = 0.50
276
+
277
+ **Python calculation**:
278
+ ```python
279
+ from scipy import stats
280
+
281
+ # Standardize variables first
282
+ X_std = (X - X.mean()) / X.std()
283
+ y_std = (y - y.mean()) / y.std()
284
+
285
+ model = OLS(y_std, X_std).fit()
286
+ beta = model.params
287
+ ```
288
+
289
+ ---
290
+
291
+ #### f² (Cohen's f-squared for Regression)
292
+
293
+ **What it measures**: Effect size for individual predictors or model comparison
294
+
295
+ **Formula**: f² = (R²_AB - R²_A) / (1 - R²_AB)
296
+
297
+ Where:
298
+ - R²_AB = R² for full model with predictor
299
+ - R²_A = R² for reduced model without predictor
300
+
301
+ **Interpretation**:
302
+ - Small: f² = 0.02
303
+ - Medium: f² = 0.15
304
+ - Large: f² = 0.35
305
+
306
+ **Python calculation**:
307
+ ```python
308
+ # Compare two nested models
309
+ model_full = OLS(y, X_full).fit()
310
+ model_reduced = OLS(y, X_reduced).fit()
311
+
312
+ r2_full = model_full.rsquared
313
+ r2_reduced = model_reduced.rsquared
314
+
315
+ f_squared = (r2_full - r2_reduced) / (1 - r2_full)
316
+ ```
317
+
318
+ ---
319
+
320
+ ### Categorical Data Analysis
321
+
322
+ #### Cramér's V
323
+
324
+ **What it measures**: Association strength for χ² test (works for any table size)
325
+
326
+ **Formula**: V = √(χ² / (n × (k - 1)))
327
+
328
+ Where k = min(rows, columns)
329
+
330
+ **Interpretation** (benchmarks depend on df* = min(rows, columns) − 1):
331
+
332
+ | df* | Small | Medium | Large |
333
+ |-----|-------|--------|-------|
334
+ | 1 (2×2) | 0.10 | 0.30 | 0.50 |
335
+ | 2 | 0.07 | 0.21 | 0.35 |
336
+ | 3 | 0.06 | 0.17 | 0.29 |
337
+
338
+ **For 2×2 tables**: Use phi coefficient (φ)
339
+
340
+ **Python calculation**:
341
+ ```python
342
+ import numpy as np
343
+ from scipy.stats.contingency import association
344
+
345
+ # Cramér's V
346
+ cramers_v = association(contingency_table, method='cramer')
347
+
348
+ # Phi coefficient (2x2): |phi| equals Cramér's V for a 2x2 table.
349
+ # Caution: method='pearson' is Pearson's contingency coefficient, NOT phi.
350
+ a, b, c, d = np.asarray(contingency_table).ravel()
351
+ phi = (a * d - b * c) / np.sqrt((a + b) * (c + d) * (a + c) * (b + d)) # signed phi
352
+ ```
353
+
354
+ ---
355
+
356
+ #### Odds Ratio (OR) and Risk Ratio (RR)
357
+
358
+ **For 2×2 contingency tables**:
359
+
360
+ | | Outcome + | Outcome - |
361
+ |-----------|-----------|-----------|
362
+ | Exposed | a | b |
363
+ | Unexposed | c | d |
364
+
365
+ **Odds Ratio**: OR = (a/b) / (c/d) = ad / bc
366
+
367
+ **Interpretation**:
368
+ - OR = 1: No association
369
+ - OR > 1: Positive association (increased odds)
370
+ - OR < 1: Negative association (decreased odds)
371
+ - OR = 2: Twice the odds
372
+ - OR = 0.5: Half the odds
373
+
374
+ **Risk Ratio**: RR = (a/(a+b)) / (c/(c+d))
375
+
376
+ **When to use**:
377
+ - Cohort studies: Use RR (more interpretable)
378
+ - Case-control studies: Use OR (RR not available)
379
+ - Logistic regression: OR is natural output
380
+
381
+ **Python calculation**:
382
+ ```python
383
+ import numpy as np
384
+ from scipy import stats
385
+ import statsmodels.api as sm
386
+
387
+ # From contingency table
388
+ odds_ratio = (a * d) / (b * c)
389
+
390
+ # Fisher's exact test returns only the sample OR and a p-value (no CI)
391
+ table = np.array([[a, b], [c, d]])
392
+ oddsratio, pvalue = stats.fisher_exact(table)
393
+
394
+ # Odds-ratio confidence interval (scipy >= 1.10; conditional MLE estimate)
395
+ or_result = stats.contingency.odds_ratio(table)
396
+ ci = or_result.confidence_interval(confidence_level=0.95)
397
+
398
+ # From logistic regression
399
+ model = sm.Logit(y, X).fit()
400
+ odds_ratios = np.exp(model.params) # Exponentiate coefficients
401
+ ci = np.exp(model.conf_int()) # Exponentiate CIs
402
+ ```
403
+
404
+ ---
405
+
406
+ ### Nonparametric Effect Sizes
407
+
408
+ **Rank-biserial correlation (r_rb)**: Effect size for Mann-Whitney U and Wilcoxon signed-rank tests (range −1 to 1; interpret |r_rb| roughly like r). Returned by `pg.mwu` and `pg.wilcoxon` as the `RBC` column.
409
+
410
+ **Common-language effect size (CLES)**: Probability that a randomly sampled value from one group exceeds a randomly sampled value from the other (0.5 = no effect). Returned by `pg.mwu` as `CLES`.
411
+
412
+ **r = z / √N**: Classic effect size when a z approximation is reported for Mann-Whitney/Wilcoxon (small 0.10, medium 0.30, large 0.50).
413
+
414
+ **Epsilon-squared (ε²)**: Effect size for Kruskal-Wallis: ε² = H × (n + 1) / (n² − 1).
415
+
416
+ **Python calculation**:
417
+ ```python
418
+ import numpy as np
419
+ import pandas as pd
420
+ import pingouin as pg
421
+
422
+ res = pg.mwu(group1, group2)
423
+ print(res[['U_val', 'p_val', 'RBC', 'CLES']])
424
+
425
+ # Kruskal-Wallis with epsilon-squared
426
+ df = pd.DataFrame({'value': np.concatenate([group1, group2, group3]),
427
+ 'group': np.repeat(['a', 'b', 'c'],
428
+ [len(group1), len(group2), len(group3)])})
429
+ kw = pg.kruskal(df, dv='value', between='group')
430
+ H, n = kw['H'].values[0], len(df)
431
+ epsilon_sq = H * (n + 1) / (n**2 - 1)
432
+ ```
433
+
434
+ ---
435
+
436
+ ### Bayesian Effect Sizes
437
+
438
+ #### Bayes Factor (BF)
439
+
440
+ **What it measures**: Ratio of evidence for alternative vs. null hypothesis
441
+
442
+ **Interpretation**:
443
+ - BF₁₀ = 1: Equal evidence for H₁ and H₀
444
+ - BF₁₀ = 3: H₁ is 3× more likely than H₀ (moderate evidence)
445
+ - BF₁₀ = 10: H₁ is 10× more likely than H₀ (strong evidence)
446
+ - BF₁₀ > 100: Decisive evidence for H₁ (30-100 counts as "very strong" on the Jeffreys scale)
447
+ - BF₁₀ = 0.33: H₀ is 3× more likely than H₁
448
+ - BF₁₀ = 0.10: H₀ is 10× more likely than H₁
449
+
450
+ For the full Jeffreys interpretation table and BF reporting language, see `bayesian_statistics.md`.
451
+
452
+ **Python calculation**:
453
+ ```python
454
+ import pingouin as pg
455
+
456
+ # Pingouin 0.5+: two-sided BF10 on independent t-tests; use BayesFactor/JASP/PyMC for full inference
457
+ result = pg.ttest(group1, group2, correction=False)
458
+ bf10 = result['BF10'].values[0]
459
+ ```
460
+
461
+ ---
462
+
463
+ ### Bootstrap Confidence Intervals
464
+
465
+ When no analytic CI exists for an effect size (or its assumptions are doubtful), bootstrap one:
466
+
467
+ ```python
468
+ import numpy as np
469
+ from scipy import stats
470
+
471
+ def cohen_d(x, y):
472
+ nx, ny = len(x), len(y)
473
+ sp = np.sqrt(((nx - 1) * np.var(x, ddof=1) + (ny - 1) * np.var(y, ddof=1))
474
+ / (nx + ny - 2))
475
+ return (np.mean(x) - np.mean(y)) / sp
476
+
477
+ boot = stats.bootstrap((group1, group2), cohen_d, n_resamples=9999,
478
+ method='BCa', rng=np.random.default_rng(42))
479
+ print(boot.confidence_interval) # 95% BCa CI by default
480
+ ```
481
+
482
+ The same pattern works for any statistic (medians, correlations, rank-biserial, ...). Prefer `method='BCa'` and use at least 5000-10000 resamples.
483
+
484
+ ---
485
+
486
+ ## Power Analysis
487
+
488
+ ### Concepts
489
+
490
+ **Statistical power**: Probability of detecting an effect if it exists (1 - β)
491
+
492
+ **Conventional standards**:
493
+ - Power = 0.80 (80% chance of detecting effect)
494
+ - α = 0.05 (5% Type I error rate)
495
+
496
+ **Four interconnected parameters** (given 3, can solve for 4th):
497
+ 1. Sample size (n)
498
+ 2. Effect size (d, f, etc.)
499
+ 3. Significance level (α)
500
+ 4. Power (1 - β)
501
+
502
+ ---
503
+
504
+ ### A Priori Power Analysis (Planning)
505
+
506
+ **Purpose**: Determine required sample size before study
507
+
508
+ **Steps**:
509
+ 1. Specify expected effect size (from literature, pilot data, or minimum meaningful effect)
510
+ 2. Set α level (typically 0.05)
511
+ 3. Set desired power (typically 0.80)
512
+ 4. Calculate required n
513
+
514
+ **Python implementation**:
515
+ ```python
516
+ from statsmodels.stats.power import (
517
+ tt_ind_solve_power,
518
+ zt_ind_solve_power,
519
+ FTestAnovaPower,
520
+ NormalIndPower
521
+ )
522
+
523
+ # T-test power analysis
524
+ n_required = tt_ind_solve_power(
525
+ effect_size=0.5, # Cohen's d
526
+ alpha=0.05,
527
+ power=0.80,
528
+ ratio=1.0, # Equal group sizes
529
+ alternative='two-sided'
530
+ )
531
+
532
+ # ANOVA power analysis (kwarg is k_groups, not ngroups)
533
+ anova_power = FTestAnovaPower()
534
+ n_total = anova_power.solve_power(
535
+ effect_size=0.25, # Cohen's f
536
+ k_groups=3,
537
+ alpha=0.05,
538
+ power=0.80
539
+ )
540
+ # Returns the TOTAL sample size across all groups:
541
+ # f = 0.25, k = 3 -> ~158 total, i.e. ~53 per group
542
+
543
+ # Correlation power analysis
544
+ from pingouin import power_corr
545
+ n_required = power_corr(r=0.30, power=0.80, alpha=0.05)
546
+ ```
547
+
548
+ ---
549
+
550
+ ### Post Hoc Power Analysis (After Study)
551
+
552
+ **⚠️ CAUTION**: Post hoc power is controversial and often not recommended
553
+
554
+ **Why it's problematic**:
555
+ - Observed power is a direct function of p-value
556
+ - If p > 0.05, power is always low
557
+ - Provides no additional information beyond p-value
558
+ - Can be misleading
559
+
560
+ **When it might be acceptable**:
561
+ - Study planning for future research
562
+ - Using effect size from multiple studies (not just your own)
563
+ - Explicit goal is sample size for replication
564
+
565
+ **Better alternatives**:
566
+ - Report confidence intervals for effect sizes
567
+ - Conduct sensitivity analysis
568
+ - Report minimum detectable effect size
569
+
570
+ ---
571
+
572
+ ### Sensitivity Analysis
573
+
574
+ **Purpose**: Determine minimum detectable effect size given study parameters
575
+
576
+ **When to use**: After study is complete, to understand study's capability
577
+
578
+ **Python implementation**:
579
+ ```python
580
+ # What effect size could we detect with n=50 per group?
581
+ detectable_effect = tt_ind_solve_power(
582
+ effect_size=None, # Solve for this
583
+ nobs1=50,
584
+ alpha=0.05,
585
+ power=0.80,
586
+ ratio=1.0,
587
+ alternative='two-sided'
588
+ )
589
+
590
+ print(f"With n=50 per group, we could detect d ≥ {detectable_effect:.2f}")
591
+ ```
592
+
593
+ ---
594
+
595
+ ## Reporting Effect Sizes
596
+
597
+ ### APA Style Guidelines
598
+
599
+ **T-test example**:
600
+ > "Group A (M = 75.2, SD = 8.5) scored significantly higher than Group B (M = 68.3, SD = 9.2), t(98) = 3.82, p < .001, d = 0.77, 95% CI [0.36, 1.18]."
601
+
602
+ **ANOVA example**:
603
+ > "There was a significant main effect of treatment condition on test scores, F(2, 87) = 8.45, p < .001, η²p = .16. Post hoc comparisons using Tukey's HSD revealed..."
604
+
605
+ **Correlation example**:
606
+ > "There was a moderate positive correlation between study time and exam scores, r(148) = .42, p < .001, 95% CI [.27, .55]."
607
+
608
+ **Regression example**:
609
+ > "The regression model significantly predicted exam scores, F(3, 146) = 45.2, p < .001, R² = .48. Study hours (β = .52, p < .001) and prior GPA (β = .31, p < .001) were significant predictors."
610
+
611
+ **Bayesian example**: See `bayesian_statistics.md` (Reporting Bayesian Results) for Bayes Factor and posterior reporting templates.
612
+
613
+ ---
614
+
615
+ ## Effect Size Pitfalls
616
+
617
+ 1. **Don't only rely on benchmarks**: Context matters; small effects can be meaningful
618
+ 2. **Report confidence intervals**: CIs show precision of effect size estimate
619
+ 3. **Distinguish statistical vs. practical significance**: Large n can make trivial effects "significant"
620
+ 4. **Consider cost-benefit**: Even small effects may be valuable if intervention is low-cost
621
+ 5. **Multiple outcomes**: Effect sizes vary across outcomes; report all
622
+ 6. **Don't cherry-pick**: Report effects for all planned analyses
623
+ 7. **Publication bias**: Published effects are often overestimated
624
+
625
+ ---
626
+
627
+ ## Quick Reference Table
628
+
629
+ | Analysis | Effect Size | Small | Medium | Large |
630
+ |----------|-------------|-------|--------|-------|
631
+ | T-test | Cohen's d | 0.20 | 0.50 | 0.80 |
632
+ | ANOVA | η², ω² | 0.01 | 0.06 | 0.14 |
633
+ | ANOVA | Cohen's f | 0.10 | 0.25 | 0.40 |
634
+ | Correlation | r, ρ | 0.10 | 0.30 | 0.50 |
635
+ | Regression | R² | 0.02 | 0.13 | 0.26 |
636
+ | Regression | f² | 0.02 | 0.15 | 0.35 |
637
+ | Chi-square (df* = 1, 2×2) | Cramér's V, φ | 0.10 | 0.30 | 0.50 |
638
+ | Chi-square (df* = 2) | Cramér's V | 0.07 | 0.21 | 0.35 |
639
+ | Chi-square (df* = 3) | Cramér's V | 0.06 | 0.17 | 0.29 |
640
+
641
+ *Note*: df* = min(rows, columns) − 1.
642
+
643
+ ---
644
+
645
+ ## Resources
646
+
647
+ - Cohen, J. (1988). *Statistical Power Analysis for the Behavioral Sciences* (2nd ed.)
648
+ - Lakens, D. (2013). Calculating and reporting effect sizes
649
+ - Ellis, P. D. (2010). *The Essential Guide to Effect Sizes*