statstudio 0.1.0__py3-none-any.whl

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 (110) hide show
  1. statstudio/__init__.py +9 -0
  2. statstudio/__main__.py +3 -0
  3. statstudio/app.py +83 -0
  4. statstudio/cli.py +116 -0
  5. statstudio/core/__init__.py +3 -0
  6. statstudio/core/archive.py +27 -0
  7. statstudio/core/commands.py +67 -0
  8. statstudio/core/formula_catalog.py +74 -0
  9. statstudio/core/formulas.py +605 -0
  10. statstudio/core/joins.py +123 -0
  11. statstudio/core/project.py +358 -0
  12. statstudio/core/runtime.py +321 -0
  13. statstudio/core/scripting.py +594 -0
  14. statstudio/core/table.py +796 -0
  15. statstudio/core/transform.py +450 -0
  16. statstudio/feature_help.py +595 -0
  17. statstudio/io/__init__.py +3 -0
  18. statstudio/io/docx.py +201 -0
  19. statstudio/io/export.py +99 -0
  20. statstudio/io/file_import.py +199 -0
  21. statstudio/io/odbc.py +334 -0
  22. statstudio/io/sample_data.py +164 -0
  23. statstudio/io/table_io.py +118 -0
  24. statstudio/plots/__init__.py +19 -0
  25. statstudio/plots/advanced.py +651 -0
  26. statstudio/plots/basic.py +957 -0
  27. statstudio/plots/bayesian_plots.py +94 -0
  28. statstudio/plots/common.py +334 -0
  29. statstudio/plots/diagnostics.py +214 -0
  30. statstudio/plots/doe_plots.py +235 -0
  31. statstudio/plots/plotly_builders.py +719 -0
  32. statstudio/plots/predictive_plots.py +72 -0
  33. statstudio/plots/registry.py +251 -0
  34. statstudio/plugins.py +111 -0
  35. statstudio/resources/help_topics.json +13195 -0
  36. statstudio/resources/logo.ico +0 -0
  37. statstudio/resources/logo.png +0 -0
  38. statstudio/resources/statstudio.svg +8 -0
  39. statstudio/stats/__init__.py +42 -0
  40. statstudio/stats/bayesian.py +1094 -0
  41. statstudio/stats/bayesian_optimization.py +590 -0
  42. statstudio/stats/common.py +140 -0
  43. statstudio/stats/correlation.py +135 -0
  44. statstudio/stats/custom_doe.py +1714 -0
  45. statstudio/stats/descriptive.py +200 -0
  46. statstudio/stats/desirability.py +132 -0
  47. statstudio/stats/distributions.py +331 -0
  48. statstudio/stats/doe.py +1070 -0
  49. statstudio/stats/hypothesis.py +1305 -0
  50. statstudio/stats/multivariate.py +307 -0
  51. statstudio/stats/optimal_doe.py +264 -0
  52. statstudio/stats/power.py +194 -0
  53. statstudio/stats/predictive.py +605 -0
  54. statstudio/stats/profiler.py +379 -0
  55. statstudio/stats/quality.py +1218 -0
  56. statstudio/stats/regression.py +1600 -0
  57. statstudio/stats/results.py +235 -0
  58. statstudio/stats/simulator.py +95 -0
  59. statstudio/stats/survival.py +637 -0
  60. statstudio/stats/timeseries.py +643 -0
  61. statstudio/stats/tolerance.py +154 -0
  62. statstudio/ui/__init__.py +0 -0
  63. statstudio/ui/analysis_hub.py +271 -0
  64. statstudio/ui/command_catalog.py +460 -0
  65. statstudio/ui/command_palette.py +55 -0
  66. statstudio/ui/console.py +239 -0
  67. statstudio/ui/dialogs/__init__.py +0 -0
  68. statstudio/ui/dialogs/advanced_dialogs.py +392 -0
  69. statstudio/ui/dialogs/base.py +537 -0
  70. statstudio/ui/dialogs/bayesian_dialogs.py +488 -0
  71. statstudio/ui/dialogs/bayesian_optimization_dialog.py +299 -0
  72. statstudio/ui/dialogs/custom_doe_dialog.py +467 -0
  73. statstudio/ui/dialogs/doe_dialogs.py +220 -0
  74. statstudio/ui/dialogs/extended_dialogs.py +665 -0
  75. statstudio/ui/dialogs/graph_builder.py +139 -0
  76. statstudio/ui/dialogs/help_dialog.py +207 -0
  77. statstudio/ui/dialogs/help_topics.py +280 -0
  78. statstudio/ui/dialogs/lazy.py +184 -0
  79. statstudio/ui/dialogs/odbc_dialog.py +311 -0
  80. statstudio/ui/dialogs/plot_dialog.py +1385 -0
  81. statstudio/ui/dialogs/report_composer.py +218 -0
  82. statstudio/ui/dialogs/script_dialogs.py +267 -0
  83. statstudio/ui/dialogs/stats_dialogs.py +1688 -0
  84. statstudio/ui/dialogs/table_dialogs.py +997 -0
  85. statstudio/ui/dialogs/window.py +58 -0
  86. statstudio/ui/docks/__init__.py +0 -0
  87. statstudio/ui/formula_editor.py +121 -0
  88. statstudio/ui/icons.py +257 -0
  89. statstudio/ui/jobs.py +179 -0
  90. statstudio/ui/main_window.py +3934 -0
  91. statstudio/ui/plot_interaction.py +178 -0
  92. statstudio/ui/profiler_widget.py +437 -0
  93. statstudio/ui/recent.py +82 -0
  94. statstudio/ui/reports/__init__.py +0 -0
  95. statstudio/ui/reports/report_view.py +1632 -0
  96. statstudio/ui/script_jobs.py +35 -0
  97. statstudio/ui/scripts_panel.py +271 -0
  98. statstudio/ui/table_document.py +233 -0
  99. statstudio/ui/table_model.py +285 -0
  100. statstudio/ui/table_view.py +285 -0
  101. statstudio/ui/theme.py +645 -0
  102. statstudio/ui/welcome.py +453 -0
  103. statstudio/ui/window_controls.py +53 -0
  104. statstudio/ui/workers.py +53 -0
  105. statstudio-0.1.0.dist-info/METADATA +261 -0
  106. statstudio-0.1.0.dist-info/RECORD +110 -0
  107. statstudio-0.1.0.dist-info/WHEEL +5 -0
  108. statstudio-0.1.0.dist-info/entry_points.txt +5 -0
  109. statstudio-0.1.0.dist-info/licenses/LICENSE +674 -0
  110. statstudio-0.1.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,665 @@
1
+ from __future__ import annotations
2
+
3
+ import pandas as pd
4
+
5
+ from statstudio.core.table import DataTable
6
+ from statstudio.stats import distributions, hypothesis, predictive, quality, survival, timeseries
7
+ from statstudio.stats.results import AnalysisResult
8
+ from statstudio.ui.dialogs.base import BaseDialog, combo_value, text_value
9
+ from statstudio.ui.dialogs.stats_dialogs import (
10
+ all_columns,
11
+ binary_columns,
12
+ categorical_columns,
13
+ first_categorical,
14
+ low_cardinality_columns,
15
+ numeric_columns,
16
+ preferred_categorical,
17
+ )
18
+
19
+
20
+ def _parse_int_list(text: str) -> list[int]:
21
+ values = []
22
+ for part in text.replace(";", ",").split(","):
23
+ part = part.strip()
24
+ if not part:
25
+ continue
26
+ try:
27
+ values.append(int(float(part)))
28
+ except ValueError:
29
+ raise ValueError(f"Invalid index: {part!r}")
30
+ return values
31
+
32
+
33
+ class FitYByXDialog(BaseDialog):
34
+ def __init__(self, table: DataTable, parent=None) -> None:
35
+ super().__init__(table, "Simple", parent)
36
+ numeric = numeric_columns(table)
37
+ self.response_combo = self.add_combo("Y (response)", numeric, default=numeric[0] if numeric else None)
38
+ self.factor_combo = self.add_combo("X (factor or covariate)", all_columns(table), default=first_categorical(table))
39
+ self.robust_check = self.add_bool("Robust standard errors (HC3, regression only)", False)
40
+
41
+ def compute(self) -> AnalysisResult:
42
+ return self.finish(
43
+ hypothesis.fit_y_by_x(
44
+ self.df,
45
+ combo_value(self.response_combo) or "",
46
+ combo_value(self.factor_combo) or "",
47
+ self.robust_check.isChecked(),
48
+ )
49
+ )
50
+
51
+
52
+ class TwoWayANOVADialog(BaseDialog):
53
+ def __init__(self, table: DataTable, parent=None) -> None:
54
+ super().__init__(table, "Two-Way ANOVA", parent)
55
+ numeric = numeric_columns(table)
56
+ categorical = low_cardinality_columns(table) or categorical_columns(table) or all_columns(table)
57
+ self.response_combo = self.add_combo("Response", numeric, default=numeric[0] if numeric else None)
58
+ self.factor1_combo = self.add_combo("Factor 1", categorical, default=categorical[0] if categorical else None)
59
+ self.factor2_combo = self.add_combo("Factor 2", categorical, default=categorical[1] if len(categorical) > 1 else None)
60
+ if len(categorical) < 2:
61
+ self.factor2_combo.setCurrentIndex(-1)
62
+ self.interaction_check = self.add_bool("Include interaction", True)
63
+ self.ss_combo = self.add_combo("Sums of squares", ["Type II", "Type III", "Type I"], default="Type II")
64
+
65
+ def apply_params(self, params: dict | None) -> None:
66
+ params = dict(params or {})
67
+ ss_type = params.pop("ss_type", None)
68
+ if ss_type is not None:
69
+ self.ss_combo.setCurrentText({1: "Type I", 2: "Type II", 3: "Type III"}.get(int(ss_type), "Type II"))
70
+ super().apply_params(params)
71
+
72
+ def compute(self) -> AnalysisResult:
73
+ factor2 = combo_value(self.factor2_combo)
74
+ if not factor2:
75
+ raise ValueError("Choose a second factor.")
76
+ return self.finish(
77
+ hypothesis.two_way_anova(
78
+ self.df,
79
+ combo_value(self.response_combo) or "",
80
+ combo_value(self.factor1_combo) or "",
81
+ factor2,
82
+ self.interaction_check.isChecked(),
83
+ {"Type I": 1, "Type II": 2, "Type III": 3}.get(combo_value(self.ss_combo) or "Type II", 2),
84
+ )
85
+ )
86
+
87
+
88
+ class ContingencyDialog(BaseDialog):
89
+ def __init__(self, table: DataTable, parent=None) -> None:
90
+ super().__init__(table, "Contingency Analysis", parent)
91
+ categorical = low_cardinality_columns(table) or categorical_columns(table) or all_columns(table)
92
+ self.row_combo = self.add_combo("Row variable", all_columns(table), default=categorical[0] if categorical else None)
93
+ self.column_combo = self.add_combo("Column variable", all_columns(table), default=categorical[1] if len(categorical) > 1 else None)
94
+ if len(categorical) < 2:
95
+ self.column_combo.setCurrentIndex(-1)
96
+
97
+ def compute(self) -> AnalysisResult:
98
+ column = combo_value(self.column_combo)
99
+ if not column:
100
+ raise ValueError("Choose a second (column) variable.")
101
+ return self.finish(
102
+ hypothesis.contingency_table(
103
+ self.df,
104
+ combo_value(self.row_combo) or "",
105
+ column,
106
+ )
107
+ )
108
+
109
+
110
+ class PostHocDialog(BaseDialog):
111
+ def __init__(self, table: DataTable, parent=None) -> None:
112
+ super().__init__(table, "Post-Hoc Comparisons", parent)
113
+ numeric = numeric_columns(table)
114
+ self.response_combo = self.add_combo("Response", numeric, default=numeric[0] if numeric else None)
115
+ self.factor_combo = self.add_combo("Factor", all_columns(table), default=preferred_categorical(table))
116
+ self.method_combo = self.add_combo(
117
+ "Method",
118
+ [
119
+ "Tukey HSD",
120
+ "Bonferroni",
121
+ "Dunnett (vs control)",
122
+ "Hsu MCB",
123
+ "Games-Howell",
124
+ "Tamhane T2",
125
+ "Fisher LSD",
126
+ "Newman-Keuls",
127
+ "Steel-Dwass",
128
+ "Dunn",
129
+ ],
130
+ default="Tukey HSD",
131
+ )
132
+ self.alpha_spin = self.add_float("Alpha", 0.05, 0.0001, 0.5, 4)
133
+ self.control_combo = self.add_combo("Control level (Dunnett)", [], allow_none=True)
134
+ self.factor_combo.currentTextChanged.connect(self._refresh_control_levels)
135
+ self._refresh_control_levels()
136
+
137
+ def apply_params(self, params: dict | None) -> None:
138
+ params = dict(params or {})
139
+ method = params.pop("method", None)
140
+ labels = {
141
+ "tukey": "Tukey HSD",
142
+ "bonferroni": "Bonferroni",
143
+ "dunnett": "Dunnett (vs control)",
144
+ "hsu": "Hsu MCB",
145
+ "games-howell": "Games-Howell",
146
+ "tamhane": "Tamhane T2",
147
+ "fisher-lsd": "Fisher LSD",
148
+ "newman-keuls": "Newman-Keuls",
149
+ "steel-dwass": "Steel-Dwass",
150
+ "dunn": "Dunn",
151
+ }
152
+ if method:
153
+ self.method_combo.setCurrentText(labels.get(str(method).lower(), str(method)))
154
+ super().apply_params(params)
155
+ self._refresh_control_levels()
156
+
157
+ def _refresh_control_levels(self) -> None:
158
+ factor = combo_value(self.factor_combo)
159
+ self.control_combo.blockSignals(True)
160
+ self.control_combo.clear()
161
+ self.control_combo.addItem("(none)", None)
162
+ if factor and factor in self.df.columns:
163
+ for level in sorted(pd.unique(self.df[factor].dropna()).tolist(), key=str):
164
+ self.control_combo.addItem(str(level), str(level))
165
+ self.control_combo.blockSignals(False)
166
+
167
+ def compute(self) -> AnalysisResult:
168
+ method = {
169
+ "Tukey HSD": "tukey",
170
+ "Bonferroni": "bonferroni",
171
+ "Dunnett (vs control)": "dunnett",
172
+ "Hsu MCB": "hsu",
173
+ "Games-Howell": "games-howell",
174
+ "Tamhane T2": "tamhane",
175
+ "Fisher LSD": "fisher-lsd",
176
+ "Newman-Keuls": "newman-keuls",
177
+ "Steel-Dwass": "steel-dwass",
178
+ "Dunn": "dunn",
179
+ }.get(combo_value(self.method_combo) or "", "tukey")
180
+ factor = combo_value(self.factor_combo) or ""
181
+ control = combo_value(self.control_combo)
182
+ if method == "dunnett" and not control:
183
+ levels = sorted(pd.unique(self.df[factor].dropna()).tolist(), key=str) if factor in self.df.columns else []
184
+ control = str(levels[0]) if levels else None
185
+ return self.finish(
186
+ hypothesis.posthoc_test(self.df, combo_value(self.response_combo) or "", factor, method, control, self.alpha_spin.value())
187
+ )
188
+
189
+
190
+ class DistributionSummaryDialog(BaseDialog):
191
+ def __init__(self, table: DataTable, parent=None) -> None:
192
+ super().__init__(table, "Distribution Summary", parent)
193
+ numeric = numeric_columns(table)
194
+ self.columns = self.add_multi("Variables", numeric, numeric[: min(4, len(numeric))])
195
+ self.group_combo = self.add_combo("Group by", all_columns(table), allow_none=True)
196
+ self.ci_spin = self.add_float("Confidence level (%)", 95.0, 50.0, 99.9, 2)
197
+
198
+ def apply_params(self, params: dict | None) -> None:
199
+ params = dict(params or {})
200
+ if params.get("ci_width") is not None:
201
+ self.ci_spin.setValue(float(params.pop("ci_width")))
202
+ super().apply_params(params)
203
+
204
+ def compute(self) -> AnalysisResult:
205
+ return self.finish(
206
+ distributions.distribution_summary(
207
+ self.df,
208
+ self.columns.checked_items(),
209
+ combo_value(self.group_combo),
210
+ self.ci_spin.value(),
211
+ )
212
+ )
213
+
214
+
215
+ class PredictiveDialog(BaseDialog):
216
+ def __init__(self, table: DataTable, parent=None) -> None:
217
+ super().__init__(table, "Predictive Modeling", parent)
218
+ self.type_combo = self.add_combo(
219
+ "Model",
220
+ ["CART", "Random Forest", "Neural Network", "SVM", "Naive Bayes", "XGBoost", "Auto Model"],
221
+ default="CART",
222
+ )
223
+ numeric = numeric_columns(table)
224
+ self.response_combo = self.add_combo("Response", all_columns(table), default=numeric[-1] if numeric else None)
225
+ self.predictors = self.add_multi("Predictors", [c for c in all_columns(table)], numeric[: min(4, len(numeric))])
226
+ self.predictors.setMaximumHeight(130)
227
+ self.criterion_combo = self.add_combo("Criterion", ["Auto", "Regression", "Classification"], default="Auto")
228
+ self.validation_spin = self.add_float("Validation holdout (%)", 20.0, 0.0, 50.0, 1)
229
+ self.seed_spin = self.add_int("Random seed", 42, 0, 2_000_000_000)
230
+ self.depth_spin = self.add_int("Max tree depth", 6, 1, 50)
231
+ self.leaf_spin = self.add_int("Min samples per leaf", 1, 1, 1000)
232
+ self.trees_spin = self.add_int("Trees (forest)", 100, 10, 5000)
233
+ self.hidden_spin = self.add_int("Hidden units (neural)", 10, 1, 200)
234
+ self.rounds_spin = self.add_int("Boosting rounds", 100, 10, 5000)
235
+ self.lr_spin = self.add_float("Learning rate", 0.1, 0.001, 1.0, 4)
236
+ self.folds_spin = self.add_int("CV folds (Auto Model)", 5, 2, 20)
237
+ self.type_combo.currentTextChanged.connect(self._update_model_controls)
238
+ self._update_model_controls()
239
+
240
+ def _set_visible(self, widget, visible: bool) -> None:
241
+ self._form.setRowVisible(widget, visible)
242
+
243
+ def _update_model_controls(self, *_args) -> None:
244
+ model = combo_value(self.type_combo) or "CART"
245
+ visible = {
246
+ "CART": {"criterion_combo", "depth_spin", "leaf_spin"},
247
+ "Random Forest": {"criterion_combo", "leaf_spin", "trees_spin"},
248
+ "Neural Network": {"criterion_combo", "hidden_spin"},
249
+ "SVM": {"criterion_combo"},
250
+ "Naive Bayes": set(),
251
+ "XGBoost": {"criterion_combo", "depth_spin", "rounds_spin", "lr_spin"},
252
+ "Auto Model": {
253
+ "criterion_combo",
254
+ "depth_spin",
255
+ "leaf_spin",
256
+ "trees_spin",
257
+ "hidden_spin",
258
+ "rounds_spin",
259
+ "lr_spin",
260
+ "folds_spin",
261
+ },
262
+ }.get(model, set())
263
+ widgets = {
264
+ "criterion_combo": self.criterion_combo,
265
+ "depth_spin": self.depth_spin,
266
+ "leaf_spin": self.leaf_spin,
267
+ "trees_spin": self.trees_spin,
268
+ "hidden_spin": self.hidden_spin,
269
+ "rounds_spin": self.rounds_spin,
270
+ "lr_spin": self.lr_spin,
271
+ "folds_spin": self.folds_spin,
272
+ }
273
+ for name, widget in widgets.items():
274
+ self._set_visible(widget, name in visible)
275
+
276
+ def apply_params(self, params: dict | None) -> None:
277
+ params = dict(params or {})
278
+ criterion = params.pop("criterion", None)
279
+ if criterion:
280
+ self.criterion_combo.setCurrentText({"auto": "Auto", "regression": "Regression", "classification": "Classification"}.get(str(criterion).lower(), str(criterion).title()))
281
+ aliases = {
282
+ "max_depth": self.depth_spin,
283
+ "rf_trees": self.trees_spin,
284
+ "rf_min_leaf": self.leaf_spin,
285
+ "rounds": self.rounds_spin,
286
+ "learning_rate": self.lr_spin,
287
+ "hidden": self.hidden_spin,
288
+ "folds": self.folds_spin,
289
+ "validation": self.validation_spin,
290
+ }
291
+ for key, widget in aliases.items():
292
+ if params.get(key) is not None:
293
+ widget.setValue(params.pop(key))
294
+ super().apply_params(params)
295
+ self._update_model_controls()
296
+
297
+ def apply_kind(self, kind: str) -> None:
298
+ label = {
299
+ "cart": "CART",
300
+ "random_forest": "Random Forest",
301
+ "neural": "Neural Network",
302
+ "svm": "SVM",
303
+ "naive_bayes": "Naive Bayes",
304
+ "xgboost": "XGBoost",
305
+ "automl": "Auto Model",
306
+ }.get(kind)
307
+ if label:
308
+ self.type_combo.setCurrentText(label)
309
+
310
+ def _request(self):
311
+ response = combo_value(self.response_combo) or ""
312
+ predictors = [p for p in self.predictors.checked_items() if p != response]
313
+ criterion = {"Auto": "auto", "Regression": "regression", "Classification": "classification"}.get(combo_value(self.criterion_combo) or "Auto", "auto")
314
+ return {
315
+ "df": self.df,
316
+ "response": response,
317
+ "predictors": predictors,
318
+ "criterion": criterion,
319
+ "validation": self.validation_spin.value(),
320
+ "seed": self.seed_spin.value(),
321
+ "kind": combo_value(self.type_combo),
322
+ "max_depth": self.depth_spin.value(),
323
+ "leaf": self.leaf_spin.value(),
324
+ "trees": self.trees_spin.value(),
325
+ "hidden": self.hidden_spin.value(),
326
+ "rounds": self.rounds_spin.value(),
327
+ "learning_rate": self.lr_spin.value(),
328
+ "folds": self.folds_spin.value(),
329
+ }
330
+
331
+ @staticmethod
332
+ def _run_request(values):
333
+ df = values["df"]
334
+ response = values["response"]
335
+ predictors = values["predictors"]
336
+ criterion = values["criterion"]
337
+ validation = values["validation"]
338
+ seed = values["seed"]
339
+ kind = values["kind"]
340
+ if kind == "CART":
341
+ return predictive.cart(df, response, predictors, criterion, values["max_depth"], values["leaf"], 0.0, validation, seed)
342
+ if kind == "Random Forest":
343
+ return predictive.random_forest(df, response, predictors, criterion, values["trees"], None, values["leaf"], validation, seed)
344
+ if kind == "Neural Network":
345
+ return predictive.neural_network(df, response, predictors, criterion, values["hidden"], 0.0001, 500, validation, seed)
346
+ if kind == "SVM":
347
+ return predictive.svm_model(df, response, predictors, criterion, 1.0, "scale", validation, seed)
348
+ if kind == "Naive Bayes":
349
+ return predictive.naive_bayes(df, response, predictors, "classification", validation, seed)
350
+ if kind == "XGBoost":
351
+ return predictive.xgboost_model(df, response, predictors, criterion, values["rounds"], values["max_depth"], values["learning_rate"], 1.0, 1.0, 1.0, 1.0, 0.0, validation, seed)
352
+ return predictive.automl(
353
+ df,
354
+ response,
355
+ predictors,
356
+ criterion,
357
+ validation,
358
+ values["folds"],
359
+ seed,
360
+ values["max_depth"],
361
+ 0.0,
362
+ values["trees"],
363
+ None,
364
+ values["leaf"],
365
+ values["rounds"],
366
+ values["max_depth"],
367
+ values["learning_rate"],
368
+ values["hidden"],
369
+ 0.0001,
370
+ 500,
371
+ )
372
+
373
+ def make_job(self):
374
+ values = self._request()
375
+ return lambda token, progress: self._run_request(values)
376
+
377
+ def compute(self) -> AnalysisResult:
378
+ return self.finish(self._run_request(self._request()))
379
+
380
+
381
+ class GageRRDialog(BaseDialog):
382
+ def __init__(self, table: DataTable, parent=None) -> None:
383
+ super().__init__(table, "Gage R&R", parent)
384
+ numeric = numeric_columns(table)
385
+ self.measure_combo = self.add_combo("Measurement", numeric, default=numeric[0] if numeric else None)
386
+ low_card = low_cardinality_columns(table)
387
+ self.part_combo = self.add_combo("Part", all_columns(table), default=low_card[0] if low_card else None)
388
+ self.operator_combo = self.add_combo("Operator", all_columns(table), default=low_card[1] if len(low_card) > 1 else None)
389
+ self.batch_combo = self.add_combo("Batch (expanded design)", all_columns(table), allow_none=True, default=low_card[2] if len(low_card) > 2 else None)
390
+ self.design_combo = self.add_combo("Design", ["Crossed", "Nested", "Expanded"], default="Crossed")
391
+ self.interaction_check = self.add_bool("Include part x operator interaction", True)
392
+ self.tolerance_edit = self.add_text("Tolerance (optional)", "")
393
+
394
+ def compute(self) -> AnalysisResult:
395
+ return self.finish(
396
+ quality.gage_rr(
397
+ self.df,
398
+ combo_value(self.measure_combo) or "",
399
+ combo_value(self.part_combo) or "",
400
+ combo_value(self.operator_combo) or "",
401
+ (combo_value(self.design_combo) or "crossed").lower(),
402
+ self.interaction_check.isChecked(),
403
+ combo_value(self.batch_combo),
404
+ float(text_value(self.tolerance_edit)) if text_value(self.tolerance_edit) else None,
405
+ )
406
+ )
407
+
408
+
409
+ class CompetingRiskDialog(BaseDialog):
410
+ def __init__(self, table: DataTable, parent=None) -> None:
411
+ super().__init__(table, "Competing Risks", parent)
412
+ numeric = numeric_columns(table)
413
+ self.time_combo = self.add_combo("Time", numeric, default=numeric[0] if numeric else None)
414
+ binaries = binary_columns(table)
415
+ self.event_combo = self.add_combo("Event code column", all_columns(table), default=binaries[0] if binaries else None)
416
+ self.event_value_edit = self.add_text("Event of interest value", "1")
417
+ self.competing_value_edit = self.add_text("Competing event value", "2")
418
+ self.group_combo = self.add_combo("Group (optional)", all_columns(table), allow_none=True)
419
+
420
+ def compute(self) -> AnalysisResult:
421
+ return self.finish(
422
+ survival.cumulative_incidence(
423
+ self.df,
424
+ combo_value(self.time_combo) or "",
425
+ combo_value(self.event_combo) or "",
426
+ text_value(self.event_value_edit) or None,
427
+ text_value(self.competing_value_edit) or None,
428
+ combo_value(self.group_combo),
429
+ )
430
+ )
431
+
432
+
433
+ class ReliabilityDialog(BaseDialog):
434
+ def __init__(self, table: DataTable, parent=None) -> None:
435
+ super().__init__(table, "Reliability / Weibull", parent)
436
+ numeric = numeric_columns(table)
437
+ self.time_combo = self.add_combo("Time", numeric, default=numeric[0] if numeric else None)
438
+ binaries = binary_columns(table)
439
+ self.event_combo = self.add_combo("Event / censor", all_columns(table), default=binaries[0] if binaries else None)
440
+ self.event_value_edit = self.add_text("Event value (blank = auto)", "")
441
+ self.dist_combo = self.add_combo("Distribution", ["Weibull", "Exponential", "Lognormal", "Loglogistic"], default="Weibull")
442
+ self.predictors = self.add_multi("Accelerating covariates", all_columns(table), [])
443
+ self.predictors.setMaximumHeight(110)
444
+
445
+ def apply_params(self, params: dict | None) -> None:
446
+ params = dict(params or {})
447
+ distribution = params.pop("distribution", None)
448
+ if distribution:
449
+ self.dist_combo.setCurrentText(str(distribution).title())
450
+ super().apply_params(params)
451
+
452
+ def make_job(self):
453
+ df = self.df
454
+ time = combo_value(self.time_combo) or ""
455
+ event = combo_value(self.event_combo) or ""
456
+ predictors = [p for p in self.predictors.checked_items() if p not in {time, event}]
457
+ distribution = (combo_value(self.dist_combo) or "weibull").lower()
458
+ event_value = text_value(self.event_value_edit) or None
459
+ return lambda token, progress: survival.weibull_aft(df, time, event, predictors, distribution, event_value)
460
+
461
+ def compute(self) -> AnalysisResult:
462
+ return self.finish(
463
+ survival.weibull_aft(
464
+ self.df,
465
+ combo_value(self.time_combo) or "",
466
+ combo_value(self.event_combo) or "",
467
+ self.predictors.checked_items(),
468
+ (combo_value(self.dist_combo) or "weibull").lower(),
469
+ text_value(self.event_value_edit) or None,
470
+ )
471
+ )
472
+
473
+
474
+ class ZeroFailureReliabilityDialog(BaseDialog):
475
+ def __init__(self, table: DataTable, parent=None) -> None:
476
+ super().__init__(table, "Reliability with Zero Failures", parent)
477
+ self.add_label("Reliability demonstration with zero observed failures.")
478
+ self.test_time_spin = self.add_float("Test time per unit", 100.0, 0.0001, 1e12, 4)
479
+ self.units_spin = self.add_int("Units tested", 1, 1, 1_000_000)
480
+ self.confidence_spin = self.add_float("Confidence (%)", 95.0, 50.0, 99.999, 3)
481
+ self.shape_spin = self.add_float("Weibull shape", 1.0, 0.0001, 1000.0, 4)
482
+
483
+ def apply_params(self, params: dict | None) -> None:
484
+ params = dict(params or {})
485
+ if params.get("confidence") is not None:
486
+ self.confidence_spin.setValue(float(params.pop("confidence")) * 100.0)
487
+ super().apply_params(params)
488
+
489
+ def compute(self) -> AnalysisResult:
490
+ return self.finish(
491
+ survival.reliability_zero_failures(
492
+ self.test_time_spin.value(),
493
+ self.units_spin.value(),
494
+ self.confidence_spin.value() / 100.0,
495
+ self.shape_spin.value(),
496
+ )
497
+ )
498
+
499
+
500
+ class ForecastDialog(BaseDialog):
501
+ def __init__(self, table: DataTable, parent=None) -> None:
502
+ super().__init__(table, "Forecast", parent)
503
+ self.column_combo = self.add_combo("Series", numeric_columns(table))
504
+ self.method_combo = self.add_combo(
505
+ "Method",
506
+ ["Auto (ETS)", "ARIMA", "Manual ARIMA", "STL", "Seasonal naive", "Naive", "Mean", "Drift"],
507
+ default="Auto (ETS)",
508
+ )
509
+ self.period_spin = self.add_int("Seasonal period", 12, 0, 1000)
510
+ self.horizon_spin = self.add_int("Horizon", 12, 1, 1000)
511
+ self.level_spin = self.add_float("Confidence level (%)", 95.0, 50.0, 99.9, 2)
512
+ self.p_spin = self.add_int("p", 1, 0, 10)
513
+ self.d_spin = self.add_int("d", 0, 0, 3)
514
+ self.q_spin = self.add_int("q", 0, 0, 10)
515
+ self.sp_spin = self.add_int("Seasonal P", 0, 0, 5)
516
+ self.sd_spin = self.add_int("Seasonal D", 0, 0, 2)
517
+ self.sq_spin = self.add_int("Seasonal Q", 0, 0, 5)
518
+ self.seasonal_period_spin = self.add_int("Seasonal period (SARIMA)", 0, 0, 365)
519
+ self.term_combo = self.add_combo("ARIMA term", ["none", "constant", "trend", "constant+trend"], default="none")
520
+ self.backtest_spin = self.add_int("Backtest windows", 0, 0, 50)
521
+ self.pulse_edit = self.add_text("Pulse interventions (indices, comma separated)", "")
522
+ self.step_edit = self.add_text("Step interventions (indices, comma separated)", "")
523
+ self.robust_check = self.add_bool("Robust STL", False)
524
+
525
+ def apply_kind(self, kind: str) -> None:
526
+ label = {
527
+ "forecast": "Auto (ETS)",
528
+ "arima": "ARIMA",
529
+ "exponential_smoothing": "Auto (ETS)",
530
+ }.get(kind)
531
+ if label:
532
+ self.method_combo.setCurrentText(label)
533
+
534
+ def apply_params(self, params: dict | None) -> None:
535
+ params = dict(params or {})
536
+ method = params.get("method")
537
+ label = {
538
+ "auto": "Auto (ETS)",
539
+ "arima": "ARIMA",
540
+ "manual": "Manual ARIMA",
541
+ "stl": "STL",
542
+ "snaive": "Seasonal naive",
543
+ "naive": "Naive",
544
+ "mean": "Mean",
545
+ "drift": "Drift",
546
+ }.get(method or "")
547
+ if label:
548
+ self.method_combo.setCurrentText(label)
549
+ order = params.get("order")
550
+ if order and len(order) >= 3:
551
+ self.p_spin.setValue(int(order[0]))
552
+ self.d_spin.setValue(int(order[1]))
553
+ self.q_spin.setValue(int(order[2]))
554
+ seasonal_order = params.get("seasonal_order")
555
+ if seasonal_order and len(seasonal_order) >= 4:
556
+ self.sp_spin.setValue(int(seasonal_order[0]))
557
+ self.sd_spin.setValue(int(seasonal_order[1]))
558
+ self.sq_spin.setValue(int(seasonal_order[2]))
559
+ self.seasonal_period_spin.setValue(int(seasonal_order[3]))
560
+ manual_term = params.get("manual_term")
561
+ if manual_term:
562
+ label = {"none": "none", "c": "constant", "t": "trend", "ct": "constant+trend"}.get(manual_term)
563
+ if label:
564
+ self.term_combo.setCurrentText(label)
565
+ super().apply_params(params)
566
+
567
+ def make_job(self):
568
+ method = {
569
+ "Auto (ETS)": "auto",
570
+ "ARIMA": "arima",
571
+ "Manual ARIMA": "manual",
572
+ "STL": "stl",
573
+ "Seasonal naive": "snaive",
574
+ "Naive": "naive",
575
+ "Mean": "mean",
576
+ "Drift": "drift",
577
+ }.get(combo_value(self.method_combo) or "Auto (ETS)", "auto")
578
+ term = {"none": "none", "constant": "c", "trend": "t", "constant+trend": "ct"}.get(combo_value(self.term_combo) or "none", "none")
579
+ seasonal = None
580
+ if self.seasonal_period_spin.value() > 0:
581
+ seasonal = (self.sp_spin.value(), self.sd_spin.value(), self.sq_spin.value(), self.seasonal_period_spin.value())
582
+ values = {
583
+ "df": self.df,
584
+ "column": combo_value(self.column_combo) or "",
585
+ "method": method,
586
+ "period": self.period_spin.value() or None,
587
+ "horizon": self.horizon_spin.value(),
588
+ "level": self.level_spin.value(),
589
+ "order": (self.p_spin.value(), self.d_spin.value(), self.q_spin.value()),
590
+ "seasonal_order": seasonal,
591
+ "manual_term": term,
592
+ "backtest": self.backtest_spin.value(),
593
+ "pulse": _parse_int_list(text_value(self.pulse_edit)),
594
+ "step": _parse_int_list(text_value(self.step_edit)),
595
+ "robust": self.robust_check.isChecked(),
596
+ }
597
+ return lambda token, progress: timeseries.forecast(
598
+ values["df"],
599
+ values["column"],
600
+ method=values["method"],
601
+ period=values["period"],
602
+ horizon=values["horizon"],
603
+ level=values["level"],
604
+ order=values["order"],
605
+ seasonal_order=values["seasonal_order"],
606
+ manual_term=values["manual_term"],
607
+ backtest=values["backtest"],
608
+ pulse=values["pulse"],
609
+ step=values["step"],
610
+ robust=values["robust"],
611
+ )
612
+
613
+ def compute(self) -> AnalysisResult:
614
+ method = {
615
+ "Auto (ETS)": "auto",
616
+ "ARIMA": "arima",
617
+ "Manual ARIMA": "manual",
618
+ "STL": "stl",
619
+ "Seasonal naive": "snaive",
620
+ "Naive": "naive",
621
+ "Mean": "mean",
622
+ "Drift": "drift",
623
+ }.get(combo_value(self.method_combo) or "Auto (ETS)", "auto")
624
+ term = {"none": "none", "constant": "c", "trend": "t", "constant+trend": "ct"}.get(combo_value(self.term_combo) or "none", "none")
625
+ seasonal = None
626
+ if self.seasonal_period_spin.value() > 0:
627
+ seasonal = (self.sp_spin.value(), self.sd_spin.value(), self.sq_spin.value(), self.seasonal_period_spin.value())
628
+ period = self.period_spin.value() or None
629
+ return self.finish(
630
+ timeseries.forecast(
631
+ self.df,
632
+ combo_value(self.column_combo) or "",
633
+ method=method,
634
+ period=period,
635
+ horizon=self.horizon_spin.value(),
636
+ level=self.level_spin.value(),
637
+ order=(self.p_spin.value(), self.d_spin.value(), self.q_spin.value()),
638
+ seasonal_order=seasonal,
639
+ manual_term=term,
640
+ backtest=self.backtest_spin.value(),
641
+ pulse=_parse_int_list(text_value(self.pulse_edit)),
642
+ step=_parse_int_list(text_value(self.step_edit)),
643
+ robust=self.robust_check.isChecked(),
644
+ )
645
+ )
646
+
647
+
648
+ class STLDialog(BaseDialog):
649
+ def __init__(self, table: DataTable, parent=None) -> None:
650
+ super().__init__(table, "STL Decomposition", parent)
651
+ self.column_combo = self.add_combo("Series", numeric_columns(table))
652
+ self.period_spin = self.add_int("Period", 12, 2, 1000)
653
+ self.seasonal_spin = self.add_int("Seasonal smoother", 7, 3, 101)
654
+ self.robust_check = self.add_bool("Robust", False)
655
+
656
+ def compute(self) -> AnalysisResult:
657
+ return self.finish(
658
+ timeseries.stl_decomposition(
659
+ self.df,
660
+ combo_value(self.column_combo) or "",
661
+ self.period_spin.value(),
662
+ self.seasonal_spin.value(),
663
+ self.robust_check.isChecked(),
664
+ )
665
+ )