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,235 @@
1
+ from __future__ import annotations
2
+
3
+ import math
4
+
5
+ import numpy as np
6
+ import pandas as pd
7
+
8
+ from statstudio.plots.common import color, frame, new_figure, numeric, style_axes
9
+ from statstudio.stats.results import PlotSpec
10
+
11
+
12
+ def doe_pareto(spec: PlotSpec):
13
+ data = frame(spec)
14
+ if data.empty or "Abs t" not in data.columns or "Term" not in data.columns:
15
+ return new_figure()
16
+ data = data.sort_values("Abs t", ascending=True)
17
+ figure = new_figure(7, max(3.5, 0.38 * len(data) + 1.4))
18
+ ax = figure.add_subplot(111)
19
+ colors = [color(1) if value >= 2 else color(0) for value in data["Abs t"]]
20
+ ax.barh(data["Term"].astype(str), data["Abs t"], color=colors)
21
+ ax.axvline(2, color="#666666", linestyle="--", linewidth=1, label="|t| = 2")
22
+ ax.legend(frameon=False, fontsize=8)
23
+ style_axes(ax, spec.title or "Pareto of Standardized Effects", "Absolute t value", "Term")
24
+ return figure
25
+
26
+
27
+ def main_effects(spec: PlotSpec):
28
+ data = frame(spec)
29
+ factor_name = spec.params.get("factor", "Factor")
30
+ level_name = spec.params.get("level", "Level")
31
+ response_name = spec.params.get("response", "Predicted")
32
+ if data.empty or factor_name not in data.columns:
33
+ return new_figure()
34
+ factors = list(pd.unique(data[factor_name]))
35
+ columns = min(3, len(factors))
36
+ if not factors or columns == 0:
37
+ return new_figure()
38
+ rows = math.ceil(len(factors) / columns)
39
+ figure = new_figure(max(7, columns * 3.2), max(3, rows * 2.8))
40
+ order = ["Low", "High"]
41
+ for index, factor in enumerate(factors):
42
+ ax = figure.add_subplot(rows, columns, index + 1)
43
+ chunk = data[data[factor_name] == factor]
44
+ levels = list(chunk[level_name])
45
+ values = numeric(chunk, response_name)
46
+ mapping = dict(zip(levels, values))
47
+ xs = [level for level in order if level in mapping] or levels
48
+ ys = [mapping[level] for level in xs]
49
+ ax.plot(range(len(xs)), ys, marker="o", color=color(0), linewidth=2)
50
+ ax.axhline(float(data[response_name].mean()), color="#888888", linestyle="--", linewidth=1)
51
+ ax.set_xticks(range(len(xs)), [str(x) for x in xs])
52
+ style_axes(ax, str(factor), "", str(response_name))
53
+ figure.suptitle(spec.title or "Main Effects", fontsize=12)
54
+ return figure
55
+
56
+
57
+ def interaction(spec: PlotSpec):
58
+ data = frame(spec)
59
+ f1 = spec.params.get("factor1", "Factor 1")
60
+ l1 = spec.params.get("level1", "Level 1")
61
+ f2 = spec.params.get("factor2", "Factor 2")
62
+ l2 = spec.params.get("level2", "Level 2")
63
+ response_name = spec.params.get("response", "Predicted")
64
+ pairs = list(data[[f1, f2]].drop_duplicates().itertuples(index=False, name=None))
65
+ columns = min(2, max(1, len(pairs)))
66
+ rows = math.ceil(len(pairs) / columns)
67
+ figure = new_figure(max(7, columns * 4), max(3, rows * 3.2))
68
+ for index, (first, second) in enumerate(pairs):
69
+ ax = figure.add_subplot(rows, columns, index + 1)
70
+ chunk = data[(data[f1] == first) & (data[f2] == second)]
71
+ for line_index, (level2, line_chunk) in enumerate(chunk.groupby(l2, sort=False)):
72
+ line_chunk = line_chunk.copy()
73
+ line_chunk["__order__"] = line_chunk[l1].map({"Low": 0, "High": 1}).fillna(2)
74
+ line_chunk = line_chunk.sort_values("__order__")
75
+ ax.plot(line_chunk[l1].astype(str), numeric(line_chunk, response_name), marker="o", linewidth=2, color=color(line_index), label=str(level2))
76
+ ax.legend(title=str(second), frameon=False, fontsize=7)
77
+ style_axes(ax, f"{first} x {second}", str(first), str(response_name))
78
+ figure.suptitle(spec.title or "Interaction Plots", fontsize=12)
79
+ return figure
80
+
81
+
82
+ def _grid(data: pd.DataFrame, x_name: str, y_name: str, z_name: str):
83
+ work = pd.DataFrame(
84
+ {
85
+ "x": pd.to_numeric(data[x_name], errors="coerce"),
86
+ "y": pd.to_numeric(data[y_name], errors="coerce"),
87
+ "z": pd.to_numeric(data[z_name], errors="coerce"),
88
+ }
89
+ ).dropna()
90
+ if work.empty or work["x"].nunique() < 2 or work["y"].nunique() < 2:
91
+ raise ValueError("Response contour and surface plots need at least two numeric levels on each axis.")
92
+ pivot = work.pivot_table(index="y", columns="x", values="z", aggfunc="mean")
93
+ return pivot.columns.to_numpy(dtype=float), pivot.index.to_numpy(dtype=float), pivot.to_numpy(dtype=float)
94
+
95
+
96
+ def doe_contour(spec: PlotSpec):
97
+ data = frame(spec)
98
+ x_name = spec.params.get("x", "Factor 1")
99
+ y_name = spec.params.get("y", "Factor 2")
100
+ z_name = spec.params.get("z", "Predicted")
101
+ x, y, z = _grid(data, x_name, y_name, z_name)
102
+ figure = new_figure(6.5, 5)
103
+ ax = figure.add_subplot(111)
104
+ filled = ax.contourf(x, y, z, levels=18, cmap="RdYlBu_r")
105
+ lines = ax.contour(x, y, z, levels=10, colors="white", linewidths=0.6)
106
+ ax.clabel(lines, inline=True, fontsize=7, fmt="%.3g")
107
+ figure.colorbar(filled, ax=ax, label=str(z_name))
108
+ style_axes(ax, spec.title or "Response Contour", spec.params.get("x_label", str(x_name)), spec.params.get("y_label", str(y_name)))
109
+ return figure
110
+
111
+
112
+ def doe_surface(spec: PlotSpec):
113
+ data = frame(spec)
114
+ x_name = spec.params.get("x", "Factor 1")
115
+ y_name = spec.params.get("y", "Factor 2")
116
+ z_name = spec.params.get("z", "Predicted")
117
+ x, y, z = _grid(data, x_name, y_name, z_name)
118
+ figure = new_figure(7, 5.5)
119
+ ax = figure.add_subplot(111, projection="3d")
120
+ xx, yy = np.meshgrid(x, y)
121
+ ax.plot_surface(xx, yy, z, cmap="RdYlBu_r", alpha=0.9, linewidth=0)
122
+ ax.set_xlabel(spec.params.get("x_label", str(x_name)))
123
+ ax.set_ylabel(spec.params.get("y_label", str(y_name)))
124
+ ax.set_zlabel(str(z_name))
125
+ ax.set_title(spec.title or "Response Surface", fontsize=11, fontweight="bold")
126
+ return figure
127
+
128
+
129
+ def _scatter_xyz(data: pd.DataFrame, x_name: str, y_name: str, z_name: str):
130
+ frame_xyz = pd.DataFrame(
131
+ {
132
+ "x": pd.to_numeric(data[x_name], errors="coerce"),
133
+ "y": pd.to_numeric(data[y_name], errors="coerce"),
134
+ "z": pd.to_numeric(data[z_name], errors="coerce"),
135
+ }
136
+ ).dropna()
137
+ return (
138
+ frame_xyz["x"].to_numpy(dtype=float),
139
+ frame_xyz["y"].to_numpy(dtype=float),
140
+ frame_xyz["z"].to_numpy(dtype=float),
141
+ )
142
+
143
+
144
+ def contour_generic(spec: PlotSpec):
145
+ data = frame(spec)
146
+ x_name = spec.params["x"]
147
+ y_name = spec.params["y"]
148
+ z_name = spec.params["z"]
149
+ figure = new_figure()
150
+ ax = figure.add_subplot(111)
151
+ if any(name not in data.columns for name in (x_name, y_name, z_name)):
152
+ style_axes(ax, spec.title or "Contour Plot", str(x_name), str(y_name))
153
+ return figure
154
+ x, y, z = _scatter_xyz(data, x_name, y_name, z_name)
155
+ if len(x) < 3:
156
+ style_axes(ax, spec.title or "Contour Plot", str(x_name), str(y_name))
157
+ return figure
158
+ try:
159
+ filled = ax.tricontourf(x, y, z, levels=16, cmap="RdYlBu_r")
160
+ ax.tricontour(x, y, z, levels=8, colors="white", linewidths=0.6)
161
+ except (ValueError, RuntimeError):
162
+ filled = ax.scatter(x, y, c=z, cmap="RdYlBu_r", s=28, edgecolors="white", linewidths=0.4)
163
+ figure.colorbar(filled, ax=ax, label=str(z_name))
164
+ style_axes(ax, spec.title or "Contour Plot", str(x_name), str(y_name))
165
+ return figure
166
+
167
+
168
+ def surface_generic(spec: PlotSpec):
169
+ data = frame(spec)
170
+ x_name = spec.params["x"]
171
+ y_name = spec.params["y"]
172
+ z_name = spec.params["z"]
173
+ figure = new_figure(7, 5.5)
174
+ ax = figure.add_subplot(111, projection="3d")
175
+ if any(name not in data.columns for name in (x_name, y_name, z_name)):
176
+ ax.set_title(spec.title or "Surface Plot", fontsize=11, fontweight="bold")
177
+ return figure
178
+ x, y, z = _scatter_xyz(data, x_name, y_name, z_name)
179
+ if len(x) < 4:
180
+ ax.set_title(spec.title or "Surface Plot", fontsize=11, fontweight="bold")
181
+ return figure
182
+ try:
183
+ from scipy.interpolate import griddata
184
+
185
+ grid_x, grid_y = np.meshgrid(
186
+ np.linspace(float(np.min(x)), float(np.max(x)), 40),
187
+ np.linspace(float(np.min(y)), float(np.max(y)), 40),
188
+ )
189
+ grid_z = griddata((x, y), z, (grid_x, grid_y), method="linear")
190
+ nearest = griddata((x, y), z, (grid_x, grid_y), method="nearest")
191
+ grid_z = np.where(np.isnan(grid_z), nearest, grid_z)
192
+ ax.plot_surface(grid_x, grid_y, grid_z, cmap="RdYlBu_r", alpha=0.9, linewidth=0)
193
+ except (ValueError, RuntimeError):
194
+ ax.scatter(x, y, z, c=z, cmap="RdYlBu_r", s=28, alpha=0.9)
195
+ ax.set_xlabel(str(x_name))
196
+ ax.set_ylabel(str(y_name))
197
+ ax.set_zlabel(str(z_name))
198
+ ax.set_title(spec.title or "Surface Plot", fontsize=11, fontweight="bold")
199
+ return figure
200
+
201
+
202
+ def profiler(spec: PlotSpec):
203
+ data = frame(spec)
204
+ factor_name = spec.params.get("factor", "Factor")
205
+ level_name = spec.params.get("level", "Level")
206
+ label_name = spec.params.get("label")
207
+ categorical_name = spec.params.get("categorical")
208
+ response_name = spec.params.get("predicted", "Predicted")
209
+ y_label = spec.params.get("y_label", str(response_name))
210
+ if data.empty or factor_name not in data.columns:
211
+ return new_figure()
212
+ factors = list(pd.unique(data[factor_name]))
213
+ columns = min(3, max(1, len(factors)))
214
+ rows = math.ceil(len(factors) / columns)
215
+ figure = new_figure(max(7, columns * 3.2), max(3, rows * 2.8))
216
+ for index, factor in enumerate(factors):
217
+ ax = figure.add_subplot(rows, columns, index + 1)
218
+ chunk = data[data[factor_name] == factor]
219
+ order = chunk.sort_values(level_name)
220
+ categorical = False
221
+ if categorical_name in order.columns and not order.empty:
222
+ categorical = bool(order[categorical_name].iloc[0])
223
+ predicted = numeric(order, response_name)
224
+ if categorical and label_name in order.columns:
225
+ positions = np.arange(len(order))
226
+ labels = order[label_name].astype(str).tolist()
227
+ ax.plot(positions, predicted, marker="o", color=color(0), linewidth=2)
228
+ ax.set_xticks(positions)
229
+ ax.set_xticklabels(labels, rotation=30 if any(len(label) > 5 for label in labels) else 0)
230
+ ax.tick_params(axis="x", labelsize=8)
231
+ else:
232
+ ax.plot(numeric(order, level_name), predicted, marker="o", color=color(0), linewidth=2)
233
+ style_axes(ax, str(factor), spec.params.get("x_label", str(level_name)), y_label)
234
+ figure.suptitle(spec.title or "Prediction Profiler", fontsize=12)
235
+ return figure