doestat 0.1.0__tar.gz

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.
doestat-0.1.0/LICENSE ADDED
@@ -0,0 +1,14 @@
1
+ # Copyright (C) 2025 Romulo Pires
2
+ #
3
+ # This program is free software: you can redistribute it and/or modify
4
+ # it under the terms of the GNU General Public License as published by
5
+ # the Free Software Foundation, either version 3 of the License, or
6
+ # any later version.
7
+ #
8
+ # This program is distributed in the hope that it will be useful,
9
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
10
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
+ # GNU General Public License for more details.
12
+ #
13
+ # You should have received a copy of the GNU General Public License
14
+ # along with this program. If not, see <https://www.gnu.org/licenses/>.
doestat-0.1.0/PKG-INFO ADDED
@@ -0,0 +1,437 @@
1
+ Metadata-Version: 2.4
2
+ Name: doestat
3
+ Version: 0.1.0
4
+ Summary: Design of Experiments statistical tools
5
+ Author-email: Romulo Pires <romulo.pires@outlook.com>
6
+ Project-URL: Homepage, https://github.com/RomuloPires88/DoEStat
7
+ Requires-Python: >=3.8
8
+ Description-Content-Type: text/markdown
9
+ License-File: LICENSE
10
+ Requires-Dist: numpy
11
+ Requires-Dist: pandas
12
+ Requires-Dist: scipy
13
+ Requires-Dist: matplotlib
14
+ Requires-Dist: seaborn
15
+ Requires-Dist: IPython
16
+ Requires-Dist: plotly
17
+ Dynamic: license-file
18
+
19
+ # DoE Statistc (doestat.py)
20
+
21
+ ![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)
22
+
23
+ A Python implementation for Design of Experiments (DOE), providing tools to optimize processes, analyze factor effects, and evaluate quality metrics in robust engineering applications.
24
+
25
+ ## πŸ“Œ Overview
26
+ Design of Experiments (DOE) is a powerful approach for systematically planning, conducting, analyzing, and interpreting controlled tests to evaluate factor effects on responses. This package offers two distinct yet complementary methods to support experimental design and analysis:
27
+
28
+ 1 - Taguchi Method:
29
+ The `Taguchi` approach provides a robust framework for process optimization and quality improvement. By minimizing the variability in responses and optimizing the mean performance, this method is especially effective in manufacturing, engineering, and other applied sciences. Key features include:
30
+ - Evaluation of quality metrics using **Signal-to-Noise Ratios (S/N)** for "Bigger is Better," "Smaller is Better," and "Nominal is Better" objectives.
31
+ - Handling of multiple responses via techniques like the **Multi-Response Performance Index (MRPI)**.
32
+ - Visualization of factor effects, interaction graphs, and predictive capabilities for optimizing responses.
33
+ - Statistical tools such as Analysis of Variance **(ANOVA)** for variance decomposition and factor impact assessment.
34
+
35
+ 2 - Factorial Design Analysis:
36
+ `Factorial designs` are fundamental for understanding the interactions and contributions of multiple factors in experimental studies. This method focuses on:
37
+ - Calculation and visualization of factorial effects, including main effects and interactions.
38
+ - Representation of effects using Gaussian-based probability plots and percentage contribution charts to reveal the most influential factors.
39
+ - Support for error estimation using t-Student distribution, enhancing the reliability of conclusions.
40
+ - Compatibility with both simple and interaction-inclusive experimental designs.
41
+
42
+ ## ✨ Features
43
+ ### Key Functionalities
44
+ #### Taguchi Method
45
+ - **Signal-to-Noise (S/N) Ratios**: Evaluate quality characteristics with:
46
+ - "Bigger is better"
47
+ - "Smaller is better"
48
+ - "Nominal is better"
49
+ - **Multi-Response Performance Index (MRPI)**: Handle multiple responses with:
50
+ - Weighted methods (`"wgt"`)
51
+ - Envelopment methods (`"env"`)
52
+ - **Effect Analysis**: Analyze and visualize the influence of factors and interactions.
53
+ - **Interaction Checks**: Display interaction graphs to identify dependencies.
54
+ - **Prediction**: Predict responses for specific factor combinations.
55
+ - **ANOVA**: Perform Analysis of Variance to understand variance contributions.
56
+
57
+ #### Factorial Design Analysis
58
+ - **Factorial Effect Calculation**: Quantify the contributions of main effects and interactions in factorial designs.
59
+ - **Probability Plot Visualization**: Represent effects in Gaussian-based probability plots to identify significant factors.
60
+ - **Percentage Contribution Analysis**: Display and quantify the relative influence of each factor or interaction on overall variability.
61
+ - **Error Estimation**: Compute effect errors and confidence intervals using the t-Student distribution for robustness.
62
+ - **Flexible Design Support**: Analyze coded factorial matrices with or without interactions.
63
+ - **Regression Plot Visualization**: Displays the regression plot using the provided matrix data.
64
+ - **Residual Plot Visualization**: Shows the residual plot for the experimental data.
65
+ - **Histogram Plot Visualization**: Displays a histogram plot for the distribution of residuals.
66
+ - **Coefficient Error Plot Visualization**: Displays the confidence intervals for the calculated regression coefficients, providing a visual representation of their variability and reliability.
67
+ - **Response Surface**: Generate s surface response and contour plot with coded data or real values.
68
+ - **Model Equation**: Displays the model equation.
69
+
70
+ ## πŸ”§ Installation
71
+ Ensure you have Python and the necessary dependencies installed. This class requires standard scientific libraries like `numpy` and `matplotlib`.
72
+ ```bash
73
+ pip install pandas numpy matplotlib.pyplot plotly.graph_objs scipy.stats seaborn IPython.display sys itertools re
74
+ ```
75
+ Recommended Stable Versions
76
+ ```bash
77
+ pandas: 2.3.1
78
+ numpy: 1.26.4
79
+ matplotlib: 3.10.5
80
+ plotly: 5.24.1
81
+ scipy: 1.13.1
82
+ seaborn: 0.13.2
83
+ IPython: 8.27.0
84
+ Python: 3.12.7
85
+ ```
86
+
87
+ ## Class Reference
88
+
89
+ ### Class: `Taguchi`
90
+ #### Parameters:
91
+ - **X** *(matrix)*: Experimental design matrix containing factors (effects/interactions).
92
+ - **y** *(array-like)*: Response vector or matrix. Supports single or multiple responses.
93
+ - **T** *(float, optional)*: Target value for "Nominal is better" S/N ratio (default: 0).
94
+ - **sn** *(str, optional)*: Quality characteristic for S/N ratio:
95
+ - `"max"` β†’ Bigger is better
96
+ - `"min"` β†’ Smaller is better
97
+ - `"target"` β†’ Nominal is better
98
+ - **mrpi** *(str, optional)*: Method for multi-response evaluation:
99
+ - `"wgt"` β†’ Weighted method
100
+ - `"env"` β†’ Envelopment method
101
+ - **r1, r2** *(str, optional)*: Quality characteristics for multiple responses:
102
+ - `"max"` β†’ Bigger is better
103
+ - `"min"` β†’ Smaller is better
104
+ - `"target"` β†’ Nominal is better
105
+
106
+ #### Attributes:
107
+ - **y** *(array-like)*: Processed response vector/matrix after applying S/N ratios or MRPI.
108
+ - **vector_y** *(array-like)*: Final response vector/matrix ready for analysis.
109
+
110
+ ### Methods:
111
+ #### `vector_y`
112
+ - Returns the processed response vector/matrix.
113
+ - **Usage**:
114
+ ```python
115
+ doe.Taguchi(X, y).vector_y()
116
+ ```
117
+
118
+ #### `effect_analysis`
119
+ - Calculates the total response for each factor level and visualizes their effects.
120
+ - **Usage**:
121
+ ```python
122
+ doe.Taguchi(X, y).effect_analysis
123
+ ```
124
+
125
+ #### `check_interactions()`
126
+ - Displays interaction graphs between selected factors.
127
+ - **Usage**:
128
+ ```python
129
+ doe.Taguchi(X, y).check_interactions()
130
+ ```
131
+
132
+ #### `prev()`
133
+ - Predicts the response values for selected factors or interactions.
134
+ - **Usage**:
135
+ ```python
136
+ doe.Taguchi(X, y).prev()
137
+ ```
138
+
139
+ #### `anova()`
140
+ - Performs Analysis of Variance (ANOVA) and returns a summary table of variance contributions.
141
+ - **Usage**:
142
+ ```python
143
+ doe.Taguchi(X, y).anova()
144
+ ```
145
+
146
+ ## πŸ“Ž Notes
147
+ - The input data **X** and **y** must be formatted correctly:
148
+ - **X**: Matrix representing the experimental design.
149
+ - **y**: Response vector or matrix with dimensions consistent with **X**.
150
+ - For MRPI with multiple responses, ensure quality characteristics (**r1, r2**) and methods (`"wgt"` or `"env"`) are appropriately defined.
151
+
152
+ ## πŸš€ Example Usage
153
+ Here is an example to demonstrate the functionality of the `Taguchi` class:
154
+
155
+ ```python
156
+ df = pd.read_excel('test.xlsx', sheet_name = 'teste1')
157
+ X = df.iloc[:,1:8]
158
+ y = df.iloc[:,8:]
159
+
160
+ print('DataFrame')
161
+ print(df)
162
+ print('Matrix X')
163
+ print(X)
164
+ print('Vector y')
165
+ print(y)
166
+ ```
167
+ ```python
168
+ DataFrame
169
+ Exp A B C D E F G R1 R2
170
+ 0 1 1 1 1 1 1 1 1 11 11
171
+ 1 2 1 1 1 2 2 2 2 4 4
172
+ 2 3 1 2 2 1 1 2 2 4 10
173
+ 3 4 1 2 2 2 2 1 1 4 8
174
+ 4 5 2 1 2 1 2 1 2 9 4
175
+ 5 6 2 1 2 2 1 2 1 4 3
176
+ 6 7 2 2 1 1 2 2 1 1 4
177
+ 7 8 2 2 1 2 1 1 2 10 8
178
+ Matrix X
179
+ A B C D E F G
180
+ 0 1 1 1 1 1 1 1
181
+ 1 1 1 1 2 2 2 2
182
+ 2 1 2 2 1 1 2 2
183
+ 3 1 2 2 2 2 1 1
184
+ 4 2 1 2 1 2 1 2
185
+ 5 2 1 2 2 1 2 1
186
+ 6 2 2 1 1 2 2 1
187
+ 7 2 2 1 2 1 1 2
188
+ Vector y
189
+ R1 R2
190
+ 0 11 11
191
+ 1 4 4
192
+ 2 4 10
193
+ 3 4 8
194
+ 4 9 4
195
+ 5 4 3
196
+ 6 1 4
197
+ 7 10 8
198
+ ```
199
+
200
+ ```python
201
+ doe.Taguchi(X,y).effect_analysis
202
+ ```
203
+
204
+ ![imagem](https://github.com/user-attachments/assets/4c6c51bb-4253-4764-8256-afa375229ebd)
205
+
206
+ ![imagem](https://github.com/user-attachments/assets/31d81a18-79fe-4343-9b54-bca1cf69724c)
207
+
208
+ ![imagem](https://github.com/user-attachments/assets/8373f369-2a03-471a-adc9-ac570bad62af)
209
+
210
+ ```python
211
+ doe.Taguchi(X,y).prev('F-1,E-1,A-1')
212
+ ```
213
+ ```python
214
+ The predict value is:
215
+ 10.38
216
+ ```
217
+
218
+ ```python
219
+ doe.Taguchi(X,y).anova(method='Replica')
220
+ ```
221
+
222
+ ![imagem](https://github.com/user-attachments/assets/544606c3-1d3b-4259-9a03-4cc5b3af3c66)
223
+
224
+ ### Class: `Auxvalues`
225
+ `A auxiliar class that is used by others Classes`
226
+
227
+ ### Class: `Analysis`
228
+ #### Parameters:
229
+ - **X** *(matrix)*: Matrix representing the factors (effects/interactions) to be analyzed.
230
+ - **y** *(array-like)*: Vector or matrix containing the response variable(s).
231
+ - **yc** *(array-like, optional)*: Vector of central points (default: None).
232
+ - **type_matrix** *(str, optional)*: Specifies if the design includes interactions to be calculated (default: None):
233
+ - `"interaction"`
234
+ - **effect_error** *(str, optional)*: Specifies the type of effect error to be considered (default: None):
235
+ - `"cp"` β†’ Central Points
236
+ - `"replica"` β†’ Replica
237
+
238
+ #### Attributes:
239
+ - **matrix_x** *(array-like)*: Experimental design matrix, including factors and interactions.
240
+ - **vector_y** *(array-like)*: Response vector or the mean of replicates.
241
+ - **error** *(float)*: Calculated effect error.
242
+
243
+ ### Methods:
244
+ `matrix_x`
245
+ - Generates design matrix, including factors and interactions
246
+ - **Usage**:
247
+ ```python
248
+ doe.Analysis(X, y).matrix_x
249
+ ```
250
+ `vector_y`
251
+ - Show the response vector or the mean of replicates
252
+ - **Usage**:
253
+ ```python
254
+ doe.Analysis(X, y).vector_y
255
+ ```
256
+ `error`
257
+ - Show the error effect
258
+ - **Usage**:
259
+ ```python
260
+ doe.Analysis(X, y).error
261
+ ```
262
+
263
+ `effect_analysis()`
264
+ - Analyzes the effects of factors and optionally excludes specified variables.
265
+ - Generates:
266
+ - Probability Effects Plot: Visualizes the Gaussian distribution of effects, with confidence intervals.
267
+ - Percentage Effects Plot: Displays the contribution of each effect to the overall variability as a horizontal bar plot.
268
+ - **Usage**:
269
+ ```python
270
+ doe.Analysis(X, y).effect_analysis()
271
+ ```
272
+
273
+ # πŸ“ŽNotes:
274
+ - This class is ideal for factorial designs and provides tools to interpret experimental results. Input Requirements:
275
+ - X: Matrix of coded factors (interactions can be generated within the class).
276
+ - y: Response vector or matrix (should be formatted appropriately).
277
+ - Effect Error and Confidence Intervals: Calculated using central points or replicates, leveraging the t-Student distribution for robustness.
278
+ - Graphs:
279
+ - Automatically saved as image files.
280
+
281
+ ## πŸš€ Examples Usage
282
+ Here is an example to demonstrate the functionality of the `Analysis` class:
283
+ ```python
284
+ doe.Analysis(X,y,yc,type_matrix='interaction', effect_error='cp').effect_analysis()
285
+ ```
286
+ ![imagem](https://github.com/user-attachments/assets/ecc1d17a-f2d4-4c92-b2c4-be5a614897bd)
287
+
288
+ ![imagem](https://github.com/user-attachments/assets/2eca9cf8-341f-47a2-ab0e-fee4bf973b25)
289
+
290
+ ### Class: `Regression`
291
+ #### Parameters:
292
+ - **X** *(matrix)*: Matrix representing the factors (effects/interactions) to be analyzed.
293
+ - **y** *(array-like)*: Vector or matrix containing the response variable(s).
294
+ - **yc** *(array-like, optional)*: Vector of central points (default: None).
295
+ - **type_matrix** *(str, optional)*: Specifies if the design includes interactions to be calculated (default: None):
296
+ - `"interaction"`
297
+ - **effect_error** *(str, optional)*: Specifies the type of effect error to be considered (default: None):
298
+ - `"cp"` β†’ Central Points
299
+ - `"replica"` β†’ Replica
300
+ - **selected_factors** *(str, optional (default=None))*: Specifies the factors (effects/interactions) to be analyzed
301
+ - **regression** *(str, optional (default = 'quadratic'))*: Specifies the type of regression:
302
+ - `"quadratic"` β†’ Includes quadratic coefficients and, if the type_matrix='interaction', interaction coefficients.
303
+ - `"linear"` β†’ Includes linear coefficients and, if the type_matrix='interaction', interaction coefficients.
304
+
305
+ #### Attributes:
306
+ - **Xb** *(array-like)*: Reorganized array for the analyzed factors.
307
+
308
+ - Generates design matrix, including factors and interactions
309
+ - **Usage**:
310
+ ```python
311
+ doe.Analysis(X, y).matrix_x
312
+ ```
313
+
314
+ #### Methods:
315
+ `anova`
316
+ - Generates and displays a DataFrame summarizing the analysis of variance, includes results for the F-test, p-value, and evaluation of null and alternative hypotheses.
317
+ - **Usage**:
318
+ ```python
319
+ doe.Regression(X, y).effect_analysis()
320
+ ```
321
+
322
+ `regression_plot`
323
+ - Generates and displays the regression plot using the provided matrix data.
324
+ - **Usage**:
325
+ ```python
326
+ doe.Regression(X, y).regression_plot
327
+ ```
328
+ `residual_plot`
329
+ - Generates and displays the residual plot for the experimental data.
330
+ - **Usage**:
331
+ ```python
332
+ doe.Regression(X, y).residual_plot
333
+ ```
334
+
335
+ `histogram_plot`
336
+ - Generates and displays the histogram plot for the distribution of residuals.
337
+ - **Usage**:
338
+ ```python
339
+ doe.Regression(X, y).histogram_plot
340
+ ```
341
+
342
+ `coefficient_error_plot`
343
+ - Generates and displays the confidence intervals for the calculated regression coefficients.
344
+ - **Usage**:
345
+ ```python
346
+ doe.Regression(X, y).coefficient_error_plot
347
+ ```
348
+
349
+ `analysis`
350
+ - Displays Regression plot, Residual plot, Histogram plot, Coefficient error plot.
351
+ - **Usage**:
352
+ ```python
353
+ doe.Regression(X, y).analysis
354
+ ```
355
+
356
+ `coefficient`
357
+ - Generates and displays the table with the model coefficients and if their are significants.
358
+ - **Usage**:
359
+ ```python
360
+ doe.Regression(X, y).coefficient
361
+ ```
362
+
363
+ `curve()`
364
+ - Generates and displays a 1D graph model for better visualization.
365
+ - **Usage**:
366
+ ```python
367
+ doe.Regression(X, y).curve()
368
+ ```
369
+
370
+ `surface()`
371
+ - Generates and displays the response surface model and corresponding contour plot or a 3D surface model for better visualization.
372
+ - **Usage**:
373
+ ```python
374
+ doe.Regression(X, y).surface()
375
+ ```
376
+
377
+ `show_equation()`
378
+ - Displays the model equation.
379
+ - **Usage**:
380
+ ```python
381
+ doe.Regression(X, y).show_equation()
382
+ ```
383
+
384
+ `find_xy()`
385
+ - Finds possible (x, y) values that satisfy the response surface equation for a given z.
386
+ - **Usage**:
387
+ ```python
388
+ doe.Regression(X, y).find_xy()
389
+ ```
390
+
391
+ ## πŸš€ Examples Usage
392
+ Here is an example to demonstrate the functionality of the `Regression` class:
393
+ ```python
394
+ doe.Regression(X,y,yc, type_matrix='interaction', order=2, effect_error='cp').analysis
395
+ ```
396
+ ![imagem](https://github.com/user-attachments/assets/6ac5f2bf-b322-4121-92f0-81fa966991aa)
397
+
398
+ ![imagem](https://github.com/user-attachments/assets/6b5c3238-e40a-4fd7-b0e6-a5e7c049f287)
399
+
400
+ ![imagem](https://github.com/user-attachments/assets/9f6e0cff-5cd2-4bc0-876f-0b0f6c66b325)
401
+
402
+ ![imagem](https://github.com/user-attachments/assets/7e3209ad-b9aa-4852-af70-bc0654d58a57)
403
+
404
+ ```python
405
+ v1=[70,85]
406
+ v2=[6,13.83]
407
+ doe.Regression(X,y,yc, type_matrix='interaction', order=2, effect_error='cp', selected_factors=['Temperature','Alcohol/oil']).surface(v1=v1,v2=v2,plot3D=True, significant_coeff=True)
408
+ ```
409
+ ![imagem](https://github.com/user-attachments/assets/4bba62a7-6df0-4aea-978b-b1560fa126b4)
410
+
411
+ ```python
412
+ v=[16,30]
413
+ doe.Regression(X4,yzn,yczn,effect_error='cp',regression='quadratic',selected_factors=['time/min']).curve(v=v)
414
+ ```
415
+ <img width="802" height="635" alt="imagem" src="https://github.com/user-attachments/assets/c56d0545-36c1-4170-9a7a-72019e21ee81" />
416
+
417
+ # πŸ“ŽNotes:
418
+ - This class is suitable for regression calculations in factorial designs and provides visual and numerical tools for interpreting experimental results. Input data should be formatted appropriately:
419
+ - X: should represent the coded matrix of factors. Interactions can be calculated within this class.
420
+ - y: should be the corresponding response vector or matrix.
421
+ - Graphs:
422
+ - Automatically saved as image files.
423
+
424
+ ## License
425
+ Copyright (C) 2025 Romulo Pires
426
+
427
+ This program is free software: you can redistribute it and/or modify
428
+ it under the terms of the GNU General Public License as published by
429
+ the Free Software Foundation, either version 3 of the License, or any later version.
430
+
431
+ This program is distributed in the hope that it will be useful,
432
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
433
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
434
+ GNU General Public License for more details.
435
+
436
+ You should have received a copy of the GNU General Public License
437
+ along with this program. If not, see <https://www.gnu.org/licenses/>.