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,379 @@
1
+ # Statistical Assumptions and Diagnostic Procedures
2
+
3
+ This document provides comprehensive guidance on checking and validating statistical assumptions for various analyses.
4
+
5
+ ## General Principles
6
+
7
+ 1. **Always check assumptions before interpreting test results**
8
+ 2. **Use multiple diagnostic methods** (visual + formal tests)
9
+ 3. **Consider robustness**: Some tests are robust to violations under certain conditions
10
+ 4. **Document all assumption checks** in analysis reports
11
+ 5. **Report violations and remedial actions taken**
12
+
13
+ ## Common Assumptions Across Tests
14
+
15
+ ### 1. Independence of Observations
16
+
17
+ **What it means**: Each observation is independent; measurements on one subject do not influence measurements on another.
18
+
19
+ **How to check**:
20
+ - Review study design and data collection procedures
21
+ - For time series: Check autocorrelation (ACF/PACF plots, Durbin-Watson test)
22
+ - For clustered data: Consider intraclass correlation (ICC)
23
+
24
+ **What to do if violated**:
25
+ - Use mixed-effects models for clustered/hierarchical data
26
+ - Use time series methods for temporally dependent data
27
+ - Use generalized estimating equations (GEE) for correlated data
28
+
29
+ **Critical severity**: HIGH - violations can severely inflate Type I error
30
+
31
+ ---
32
+
33
+ ### 2. Normality
34
+
35
+ **What it means**: Data or residuals follow a normal (Gaussian) distribution.
36
+
37
+ **When required**:
38
+ - t-tests (for small samples; robust for n > 30 per group)
39
+ - ANOVA (for small samples; robust for n > 30 per group)
40
+ - Linear regression (for residuals)
41
+ - Some correlation tests (Pearson)
42
+
43
+ **How to check**:
44
+
45
+ **Visual methods** (primary):
46
+ - Q-Q (quantile-quantile) plot: Points should fall on diagonal line
47
+ - Histogram with normal curve overlay
48
+ - Kernel density plot
49
+
50
+ **Formal tests** (secondary):
51
+ - Shapiro-Wilk test (good default; scipy handles n up to ~5000 and warns above that)
52
+ - Lilliefors test (`statsmodels.stats.diagnostic.lilliefors`) — use this instead of a plain Kolmogorov-Smirnov test, which is invalid when the mean/SD are estimated from the data
53
+ - Anderson-Darling test
54
+
55
+ **Python implementation**:
56
+ ```python
57
+ from scipy import stats
58
+ import matplotlib.pyplot as plt
59
+
60
+ # Shapiro-Wilk test
61
+ statistic, p_value = stats.shapiro(data)
62
+
63
+ # Q-Q plot
64
+ stats.probplot(data, dist="norm", plot=plt)
65
+ ```
66
+
67
+ **Interpretation guidance**:
68
+ - For n < 30: Both visual and formal tests important
69
+ - For 30 ≤ n < 100: Visual inspection primary, formal tests secondary
70
+ - For n ≥ 100: Formal tests overly sensitive; rely on visual inspection
71
+ - Look for severe skewness, outliers, or bimodality
72
+
73
+ **What to do if violated**:
74
+ - **Mild violations** (slight skewness): Proceed if n > 30 per group (this CLT heuristic assumes mild skewness; severely skewed or heavy-tailed data can require much larger samples)
75
+ - **Moderate violations**: Use non-parametric alternatives (Mann-Whitney, Kruskal-Wallis, Wilcoxon)
76
+ - **Severe violations**:
77
+ - Transform data (log, square root, Box-Cox)
78
+ - Use non-parametric methods
79
+ - Use robust regression methods
80
+ - Consider bootstrapping
81
+
82
+ **Critical severity**: MEDIUM - parametric tests are often robust to mild violations with adequate sample size
83
+
84
+ ---
85
+
86
+ ### 3. Homogeneity of Variance (Homoscedasticity)
87
+
88
+ **What it means**: Variances are equal across groups or across the range of predictors.
89
+
90
+ **When required**:
91
+ - Independent samples t-test
92
+ - ANOVA
93
+ - Linear regression (constant variance of residuals)
94
+
95
+ **How to check**:
96
+
97
+ **Visual methods** (primary):
98
+ - Box plots by group (for t-test/ANOVA)
99
+ - Residuals vs. fitted values plot (for regression) - should show random scatter
100
+ - Scale-location plot (square root of standardized residuals vs. fitted)
101
+
102
+ **Formal tests** (secondary):
103
+ - Levene's test (robust to non-normality)
104
+ - Bartlett's test (sensitive to non-normality, not recommended)
105
+ - Brown-Forsythe test (median-based version of Levene's)
106
+ - Breusch-Pagan test (for regression)
107
+
108
+ **Python implementation**:
109
+ ```python
110
+ from scipy import stats
111
+ import pingouin as pg
112
+
113
+ # Levene's test
114
+ statistic, p_value = stats.levene(group1, group2, group3)
115
+
116
+ # For regression
117
+ # Breusch-Pagan test
118
+ # Note: exog must include the constant column (e.g. exog = sm.add_constant(X),
119
+ # or pass the fitted model's model.exog)
120
+ from statsmodels.stats.diagnostic import het_breuschpagan
121
+ _, p_value, _, _ = het_breuschpagan(residuals, exog)
122
+ ```
123
+
124
+ **Interpretation guidance**:
125
+ - Variance ratio (max/min) < 2-3: Generally acceptable
126
+ - For ANOVA: Test is robust if groups have equal sizes
127
+ - For regression: Look for funnel patterns in residual plots
128
+
129
+ **What to do if violated**:
130
+ - **t-test**: Use Welch's t-test (does not assume equal variances)
131
+ - **ANOVA**: Use Welch's ANOVA or Brown-Forsythe ANOVA
132
+ - **Regression**:
133
+ - Transform dependent variable (log, square root)
134
+ - Use weighted least squares (WLS)
135
+ - Use robust standard errors (HC3)
136
+ - Use generalized linear models (GLM) with appropriate variance function
137
+
138
+ **Critical severity**: MEDIUM - tests can be robust with equal sample sizes
139
+
140
+ ---
141
+
142
+ ## Test-Specific Assumptions
143
+
144
+ ### T-Tests
145
+
146
+ **Assumptions**:
147
+ 1. Independence of observations
148
+ 2. Normality (each group for independent t-test; differences for paired t-test)
149
+ 3. Homogeneity of variance (independent t-test only)
150
+
151
+ **Diagnostic workflow**:
152
+ ```python
153
+ import scipy.stats as stats
154
+ import pingouin as pg
155
+
156
+ # Check normality for each group
157
+ stats.shapiro(group1)
158
+ stats.shapiro(group2)
159
+
160
+ # Check homogeneity of variance
161
+ stats.levene(group1, group2)
162
+
163
+ # If assumptions violated:
164
+ # Option 1: Welch's t-test (unequal variances)
165
+ pg.ttest(group1, group2, correction=True) # correction=True applies Welch's
166
+ # (correction='auto' applies Welch only when variances/group sizes are unequal;
167
+ # correction=False forces Student's t-test)
168
+
169
+ # Option 2: Non-parametric alternative
170
+ pg.mwu(group1, group2) # Mann-Whitney U
171
+ ```
172
+
173
+ ---
174
+
175
+ ### ANOVA
176
+
177
+ **Assumptions**:
178
+ 1. Independence of observations within and between groups
179
+ 2. Normality in each group
180
+ 3. Homogeneity of variance across groups
181
+
182
+ **Additional considerations**:
183
+ - For repeated measures ANOVA: Sphericity assumption (Mauchly's test)
184
+
185
+ **Diagnostic workflow**:
186
+ ```python
187
+ import pingouin as pg
188
+ from scipy import stats
189
+
190
+ # Check normality per group
191
+ for group in df['group'].unique():
192
+ data = df[df['group'] == group]['value']
193
+ w, p = stats.shapiro(data)
194
+ print(f"{group}: W = {w:.3f}, p = {p:.4f}")
195
+
196
+ # Check homogeneity of variance
197
+ print(pg.homoscedasticity(df, dv='value', group='group'))
198
+
199
+ # For repeated measures: Check sphericity
200
+ # Automatically tested in pingouin's rm_anova
201
+ ```
202
+
203
+ **What to do if sphericity violated** (repeated measures):
204
+ - Greenhouse-Geisser correction (ε < 0.75)
205
+ - Huynh-Feldt correction (ε > 0.75)
206
+ - Use multivariate approach (MANOVA)
207
+
208
+ ---
209
+
210
+ ### Linear Regression
211
+
212
+ **Assumptions**:
213
+ 1. **Linearity**: Relationship between X and Y is linear
214
+ 2. **Independence**: Residuals are independent
215
+ 3. **Homoscedasticity**: Constant variance of residuals
216
+ 4. **Normality**: Residuals are normally distributed
217
+ 5. **No multicollinearity**: Predictors are not highly correlated (multiple regression)
218
+
219
+ **Diagnostic workflow**:
220
+
221
+ **1. Linearity**:
222
+ ```python
223
+ import matplotlib.pyplot as plt
224
+ import seaborn as sns
225
+
226
+ # Scatter plots of Y vs each X
227
+ # Residuals vs. fitted values (should be randomly scattered)
228
+ plt.scatter(fitted_values, residuals)
229
+ plt.axhline(y=0, color='r', linestyle='--')
230
+ ```
231
+
232
+ **2. Independence**:
233
+ ```python
234
+ from statsmodels.stats.stattools import durbin_watson
235
+
236
+ # Durbin-Watson test (for time series)
237
+ dw_statistic = durbin_watson(residuals)
238
+ # Values between 1.5-2.5 suggest independence
239
+ ```
240
+
241
+ **3. Homoscedasticity**:
242
+ ```python
243
+ # Breusch-Pagan test
244
+ # Note: exog must include the constant column (e.g. sm.add_constant(X))
245
+ from statsmodels.stats.diagnostic import het_breuschpagan
246
+ _, p_value, _, _ = het_breuschpagan(residuals, exog)
247
+
248
+ # Visual: Scale-location plot
249
+ plt.scatter(fitted_values, np.sqrt(np.abs(std_residuals)))
250
+ ```
251
+
252
+ **4. Normality of residuals**:
253
+ ```python
254
+ # Q-Q plot of residuals
255
+ stats.probplot(residuals, dist="norm", plot=plt)
256
+
257
+ # Shapiro-Wilk test
258
+ stats.shapiro(residuals)
259
+ ```
260
+
261
+ **5. Multicollinearity**:
262
+ ```python
263
+ from statsmodels.stats.outliers_influence import variance_inflation_factor
264
+
265
+ # Calculate VIF for each predictor
266
+ vif_data = pd.DataFrame()
267
+ vif_data["feature"] = X.columns
268
+ vif_data["VIF"] = [variance_inflation_factor(X.values, i) for i in range(len(X.columns))]
269
+
270
+ # VIF > 10 indicates severe multicollinearity
271
+ # VIF > 5 indicates moderate multicollinearity
272
+ ```
273
+
274
+ **What to do if violated**:
275
+ - **Non-linearity**: Add polynomial terms, use GAM, or transform variables
276
+ - **Heteroscedasticity**: Transform Y, use WLS, use robust SE
277
+ - **Non-normal residuals**: Transform Y, use robust methods, check for outliers
278
+ - **Multicollinearity**: Remove correlated predictors, use PCA, ridge regression
279
+
280
+ ---
281
+
282
+ ### Logistic Regression
283
+
284
+ **Assumptions**:
285
+ 1. **Independence**: Observations are independent
286
+ 2. **Linearity**: Linear relationship between log-odds and continuous predictors
287
+ 3. **No perfect multicollinearity**: Predictors not perfectly correlated
288
+ 4. **Large sample size**: At least 10-20 events per predictor
289
+
290
+ **Diagnostic workflow**:
291
+
292
+ **1. Linearity of logit**:
293
+ ```python
294
+ # Box-Tidwell test: Add interaction with log of continuous predictor
295
+ # If interaction is significant, linearity violated
296
+ ```
297
+
298
+ **2. Multicollinearity**:
299
+ ```python
300
+ # Use VIF as in linear regression
301
+ ```
302
+
303
+ **3. Influential observations**:
304
+ ```python
305
+ # Cook's distance, DFBetas, leverage (statsmodels >= 0.10)
306
+ # Do NOT use OLSInfluence on Logit/GLM results; use get_influence(),
307
+ # which returns MLEInfluence (Logit) or GLMInfluence (GLM)
308
+ influence = model.get_influence()
309
+ cooks_d, cooks_p = influence.cooks_distance # returns a tuple: (distances, p_values)
310
+ ```
311
+
312
+ **4. Model fit / calibration**:
313
+ ```python
314
+ # Calibration curve: compare predicted probabilities to observed event rates
315
+ # (e.g. sklearn.calibration.calibration_curve), plus the Brier score
316
+ # Pseudo R-squared
317
+ # Classification metrics (accuracy, AUC-ROC)
318
+ # Note: the Hosmer-Lemeshow test is not implemented in scipy/statsmodels
319
+ # and is sensitive to the choice of bins; prefer calibration curves
320
+ ```
321
+
322
+ ---
323
+
324
+ ## Outlier Detection
325
+
326
+ **Methods**:
327
+ 1. **Visual**: Box plots, scatter plots
328
+ 2. **Statistical**:
329
+ - Z-scores: |z| > 3 suggests outlier
330
+ - IQR method: Values < Q1 - 1.5×IQR or > Q3 + 1.5×IQR
331
+ - Modified Z-score using median absolute deviation (robust to outliers)
332
+
333
+ **For regression**:
334
+ - **Leverage**: High leverage points (hat values)
335
+ - **Influence**: Cook's distance > 4/n suggests influential point
336
+ - **Outliers**: Studentized residuals > ±3
337
+
338
+ **What to do**:
339
+ 1. Investigate data entry errors
340
+ 2. Consider if outliers are valid observations
341
+ 3. Report sensitivity analysis (results with and without outliers)
342
+ 4. Use robust methods if outliers are legitimate
343
+
344
+ ---
345
+
346
+ ## Sample Size Considerations
347
+
348
+ ### Minimum Sample Sizes (Rules of Thumb)
349
+
350
+ - **T-test**: n ≥ 30 per group for robustness to non-normality
351
+ - **ANOVA**: n ≥ 30 per group
352
+ - **Correlation**: n ≥ 30 for adequate power
353
+ - **Simple regression**: n ≥ 50
354
+ - **Multiple regression**: 10-15 observations per predictor (or Green's rule: n ≥ 50 + 8k for testing the overall model with k predictors)
355
+ - **Logistic regression**: n ≥ 10-20 events per predictor
356
+
357
+ ### Small Sample Considerations
358
+
359
+ For small samples:
360
+ - Assumptions become more critical
361
+ - Use exact tests when available (Fisher's exact, exact logistic regression)
362
+ - Consider non-parametric alternatives
363
+ - Use permutation tests or bootstrap methods
364
+ - Be conservative with interpretation
365
+
366
+ ---
367
+
368
+ ## Reporting Assumption Checks
369
+
370
+ When reporting analyses, include:
371
+
372
+ 1. **Statement of assumptions checked**: List all assumptions tested
373
+ 2. **Methods used**: Describe visual and formal tests employed
374
+ 3. **Results of diagnostic tests**: Report test statistics and p-values
375
+ 4. **Assessment**: State whether assumptions were met or violated
376
+ 5. **Actions taken**: If violated, describe remedial actions (transformations, alternative tests, robust methods)
377
+
378
+ **Example reporting statement**:
379
+ > "Normality was assessed using Shapiro-Wilk tests and Q-Q plots. Data for Group A (W = 0.97, p = .18) and Group B (W = 0.96, p = .12) showed no significant departure from normality. Homogeneity of variance was assessed using Levene's test, which was non-significant (F(1, 58) = 1.23, p = .27), indicating equal variances across groups. Therefore, assumptions for the independent samples t-test were satisfied."