staplot 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.
- staplot/__init__.py +1 -0
- staplot/api.py +441 -0
- staplot/main.py +21 -0
- staplot/models/__init__.py +1 -0
- staplot/models/project.py +461 -0
- staplot/plots/__init__.py +14 -0
- staplot/plots/bar.py +104 -0
- staplot/plots/before_after.py +110 -0
- staplot/plots/bland_altman.py +73 -0
- staplot/plots/box.py +95 -0
- staplot/plots/distribution_plot.py +188 -0
- staplot/plots/grouped_bar.py +112 -0
- staplot/plots/heatmap.py +73 -0
- staplot/plots/histogram.py +76 -0
- staplot/plots/qq.py +61 -0
- staplot/plots/residuals.py +72 -0
- staplot/plots/roc_plot.py +40 -0
- staplot/plots/scatter.py +61 -0
- staplot/plots/significance.py +94 -0
- staplot/plots/styles.py +154 -0
- staplot/plots/survival.py +78 -0
- staplot/plots/volcano.py +110 -0
- staplot/stats/__init__.py +15 -0
- staplot/stats/anova.py +124 -0
- staplot/stats/chi_square.py +85 -0
- staplot/stats/correlation.py +71 -0
- staplot/stats/curve_fit.py +85 -0
- staplot/stats/descriptive.py +52 -0
- staplot/stats/distribution.py +223 -0
- staplot/stats/multiple_comparisons.py +104 -0
- staplot/stats/normality.py +67 -0
- staplot/stats/outliers.py +62 -0
- staplot/stats/power.py +130 -0
- staplot/stats/regression.py +95 -0
- staplot/stats/repeated_measures.py +114 -0
- staplot/stats/roc.py +196 -0
- staplot/stats/tests.py +142 -0
- staplot/stats/two_way_anova.py +88 -0
- staplot/ui/__init__.py +0 -0
- staplot/ui/analysis_dialog.py +406 -0
- staplot/ui/axis_dialog.py +104 -0
- staplot/ui/computed_column_dialog.py +261 -0
- staplot/ui/contingency_table_widget.py +158 -0
- staplot/ui/data_table_widget.py +277 -0
- staplot/ui/distribution_inspector.py +431 -0
- staplot/ui/figure_layout_widget.py +236 -0
- staplot/ui/graph_gallery.py +117 -0
- staplot/ui/graph_options_dialog.py +325 -0
- staplot/ui/grouped_table_widget.py +190 -0
- staplot/ui/layout_dialog.py +218 -0
- staplot/ui/main_window.py +1126 -0
- staplot/ui/multiple_comparisons_dialog.py +168 -0
- staplot/ui/navigator.py +88 -0
- staplot/ui/plot_canvas.py +251 -0
- staplot/ui/power_dialog.py +108 -0
- staplot/ui/report_dialog.py +255 -0
- staplot/ui/reshape_dialog.py +286 -0
- staplot/ui/results_widget.py +19 -0
- staplot/ui/standard_curve_dialog.py +150 -0
- staplot/ui/test_wizard.py +252 -0
- staplot/ui/transform_dialog.py +137 -0
- staplot/ui/undo_commands.py +86 -0
- staplot-0.1.0.dist-info/METADATA +85 -0
- staplot-0.1.0.dist-info/RECORD +68 -0
- staplot-0.1.0.dist-info/WHEEL +5 -0
- staplot-0.1.0.dist-info/entry_points.txt +2 -0
- staplot-0.1.0.dist-info/licenses/LICENSE +24 -0
- staplot-0.1.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
from qtpy.QtWidgets import (
|
|
2
|
+
QDialog, QVBoxLayout, QHBoxLayout, QFormLayout, QGroupBox,
|
|
3
|
+
QComboBox, QCheckBox, QPushButton, QTextEdit, QLabel,
|
|
4
|
+
QDialogButtonBox, QTabWidget, QWidget, QDoubleSpinBox, QSpinBox,
|
|
5
|
+
QStackedWidget, QListWidget, QAbstractItemView,
|
|
6
|
+
)
|
|
7
|
+
from qtpy.QtCore import Qt
|
|
8
|
+
from qtpy.QtGui import QFont
|
|
9
|
+
|
|
10
|
+
from ..models.project import DataTable, GroupedDataTable, ContingencyTable, AnalysisResult
|
|
11
|
+
from .. import stats as stat_lib
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class AnalysisDialog(QDialog):
|
|
15
|
+
"""Unified dialog for running all supported statistical tests."""
|
|
16
|
+
|
|
17
|
+
_TABS = [
|
|
18
|
+
"t-test / Wilcoxon", # 0
|
|
19
|
+
"ANOVA / Kruskal-Wallis", # 1
|
|
20
|
+
"Two-Way ANOVA", # 2
|
|
21
|
+
"Correlation", # 3
|
|
22
|
+
"Normality", # 4
|
|
23
|
+
"Curve Fitting", # 5
|
|
24
|
+
"Descriptive", # 6
|
|
25
|
+
"Chi-square / Fisher", # 7
|
|
26
|
+
"RM ANOVA / Friedman", # 8
|
|
27
|
+
"Outliers (Grubbs)", # 9
|
|
28
|
+
"ROC Curve", # 10
|
|
29
|
+
"Multiple Regression", # 11
|
|
30
|
+
]
|
|
31
|
+
|
|
32
|
+
def __init__(self, tables: list, parent=None, initial_tab: int = 0):
|
|
33
|
+
super().__init__(parent)
|
|
34
|
+
self.setWindowTitle("Statistical Analysis")
|
|
35
|
+
self.setMinimumSize(600, 600)
|
|
36
|
+
self._tables = tables
|
|
37
|
+
self._result: AnalysisResult | None = None
|
|
38
|
+
|
|
39
|
+
layout = QVBoxLayout(self)
|
|
40
|
+
|
|
41
|
+
# Table selector (for non-contingency tests)
|
|
42
|
+
top = QFormLayout()
|
|
43
|
+
self._table_cb = QComboBox()
|
|
44
|
+
col_tables = [t for t in tables if hasattr(t, "columns")]
|
|
45
|
+
self._table_cb.addItems([t.name for t in col_tables])
|
|
46
|
+
self._col_tables = col_tables
|
|
47
|
+
self._table_cb.currentIndexChanged.connect(self._refresh_groups)
|
|
48
|
+
top.addRow("Table:", self._table_cb)
|
|
49
|
+
layout.addLayout(top)
|
|
50
|
+
|
|
51
|
+
# Test tabs
|
|
52
|
+
self._tabs = QTabWidget()
|
|
53
|
+
self._tabs.addTab(self._build_ttest_tab(), self._TABS[0])
|
|
54
|
+
self._tabs.addTab(self._build_anova_tab(), self._TABS[1])
|
|
55
|
+
self._tabs.addTab(self._build_two_way_tab(), self._TABS[2])
|
|
56
|
+
self._tabs.addTab(self._build_corr_tab(), self._TABS[3])
|
|
57
|
+
self._tabs.addTab(self._build_normality_tab(), self._TABS[4])
|
|
58
|
+
self._tabs.addTab(self._build_curvefit_tab(), self._TABS[5])
|
|
59
|
+
self._tabs.addTab(self._build_descriptive_tab(), self._TABS[6])
|
|
60
|
+
self._tabs.addTab(self._build_chisq_tab(), self._TABS[7])
|
|
61
|
+
self._tabs.addTab(self._build_rm_tab(), self._TABS[8])
|
|
62
|
+
self._tabs.addTab(self._build_grubbs_tab(), self._TABS[9])
|
|
63
|
+
self._tabs.addTab(self._build_roc_tab(), self._TABS[10])
|
|
64
|
+
self._tabs.addTab(self._build_mlr_tab(), self._TABS[11])
|
|
65
|
+
self._tabs.setCurrentIndex(min(initial_tab, len(self._TABS) - 1))
|
|
66
|
+
layout.addWidget(self._tabs)
|
|
67
|
+
|
|
68
|
+
# Run button
|
|
69
|
+
run_btn = QPushButton("Run Analysis")
|
|
70
|
+
run_btn.setDefault(True)
|
|
71
|
+
run_btn.clicked.connect(self._run)
|
|
72
|
+
layout.addWidget(run_btn, alignment=Qt.AlignmentFlag.AlignRight)
|
|
73
|
+
|
|
74
|
+
# Results
|
|
75
|
+
self._result_box = QTextEdit()
|
|
76
|
+
self._result_box.setReadOnly(True)
|
|
77
|
+
mono = QFont("Courier New", 8)
|
|
78
|
+
mono.setStyleHint(QFont.StyleHint.Monospace)
|
|
79
|
+
self._result_box.setFont(mono)
|
|
80
|
+
self._result_box.setMinimumHeight(140)
|
|
81
|
+
layout.addWidget(self._result_box)
|
|
82
|
+
|
|
83
|
+
btns = QDialogButtonBox(
|
|
84
|
+
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
|
85
|
+
)
|
|
86
|
+
btns.accepted.connect(self.accept)
|
|
87
|
+
btns.rejected.connect(self.reject)
|
|
88
|
+
layout.addWidget(btns)
|
|
89
|
+
|
|
90
|
+
self._refresh_groups()
|
|
91
|
+
|
|
92
|
+
# ------------------------------------------------------------------
|
|
93
|
+
def _current_table(self):
|
|
94
|
+
idx = self._table_cb.currentIndex()
|
|
95
|
+
if idx < 0 or idx >= len(self._col_tables):
|
|
96
|
+
return None
|
|
97
|
+
return self._col_tables[idx]
|
|
98
|
+
|
|
99
|
+
def _group_names(self) -> list[str]:
|
|
100
|
+
t = self._current_table()
|
|
101
|
+
return [c.name for c in t.columns] if t and hasattr(t, "columns") else []
|
|
102
|
+
|
|
103
|
+
def _refresh_groups(self):
|
|
104
|
+
names = self._group_names()
|
|
105
|
+
for cb in [self._tt_ga, self._tt_gb, self._cf_x, self._cf_y,
|
|
106
|
+
self._corr_a, self._corr_b, self._roc_label, self._roc_score,
|
|
107
|
+
self._mlr_y]:
|
|
108
|
+
cb.clear()
|
|
109
|
+
cb.addItems(names)
|
|
110
|
+
# Refresh MLR X list
|
|
111
|
+
self._mlr_x.clear()
|
|
112
|
+
self._mlr_x.addItems(names)
|
|
113
|
+
if len(names) >= 2:
|
|
114
|
+
self._tt_gb.setCurrentIndex(1)
|
|
115
|
+
self._corr_b.setCurrentIndex(1)
|
|
116
|
+
self._cf_y.setCurrentIndex(min(1, len(names) - 1))
|
|
117
|
+
self._roc_score.setCurrentIndex(min(1, len(names) - 1))
|
|
118
|
+
|
|
119
|
+
# ------------------------------------------------------------------
|
|
120
|
+
# Tab builders — original 7
|
|
121
|
+
# ------------------------------------------------------------------
|
|
122
|
+
def _build_ttest_tab(self) -> QWidget:
|
|
123
|
+
w = QWidget()
|
|
124
|
+
form = QFormLayout(w)
|
|
125
|
+
self._tt_ga = QComboBox()
|
|
126
|
+
self._tt_gb = QComboBox()
|
|
127
|
+
self._tt_paired = QCheckBox("Paired")
|
|
128
|
+
self._tt_alt = QComboBox()
|
|
129
|
+
self._tt_alt.addItems(["two-sided", "greater", "less"])
|
|
130
|
+
self._tt_nonpar = QCheckBox("Non-parametric (Mann-Whitney / Wilcoxon)")
|
|
131
|
+
form.addRow("Group A:", self._tt_ga)
|
|
132
|
+
form.addRow("Group B:", self._tt_gb)
|
|
133
|
+
form.addRow("", self._tt_paired)
|
|
134
|
+
form.addRow("Alternative:", self._tt_alt)
|
|
135
|
+
form.addRow("", self._tt_nonpar)
|
|
136
|
+
return w
|
|
137
|
+
|
|
138
|
+
def _build_anova_tab(self) -> QWidget:
|
|
139
|
+
w = QWidget()
|
|
140
|
+
form = QFormLayout(w)
|
|
141
|
+
self._anova_nonpar = QCheckBox("Non-parametric (Kruskal-Wallis)")
|
|
142
|
+
self._anova_posthoc = QComboBox()
|
|
143
|
+
self._anova_posthoc.addItems(["tukey", "none"])
|
|
144
|
+
form.addRow("", self._anova_nonpar)
|
|
145
|
+
form.addRow("Post-hoc:", self._anova_posthoc)
|
|
146
|
+
form.addRow(QLabel("(Uses all columns in the selected table)"))
|
|
147
|
+
return w
|
|
148
|
+
|
|
149
|
+
def _build_two_way_tab(self) -> QWidget:
|
|
150
|
+
w = QWidget()
|
|
151
|
+
layout = QVBoxLayout(w)
|
|
152
|
+
layout.addWidget(QLabel(
|
|
153
|
+
"Requires a Grouped data table (Factor A = columns, Factor B = rows).\n"
|
|
154
|
+
"Create one via Data → Add Grouped Table."
|
|
155
|
+
))
|
|
156
|
+
return w
|
|
157
|
+
|
|
158
|
+
def _build_corr_tab(self) -> QWidget:
|
|
159
|
+
w = QWidget()
|
|
160
|
+
form = QFormLayout(w)
|
|
161
|
+
self._corr_a = QComboBox()
|
|
162
|
+
self._corr_b = QComboBox()
|
|
163
|
+
self._corr_method = QComboBox()
|
|
164
|
+
self._corr_method.addItems(["pearson", "spearman", "kendall"])
|
|
165
|
+
form.addRow("Column A:", self._corr_a)
|
|
166
|
+
form.addRow("Column B:", self._corr_b)
|
|
167
|
+
form.addRow("Method:", self._corr_method)
|
|
168
|
+
return w
|
|
169
|
+
|
|
170
|
+
def _build_normality_tab(self) -> QWidget:
|
|
171
|
+
w = QWidget()
|
|
172
|
+
layout = QVBoxLayout(w)
|
|
173
|
+
layout.addWidget(QLabel(
|
|
174
|
+
"Runs Shapiro-Wilk, D'Agostino-Pearson, and KS tests\n"
|
|
175
|
+
"on every column in the selected table.\n\n"
|
|
176
|
+
"p < 0.05 → data deviate from normality → consider non-parametric tests."
|
|
177
|
+
))
|
|
178
|
+
return w
|
|
179
|
+
|
|
180
|
+
def _build_curvefit_tab(self) -> QWidget:
|
|
181
|
+
w = QWidget()
|
|
182
|
+
form = QFormLayout(w)
|
|
183
|
+
self._cf_x = QComboBox()
|
|
184
|
+
self._cf_y = QComboBox()
|
|
185
|
+
self._cf_model = QComboBox()
|
|
186
|
+
self._cf_model.addItems(list(stat_lib.MODELS.keys()))
|
|
187
|
+
form.addRow("X column:", self._cf_x)
|
|
188
|
+
form.addRow("Y column:", self._cf_y)
|
|
189
|
+
form.addRow("Model:", self._cf_model)
|
|
190
|
+
return w
|
|
191
|
+
|
|
192
|
+
def _build_descriptive_tab(self) -> QWidget:
|
|
193
|
+
w = QWidget()
|
|
194
|
+
QVBoxLayout(w).addWidget(
|
|
195
|
+
QLabel("Computes N, Mean, SD, SEM, 95% CI, Median for all columns.")
|
|
196
|
+
)
|
|
197
|
+
return w
|
|
198
|
+
|
|
199
|
+
# ------------------------------------------------------------------
|
|
200
|
+
# Tab builders — new (v0.4-0.6)
|
|
201
|
+
# ------------------------------------------------------------------
|
|
202
|
+
def _build_chisq_tab(self) -> QWidget:
|
|
203
|
+
w = QWidget()
|
|
204
|
+
layout = QVBoxLayout(w)
|
|
205
|
+
|
|
206
|
+
self._chisq_table_cb = QComboBox()
|
|
207
|
+
cont_tables = [t for t in self._tables if isinstance(t, ContingencyTable)]
|
|
208
|
+
self._cont_tables = cont_tables
|
|
209
|
+
self._chisq_table_cb.addItems([t.name for t in cont_tables])
|
|
210
|
+
|
|
211
|
+
form = QFormLayout()
|
|
212
|
+
form.addRow("Contingency table:", self._chisq_table_cb)
|
|
213
|
+
layout.addLayout(form)
|
|
214
|
+
|
|
215
|
+
self._chisq_fisher = QCheckBox("Fisher's exact test (2×2 only)")
|
|
216
|
+
layout.addWidget(self._chisq_fisher)
|
|
217
|
+
|
|
218
|
+
layout.addWidget(QLabel(
|
|
219
|
+
"\nCreate a contingency table via Data → Add Contingency Table.\n"
|
|
220
|
+
"Enter integer counts, then run the test here."
|
|
221
|
+
))
|
|
222
|
+
layout.addStretch()
|
|
223
|
+
return w
|
|
224
|
+
|
|
225
|
+
def _build_rm_tab(self) -> QWidget:
|
|
226
|
+
w = QWidget()
|
|
227
|
+
layout = QVBoxLayout(w)
|
|
228
|
+
layout.addWidget(QLabel(
|
|
229
|
+
"Repeated-measures ANOVA / Friedman test.\n\n"
|
|
230
|
+
"Table format: each column = one treatment/time-point;\n"
|
|
231
|
+
"each row = one subject (same subject across all columns).\n"
|
|
232
|
+
))
|
|
233
|
+
self._rm_nonpar = QCheckBox("Non-parametric (Friedman)")
|
|
234
|
+
layout.addWidget(self._rm_nonpar)
|
|
235
|
+
layout.addStretch()
|
|
236
|
+
return w
|
|
237
|
+
|
|
238
|
+
def _build_grubbs_tab(self) -> QWidget:
|
|
239
|
+
w = QWidget()
|
|
240
|
+
form = QFormLayout(w)
|
|
241
|
+
self._grubbs_alpha = QDoubleSpinBox()
|
|
242
|
+
self._grubbs_alpha.setRange(0.001, 0.2)
|
|
243
|
+
self._grubbs_alpha.setSingleStep(0.005)
|
|
244
|
+
self._grubbs_alpha.setValue(0.05)
|
|
245
|
+
self._grubbs_alpha.setDecimals(3)
|
|
246
|
+
form.addRow("α (significance level):", self._grubbs_alpha)
|
|
247
|
+
form.addRow(QLabel(
|
|
248
|
+
"\nTests each column for a single extreme outlier using Grubbs' test.\n"
|
|
249
|
+
"Runs on all columns of the selected table."
|
|
250
|
+
))
|
|
251
|
+
return w
|
|
252
|
+
|
|
253
|
+
def _build_roc_tab(self) -> QWidget:
|
|
254
|
+
w = QWidget()
|
|
255
|
+
form = QFormLayout(w)
|
|
256
|
+
self._roc_label = QComboBox()
|
|
257
|
+
self._roc_score = QComboBox()
|
|
258
|
+
form.addRow("Label column (0/1):", self._roc_label)
|
|
259
|
+
form.addRow("Score column:", self._roc_score)
|
|
260
|
+
form.addRow(QLabel(
|
|
261
|
+
"\nLabel column must contain binary values (0 = negative, 1 = positive).\n"
|
|
262
|
+
"Score column contains the continuous classifier output."
|
|
263
|
+
))
|
|
264
|
+
return w
|
|
265
|
+
|
|
266
|
+
def _build_mlr_tab(self) -> QWidget:
|
|
267
|
+
w = QWidget()
|
|
268
|
+
layout = QVBoxLayout(w)
|
|
269
|
+
form = QFormLayout()
|
|
270
|
+
self._mlr_y = QComboBox()
|
|
271
|
+
form.addRow("Dependent (Y):", self._mlr_y)
|
|
272
|
+
layout.addLayout(form)
|
|
273
|
+
layout.addWidget(QLabel(
|
|
274
|
+
"Predictors (X) — hold Ctrl / Shift to select multiple:"
|
|
275
|
+
))
|
|
276
|
+
self._mlr_x = QListWidget()
|
|
277
|
+
self._mlr_x.setSelectionMode(
|
|
278
|
+
QAbstractItemView.SelectionMode.ExtendedSelection)
|
|
279
|
+
self._mlr_x.setMaximumHeight(120)
|
|
280
|
+
layout.addWidget(self._mlr_x)
|
|
281
|
+
layout.addWidget(QLabel(
|
|
282
|
+
"OLS regression with intercept. Residual plot available via "
|
|
283
|
+
"Graphs menu after running."
|
|
284
|
+
))
|
|
285
|
+
layout.addStretch()
|
|
286
|
+
return w
|
|
287
|
+
|
|
288
|
+
# ------------------------------------------------------------------
|
|
289
|
+
def _run(self):
|
|
290
|
+
t = self._current_table()
|
|
291
|
+
tab = self._tabs.currentIndex()
|
|
292
|
+
try:
|
|
293
|
+
# ── Tabs that don't need _current_table ──────────────────
|
|
294
|
+
if tab == 7: # Chi-square / Fisher
|
|
295
|
+
idx = self._chisq_table_cb.currentIndex()
|
|
296
|
+
if idx < 0 or idx >= len(self._cont_tables):
|
|
297
|
+
raise ValueError("Select a contingency table.")
|
|
298
|
+
ct = self._cont_tables[idx]
|
|
299
|
+
if self._chisq_fisher.isChecked():
|
|
300
|
+
result = stat_lib.run_fisher_exact(ct)
|
|
301
|
+
else:
|
|
302
|
+
result = stat_lib.run_chi_square(ct)
|
|
303
|
+
result.run_params = {}
|
|
304
|
+
|
|
305
|
+
elif tab == 8: # RM ANOVA / Friedman
|
|
306
|
+
if t is None:
|
|
307
|
+
raise ValueError("Select a data table.")
|
|
308
|
+
friedman = self._rm_nonpar.isChecked()
|
|
309
|
+
result = (stat_lib.run_friedman(t) if friedman else stat_lib.run_rm_anova(t))
|
|
310
|
+
result.run_params = {"non_parametric": friedman}
|
|
311
|
+
|
|
312
|
+
elif tab == 9: # Grubbs
|
|
313
|
+
if t is None:
|
|
314
|
+
raise ValueError("Select a data table.")
|
|
315
|
+
alpha = self._grubbs_alpha.value()
|
|
316
|
+
result = stat_lib.run_grubbs(t, alpha=alpha)
|
|
317
|
+
result.run_params = {"alpha": alpha}
|
|
318
|
+
|
|
319
|
+
elif tab == 10: # ROC
|
|
320
|
+
if t is None:
|
|
321
|
+
raise ValueError("Select a data table.")
|
|
322
|
+
lbl, score = self._roc_label.currentText(), self._roc_score.currentText()
|
|
323
|
+
result = stat_lib.run_roc(t, lbl, score)
|
|
324
|
+
result.run_params = {"label_col": lbl, "score_col": score}
|
|
325
|
+
|
|
326
|
+
# ── Original tabs ─────────────────────────────────────────
|
|
327
|
+
elif tab == 0:
|
|
328
|
+
if t is None:
|
|
329
|
+
raise ValueError("Select a data table.")
|
|
330
|
+
ga, gb = self._tt_ga.currentText(), self._tt_gb.currentText()
|
|
331
|
+
alt = self._tt_alt.currentText()
|
|
332
|
+
paired = self._tt_paired.isChecked()
|
|
333
|
+
nonpar = self._tt_nonpar.isChecked()
|
|
334
|
+
if nonpar:
|
|
335
|
+
result = (stat_lib.run_wilcoxon(t, ga, gb, alt) if paired
|
|
336
|
+
else stat_lib.run_mann_whitney(t, ga, gb, alt))
|
|
337
|
+
else:
|
|
338
|
+
result = stat_lib.run_ttest(t, ga, gb, paired, alt)
|
|
339
|
+
result.run_params = {
|
|
340
|
+
"group_a": ga, "group_b": gb,
|
|
341
|
+
"paired": paired, "alternative": alt, "non_parametric": nonpar,
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
elif tab == 1:
|
|
345
|
+
if t is None:
|
|
346
|
+
raise ValueError("Select a data table.")
|
|
347
|
+
nonpar = self._anova_nonpar.isChecked()
|
|
348
|
+
post_hoc = self._anova_posthoc.currentText()
|
|
349
|
+
result = (stat_lib.run_kruskal_wallis(t) if nonpar
|
|
350
|
+
else stat_lib.run_one_way_anova(t, post_hoc))
|
|
351
|
+
result.run_params = {"non_parametric": nonpar, "post_hoc": post_hoc}
|
|
352
|
+
|
|
353
|
+
elif tab == 2:
|
|
354
|
+
if not isinstance(t, GroupedDataTable):
|
|
355
|
+
raise ValueError("Two-Way ANOVA requires a Grouped table.")
|
|
356
|
+
result = stat_lib.run_two_way_anova(t)
|
|
357
|
+
result.run_params = {}
|
|
358
|
+
|
|
359
|
+
elif tab == 3:
|
|
360
|
+
if t is None:
|
|
361
|
+
raise ValueError("Select a data table.")
|
|
362
|
+
ca, cb = self._corr_a.currentText(), self._corr_b.currentText()
|
|
363
|
+
meth = self._corr_method.currentText()
|
|
364
|
+
result = stat_lib.run_correlation(t, ca, cb, meth)
|
|
365
|
+
result.run_params = {"col_a": ca, "col_b": cb, "method": meth}
|
|
366
|
+
|
|
367
|
+
elif tab == 4:
|
|
368
|
+
if t is None:
|
|
369
|
+
raise ValueError("Select a data table.")
|
|
370
|
+
result = stat_lib.run_normality(t)
|
|
371
|
+
result.run_params = {}
|
|
372
|
+
|
|
373
|
+
elif tab == 5:
|
|
374
|
+
if t is None:
|
|
375
|
+
raise ValueError("Select a data table.")
|
|
376
|
+
x_col = self._cf_x.currentText()
|
|
377
|
+
y_col = self._cf_y.currentText()
|
|
378
|
+
model = self._cf_model.currentText()
|
|
379
|
+
result = stat_lib.run_curve_fit(t, x_col, y_col, model)
|
|
380
|
+
result.run_params = {"x_col": x_col, "y_col": y_col, "model": model}
|
|
381
|
+
|
|
382
|
+
elif tab == 11: # Multiple Regression
|
|
383
|
+
if t is None:
|
|
384
|
+
raise ValueError("Select a data table.")
|
|
385
|
+
y_col = self._mlr_y.currentText()
|
|
386
|
+
x_cols = [item.text() for item in self._mlr_x.selectedItems()]
|
|
387
|
+
if not x_cols:
|
|
388
|
+
raise ValueError("Select at least one predictor (X column).")
|
|
389
|
+
result = stat_lib.run_multiple_regression(t, y_col, x_cols)
|
|
390
|
+
result.run_params = {"y_col": y_col, "x_cols": x_cols}
|
|
391
|
+
|
|
392
|
+
else: # Descriptive
|
|
393
|
+
if t is None:
|
|
394
|
+
raise ValueError("Select a data table.")
|
|
395
|
+
from ..stats.tests import run_descriptive
|
|
396
|
+
result = run_descriptive(t)
|
|
397
|
+
result.run_params = {}
|
|
398
|
+
|
|
399
|
+
self._result = result
|
|
400
|
+
self._result_box.setPlainText(result.summary_text)
|
|
401
|
+
|
|
402
|
+
except Exception as exc:
|
|
403
|
+
self._result_box.setPlainText(f"Error: {exc}")
|
|
404
|
+
|
|
405
|
+
def get_result(self) -> AnalysisResult | None:
|
|
406
|
+
return self._result
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Axis settings dialog — log scale, custom range, labels."""
|
|
2
|
+
|
|
3
|
+
from qtpy.QtWidgets import (
|
|
4
|
+
QDialog, QVBoxLayout, QFormLayout, QComboBox, QDoubleSpinBox,
|
|
5
|
+
QLineEdit, QDialogButtonBox, QGroupBox, QCheckBox, QHBoxLayout,
|
|
6
|
+
QLabel,
|
|
7
|
+
)
|
|
8
|
+
from qtpy.QtCore import Qt
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class _RangeRow(QHBoxLayout):
|
|
12
|
+
"""A pair of optional min/max spinboxes."""
|
|
13
|
+
|
|
14
|
+
def __init__(self, label: str, lo=None, hi=None):
|
|
15
|
+
super().__init__()
|
|
16
|
+
self._auto_lo = QCheckBox("auto")
|
|
17
|
+
self._auto_hi = QCheckBox("auto")
|
|
18
|
+
self._lo = QDoubleSpinBox()
|
|
19
|
+
self._hi = QDoubleSpinBox()
|
|
20
|
+
for sb in (self._lo, self._hi):
|
|
21
|
+
sb.setRange(-1e9, 1e9)
|
|
22
|
+
sb.setDecimals(4)
|
|
23
|
+
sb.setFixedWidth(90)
|
|
24
|
+
self._auto_lo.setChecked(lo is None)
|
|
25
|
+
self._auto_hi.setChecked(hi is None)
|
|
26
|
+
if lo is not None:
|
|
27
|
+
self._lo.setValue(lo)
|
|
28
|
+
if hi is not None:
|
|
29
|
+
self._hi.setValue(hi)
|
|
30
|
+
self._auto_lo.toggled.connect(lambda v: self._lo.setDisabled(v))
|
|
31
|
+
self._auto_hi.toggled.connect(lambda v: self._hi.setDisabled(v))
|
|
32
|
+
self._lo.setDisabled(lo is None)
|
|
33
|
+
self._hi.setDisabled(hi is None)
|
|
34
|
+
self.addWidget(QLabel("min")); self.addWidget(self._auto_lo); self.addWidget(self._lo)
|
|
35
|
+
self.addSpacing(10)
|
|
36
|
+
self.addWidget(QLabel("max")); self.addWidget(self._auto_hi); self.addWidget(self._hi)
|
|
37
|
+
|
|
38
|
+
def get(self) -> tuple:
|
|
39
|
+
lo = None if self._auto_lo.isChecked() else self._lo.value()
|
|
40
|
+
hi = None if self._auto_hi.isChecked() else self._hi.value()
|
|
41
|
+
return lo, hi
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
class AxisDialog(QDialog):
|
|
45
|
+
"""Configure axis scales and ranges for a graph."""
|
|
46
|
+
|
|
47
|
+
def __init__(self, current: dict | None = None, parent=None):
|
|
48
|
+
super().__init__(parent)
|
|
49
|
+
self.setWindowTitle("Axis Settings")
|
|
50
|
+
self.setMinimumWidth(420)
|
|
51
|
+
opts = current or {}
|
|
52
|
+
|
|
53
|
+
layout = QVBoxLayout(self)
|
|
54
|
+
form = QFormLayout()
|
|
55
|
+
|
|
56
|
+
# X axis
|
|
57
|
+
x_grp = QGroupBox("X axis")
|
|
58
|
+
x_layout = QFormLayout(x_grp)
|
|
59
|
+
self._x_scale = QComboBox(); self._x_scale.addItems(["linear", "log"])
|
|
60
|
+
self._x_scale.setCurrentText(opts.get("x_scale", "linear"))
|
|
61
|
+
x_layout.addRow("Scale:", self._x_scale)
|
|
62
|
+
self._x_range = _RangeRow("X", opts.get("x_min"), opts.get("x_max"))
|
|
63
|
+
x_layout.addRow("Range:", self._x_range)
|
|
64
|
+
self._x_label = QLineEdit(opts.get("x_label", ""))
|
|
65
|
+
x_layout.addRow("Label:", self._x_label)
|
|
66
|
+
layout.addWidget(x_grp)
|
|
67
|
+
|
|
68
|
+
# Y axis
|
|
69
|
+
y_grp = QGroupBox("Y axis")
|
|
70
|
+
y_layout = QFormLayout(y_grp)
|
|
71
|
+
self._y_scale = QComboBox(); self._y_scale.addItems(["linear", "log"])
|
|
72
|
+
self._y_scale.setCurrentText(opts.get("y_scale", "linear"))
|
|
73
|
+
y_layout.addRow("Scale:", self._y_scale)
|
|
74
|
+
self._y_range = _RangeRow("Y", opts.get("y_min"), opts.get("y_max"))
|
|
75
|
+
y_layout.addRow("Range:", self._y_range)
|
|
76
|
+
self._y_label = QLineEdit(opts.get("y_label", ""))
|
|
77
|
+
y_layout.addRow("Label:", self._y_label)
|
|
78
|
+
# Y-start at zero
|
|
79
|
+
self._y_zero = QCheckBox("Start Y axis at zero")
|
|
80
|
+
self._y_zero.setChecked(opts.get("y_zero", False))
|
|
81
|
+
y_layout.addRow("", self._y_zero)
|
|
82
|
+
layout.addWidget(y_grp)
|
|
83
|
+
|
|
84
|
+
btns = QDialogButtonBox(
|
|
85
|
+
QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
|
|
86
|
+
)
|
|
87
|
+
btns.accepted.connect(self.accept)
|
|
88
|
+
btns.rejected.connect(self.reject)
|
|
89
|
+
layout.addWidget(btns)
|
|
90
|
+
|
|
91
|
+
def get_options(self) -> dict:
|
|
92
|
+
x_min, x_max = self._x_range.get()
|
|
93
|
+
y_min, y_max = self._y_range.get()
|
|
94
|
+
return {
|
|
95
|
+
"x_scale": self._x_scale.currentText(),
|
|
96
|
+
"y_scale": self._y_scale.currentText(),
|
|
97
|
+
"x_min": x_min,
|
|
98
|
+
"x_max": x_max,
|
|
99
|
+
"y_min": y_min,
|
|
100
|
+
"y_max": y_max,
|
|
101
|
+
"x_label": self._x_label.text(),
|
|
102
|
+
"y_label": self._y_label.text(),
|
|
103
|
+
"y_zero": self._y_zero.isChecked(),
|
|
104
|
+
}
|