Analysis¶
Statistical analysis of collected experimental results.
ANOVA¶
industrialstats.analysis.anova ¶
ANOVA analysis for experimental designs.
ANOVAAnalysis ¶
Perform ANOVA analysis on experimental data.
Initialize an ANOVA analysis instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Experimental dataset. |
required |
response_column
|
str
|
Name of the response variable column. |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in src/industrialstats/analysis/anova.py
fit_model ¶
Fit a linear model using an R-style formula.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
formula
|
str
|
Formula string such as |
required |
Returns:
| Type | Description |
|---|---|
RegressionResultsWrapper
|
Fitted model instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the model fails to fit. |
Source code in src/industrialstats/analysis/anova.py
anova_table_calculation ¶
Compute the ANOVA table for the fitted model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typ
|
int
|
ANOVA type (1, 2, or 3). Defaults to 2. |
2
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Table with sums of squares, degrees of freedom and statistics. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no model has been fitted or calculation fails. |
Source code in src/industrialstats/analysis/anova.py
multiple_comparisons ¶
Run multiple comparison tests on a factor.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
factor
|
str
|
Factor name for pairwise comparisons. |
required |
method
|
str
|
Comparison method ( |
'tukey'
|
alpha
|
float
|
Family-wise error rate. Defaults to 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Pairwise comparison results. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the factor is not present in the data or the method is unsupported. |
Source code in src/industrialstats/analysis/anova.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | |
residual_analysis ¶
Perform comprehensive residual analysis.
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
Dictionary containing various residual statistics. |
Source code in src/industrialstats/analysis/anova.py
assumptions_tests ¶
Test ANOVA assumptions.
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]]
|
Test results for normality, homogeneity of variance, and independence. |
Source code in src/industrialstats/analysis/anova.py
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 | |
model_summary ¶
Get comprehensive model summary.
Returns:
| Type | Description |
|---|---|
dict
|
Model fit statistics and summary information. |
Source code in src/industrialstats/analysis/anova.py
contrast_analysis ¶
Perform contrast analysis.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
contrasts
|
dict[str, list[float]]
|
Mapping of contrast names to coefficient vectors. |
required |
factor
|
str
|
Factor name for the contrasts. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Contrast analysis results. |
Source code in src/industrialstats/analysis/anova.py
411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 | |
power_analysis_post_hoc ¶
Calculate observed power for each effect in the model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
alpha
|
float
|
Significance level. Defaults to 0.05. |
0.05
|
Returns:
| Type | Description |
|---|---|
dict[str, float]
|
Observed power for each effect. |
Source code in src/industrialstats/analysis/anova.py
mixed_effects_model ¶
mixed_effects_model(fixed_effects: list[str], random_effects: list[str], nested_effects: list[str] | None = None) -> dict[str, Any]
Fit a mixed-effects model with optional nesting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fixed_effects
|
list[str]
|
Factors treated as fixed effects in the model. |
required |
random_effects
|
list[str]
|
Random-effect factors. The first entry specifies the grouping variable used for the random intercept. |
required |
nested_effects
|
list[str]
|
Random effects nested within the main grouping factor. Each entry is treated as a variance component. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Contains the following keys:
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If a specified factor is not present in the data. |
Source code in src/industrialstats/analysis/anova.py
534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 | |
unbalanced_anova ¶
Perform Type II ANOVA for unbalanced designs.
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing the ANOVA table. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If no model has been fitted. |
Source code in src/industrialstats/analysis/anova.py
nested_anova ¶
Perform nested ANOVA for hierarchical designs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
nesting_structure
|
dict[str, str]
|
Mapping of nested factor to its parent factor. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with the ANOVA table. |
Source code in src/industrialstats/analysis/anova.py
repeated_measures_anova ¶
Analyze repeated measures designs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
subject_column
|
str
|
Identifier for each experimental unit. |
required |
within_factors
|
list[str]
|
Factors measured repeatedly. |
required |
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary with the ANOVA table. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If specified columns are not in the data. |
Source code in src/industrialstats/analysis/anova.py
Split-plot inference¶
Split-plot experiments have two randomization stages and therefore two error strata. Whole-plot-only treatment terms must be tested against whole-plot error; terms containing subplot factors must be tested against subplot error.
Source: ../diagrams/split_plot_inference.dot
The classical stratum-specific F tests and the random-intercept mixed model answer complementary questions. A generic OLS residual denominator is not valid for whole-plot treatment effects, and mixed-model Wald tests are not substituted for the classical balanced split-plot F tests.
industrialstats.analysis.split_plot ¶
Inference helpers for balanced complete split-plot experiments.
SplitPlotErrorStrata
dataclass
¶
SplitPlotErrorStrata(whole_plot_treatments: int, subplot_treatments: int, replicates: int, whole_plots: int, runs: int, whole_plot_error_df: int, subplot_error_df: int)
Balanced split-plot experimental-unit and error-stratum summary.
SplitPlotAnalysis ¶
SplitPlotAnalysis(data: DataFrame, response_column: str, whole_plot_factors: list[str], subplot_factors: list[str], *, whole_plot_column: str = 'WholePlot', replicate_column: str = 'Replicate')
Validate and analyse a balanced complete split-plot experiment.
Source code in src/industrialstats/analysis/split_plot.py
error_strata ¶
error_strata() -> SplitPlotErrorStrata
Return balanced whole-plot and subplot error-stratum degrees of freedom.
Source code in src/industrialstats/analysis/split_plot.py
anova_table ¶
Return the classical balanced split-plot ANOVA table.
Whole-plot-only treatment terms are tested against WholePlot Error.
Terms containing at least one subplot factor are tested against
Subplot Error. Sums of squares use orthogonal Helmert-contrast
projections, so the decomposition is invariant to row order and to
arbitrary treatment labels.
Returns:
| Type | Description |
|---|---|
DataFrame
|
ANOVA table with source, randomization stratum, degrees of freedom, sums of squares, mean squares, F statistics, p-values, and the denominator error term used for each fixed effect. |
Source code in src/industrialstats/analysis/split_plot.py
141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 | |
expected_mean_squares ¶
Return error-stratum EMS values for the random-intercept split-plot model.
Source code in src/industrialstats/analysis/split_plot.py
fit_mixed_model ¶
Fit the full fixed-treatment split-plot model with a random whole-plot intercept.
Source code in src/industrialstats/analysis/split_plot.py
Effects¶
industrialstats.analysis.effects ¶
Effect analysis with canonical two-level factorial contrast semantics.
EffectsAnalysis ¶
Bases: EffectsAnalysis
Calculate factorial effects with one canonical two-level convention.
Complete balanced two-level factorials use the same -1/+1 orthogonal
contrast engine as :meth:industrialstats.designs.factorial.FactorialDesign.calculate_effects.
Multi-level and incomplete layouts retain the established analysis paths.
Initialize effect analysis and exclude known design metadata columns.
Source code in src/industrialstats/analysis/effects.py
calculate_main_effects ¶
Calculate main effects, using canonical contrasts for complete 2^k data.
Source code in src/industrialstats/analysis/effects.py
calculate_interaction_effects ¶
Calculate interaction effects under the canonical factorial convention.
Source code in src/industrialstats/analysis/effects.py
Model fitting¶
industrialstats.analysis.model_fitting ¶
Advanced model fitting and selection for experimental data.
ModelFitting ¶
Advanced model fitting with automatic term selection and validation.
Initialize model fitting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
Experimental data. |
required |
response_column
|
str
|
Name of the response variable. |
required |
Source code in src/industrialstats/analysis/model_fitting.py
stepwise_selection ¶
stepwise_selection(entry_threshold: float = 0.05, removal_threshold: float = 0.1, max_terms: int | None = None) -> dict[str, Any]
Perform stepwise model selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entry_threshold
|
float
|
P-value threshold for entering terms, by default |
0.05
|
removal_threshold
|
float
|
P-value threshold for removing terms, by default |
0.1
|
max_terms
|
int
|
Maximum number of terms in the model. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Stepwise selection results. |
Source code in src/industrialstats/analysis/model_fitting.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
hierarchical_fitting ¶
Fit hierarchical models while respecting effect hierarchy.
Terms are added in increasing order of interaction degree. A term is only
considered if all of its lower-order components are already present in the
model, enforcing the principle described by Montgomery [1]_. Each
candidate term is fit and retained when its p-value is below
significance_level.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_order
|
int
|
Maximum interaction order. For example, |
3
|
significance_level
|
float
|
Significance level for term inclusion. Default is |
0.05
|
Returns:
| Type | Description |
|---|---|
dict
|
Dictionary containing selected terms and fitted model statistics. |
See Also
stepwise_selection Forward/backward stepwise regression based on information criteria. all_subsets_selection Exhaustive model search for small factor sets.
Examples:
>>> from industrialstats.analysis.model_fitting import ModelFitting
>>> import pandas as pd
>>> df = pd.DataFrame(
... {"A": [1, -1, 1, -1], "B": [1, 1, -1, -1], "y": [4, 2, 3, 1]}
... )
>>> fitter = ModelFitting(df, response_column="y")
>>> res = fitter.hierarchical_fitting(max_order=1)
>>> res["selected_terms"]
['Intercept', 'A', 'B']
References
.. [1] Montgomery, D.C. (2017). Design and Analysis of Experiments. 9th ed. Wiley.
Source code in src/industrialstats/analysis/model_fitting.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | |
all_subsets_selection ¶
Perform all possible subsets selection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
criterion
|
str
|
Selection criterion: |
"AIC"
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
All subsets results. |
Source code in src/industrialstats/analysis/model_fitting.py
290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
cross_validation ¶
cross_validation(model_terms: list[str], k_folds: int = 5, random_state: int | None = None) -> dict[str, Any]
Perform k-fold cross-validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_terms
|
list of str
|
Model terms to validate. |
required |
k_folds
|
int
|
Number of folds, by default 5. |
5
|
random_state
|
int
|
Seed for reproducible splitting. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Cross-validation results. |
Source code in src/industrialstats/analysis/model_fitting.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 | |
bootstrap_validation ¶
bootstrap_validation(model_terms: list[str], n_bootstrap: int = 100, random_state: int | None = None) -> dict[str, Any]
Perform bootstrap validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_terms
|
list of str
|
Model terms to validate. |
required |
n_bootstrap
|
int
|
Number of bootstrap samples, by default 100. |
100
|
random_state
|
int
|
Seed for reproducible resampling. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Bootstrap validation results. |
Source code in src/industrialstats/analysis/model_fitting.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 | |
regularized_fitting ¶
regularized_fitting(method: str = 'lasso', alphas: Sequence[float] | None = None, cv: int = 5, l1_ratio: float = 0.5, plot_path: bool = False, random_state: int | None = None) -> dict[str, Any]
Fit linear models with regularization and cross-validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
method
|
(lasso, ridge, elasticnet)
|
Regularization technique to use. Default is |
"lasso"
|
alphas
|
sequence of float
|
Grid of regularization strengths to evaluate. If |
None
|
cv
|
int
|
Number of cross-validation folds. Default is |
5
|
l1_ratio
|
float
|
Elastic net mixing parameter, with |
0.5
|
plot_path
|
bool
|
If |
False
|
random_state
|
int
|
Seed for reproducible cross-validation splits. |
None
|
Returns:
| Type | Description |
|---|---|
dict
|
Results containing fitted model, selected features, and path data. |
References
.. [1] Tibshirani, R. (1996). Regression shrinkage and selection via the lasso. Journal of the Royal Statistical Society: Series B. .. [2] Zou, H., & Hastie, T. (2005). Regularization and variable selection via the elastic net. Journal of the Royal Statistical Society: Series B.
Source code in src/industrialstats/analysis/model_fitting.py
597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 | |
model_comparison ¶
Compare multiple models using various criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_list
|
list of list of str
|
List of model term lists to compare. |
required |
Returns:
| Type | Description |
|---|---|
DataFrame
|
Model comparison table. |
Source code in src/industrialstats/analysis/model_fitting.py
residual_diagnostics ¶
Perform comprehensive residual diagnostics.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_terms
|
List[str]
|
Model terms to diagnose. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Diagnostic results. |
Source code in src/industrialstats/analysis/model_fitting.py
904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | |
lack_of_fit_test ¶
Perform lack-of-fit test for models with replicates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_terms
|
List[str]
|
Model terms to test. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Lack-of-fit test results. |
Source code in src/industrialstats/analysis/model_fitting.py
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 | |
Diagnostics¶
Model diagnostics are a decision process, not a single goodness-of-fit number. The package combines formal assumption checks, influence diagnostics, explicit outlier thresholds, residual plots, and an adequacy summary before producing remediation guidance.
Source: ../diagrams/model_diagnostics.dot
Formal assumption tests should be interpreted together with residual plots and influence measures. A model can pass a normality or variance test and still contain observations with enough leverage or Cook's distance to destabilize inference; conversely, a flagged point should be investigated rather than deleted automatically.
industrialstats.analysis.diagnostics ¶
Comprehensive regression diagnostics.
This module implements residual diagnostics described by Cook & Weisberg
(1982) and extends classical assumption checks with actionable guidance.
The :class:ModelDiagnostics class operates on dictionaries returned by the
high-level fitting utilities in :mod:industrialstats.analysis.model_fitting
and requires the original design data to contextualize the diagnostics.
Examples:
>>> import pandas as pd
>>> import numpy as np
>>> import statsmodels.api as sm
>>> from industrialstats.analysis.diagnostics import ModelDiagnostics
>>> rng = np.random.default_rng(42)
>>> x1 = rng.normal(size=120)
>>> x2 = rng.normal(size=120)
>>> y = 1.5 + 2.0 * x1 - 1.2 * x2 + rng.normal(size=120)
>>> data = pd.DataFrame({"y": y, "x1": x1, "x2": x2})
>>> model = sm.OLS(data["y"], sm.add_constant(data[["x1", "x2"]])).fit()
>>> model_result = {
... "model_object": model,
... "residuals": model.resid,
... "fitted_values": model.fittedvalues,
... "model_metrics": {"R2": model.rsquared},
... }
>>> diagnostics = ModelDiagnostics(model_result, data)
>>> summary = diagnostics.assumption_tests()
>>> round(summary["normality"]["shapiro"]["p_value"], 3) >= 0.05
True
ModelDiagnostics ¶
Diagnostic analytics for linear models.
The diagnostics follow the influence framework of Cook & Weisberg [1]_ and
are compatible with dictionaries returned by
:class:~industrialstats.analysis.model_fitting.ModelFitting.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_result
|
Dict[str, Any]
|
Dictionary containing the fitted |
required |
data
|
DataFrame
|
Original dataset used during model fitting. The frame is copied to avoid inadvertent mutation during diagnostics. |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
If |
KeyError
|
When mandatory keys are absent from |
ValueError
|
If residual and fitted vector lengths are inconsistent with |
References
.. [1] Cook, R. D., & Weisberg, S. (1982). Residuals and Influence in Regression. Chapman & Hall/CRC.
Source code in src/industrialstats/analysis/diagnostics.py
assumption_tests ¶
Evaluate classical regression assumptions.
The procedure combines the Shapiro-Wilk and Anderson-Darling tests for normality, Levene and Bartlett tests for homoscedasticity across fitted quantile groups, and the Durbin-Watson statistic for independence.
Returns:
| Type | Description |
|---|---|
Dict[str, Dict[str, Any]]
|
Nested mapping summarising each assumption. For example,
The Anderson-Darling entry reports whichever evidence the installed
SciPy can supply: |
Examples:
>>> tests = diagnostics.assumption_tests()
>>> sorted(tests.keys())
['homoscedasticity', 'independence', 'normality']
>>> tests["independence"]["passes"]
True
Source code in src/industrialstats/analysis/diagnostics.py
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 | |
influence_analysis ¶
Compute influence diagnostics under the Cook & Weisberg framework.
Returns:
| Type | Description |
|---|---|
Dict[str, ndarray]
|
Arrays of studentized residuals, Cook's distances, DFFITS, leverage, and DFBETAS for each observation. |
Examples:
>>> influence = diagnostics.influence_analysis()
>>> {k: v.shape for k, v in influence.items()}["leverage"]
(120,)
Source code in src/industrialstats/analysis/diagnostics.py
outlier_detection ¶
Identify influential observations with multiple criteria.
Returns:
| Type | Description |
|---|---|
Dict[str, List[int]]
|
Observation indices flagged by studentized residual, Cook's distance and DFBETAS thresholds. Indices are returned in ascending order. |
Examples:
Source code in src/industrialstats/analysis/diagnostics.py
model_adequacy ¶
Summarise overall adequacy of the fitted model.
The summary merges assumption test outcomes, influence diagnostics, and model fit statistics. Diagnostic plots for residual behaviour and Cook's distance are included to support expert review.
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dictionary with keys |
Examples:
>>> adequacy = diagnostics.model_adequacy()
>>> sorted(adequacy["plots"].keys())
['cook_distance', 'qq_plot', 'residuals_vs_fitted']
Source code in src/industrialstats/analysis/diagnostics.py
recommendation_system ¶
Produce actionable recommendations based on diagnostics.
Recommendations interpret assumption violations and influential point detections to guide remedial strategies such as variance-stabilising transformations, robust regression, or data review.
Returns:
| Type | Description |
|---|---|
List[str]
|
Human-readable recommendations ordered by severity. |
Examples:
>>> diagnostics.recommendation_system()
['No major issues detected. Consider validating on a holdout set.']
Source code in src/industrialstats/analysis/diagnostics.py
Power analysis¶
industrialstats.analysis.power_analysis ¶
Power analysis and sample size determination for experimental designs.
PowerAnalysisResult
dataclass
¶
PowerAnalysisResult(effect_size: float, alpha: float, power: float, sample_size: int, test_type: str, additional_info: dict[str, Any])
Container for power analysis results.
PowerAnalysis ¶
Comprehensive power analysis for experimental designs.
Supports power calculations for t-tests, ANOVA, factorial designs, and regression models.
Initialize power analysis.
Source code in src/industrialstats/analysis/power_analysis.py
t_test_power ¶
t_test_power(effect_size: float | None = None, alpha: float = 0.05, power: float | None = None, sample_size: int | None = None, test_type: str = 'two_sample') -> PowerAnalysisResult
Power analysis for t-tests.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_size
|
float
|
Cohen's d effect size. |
None
|
alpha
|
float
|
Type I error rate. Defaults to 0.05. |
0.05
|
power
|
float
|
Statistical power ( |
None
|
sample_size
|
int
|
Sample size per group. |
None
|
test_type
|
str
|
Type of t-test ( |
'two_sample'
|
Returns:
| Type | Description |
|---|---|
PowerAnalysisResult
|
Power analysis results. |
Source code in src/industrialstats/analysis/power_analysis.py
anova_power ¶
anova_power(effect_size: float | None = None, alpha: float = 0.05, power: float | None = None, sample_size: int | None = None, n_groups: int = 3) -> PowerAnalysisResult
Power analysis for one-way ANOVA.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_size
|
float
|
Cohen's |
None
|
alpha
|
float
|
Type I error rate. Defaults to 0.05. |
0.05
|
power
|
float
|
Desired power. |
None
|
sample_size
|
int
|
Sample size per group. |
None
|
n_groups
|
int
|
Number of groups. Defaults to 3. |
3
|
Returns:
| Type | Description |
|---|---|
PowerAnalysisResult
|
Power analysis results. |
Source code in src/industrialstats/analysis/power_analysis.py
116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 | |
factorial_power ¶
factorial_power(effect_size: float | None = None, alpha: float = 0.05, power: float | None = None, replicates: int | None = None, factor_levels: list[int] | None = None, effect: tuple[int, ...] | None = None) -> PowerAnalysisResult
Power analysis for factorial designs.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_size
|
float
|
Cohen's |
None
|
alpha
|
float
|
Type I error rate. Defaults to 0.05. |
0.05
|
power
|
float
|
Statistical power. |
None
|
replicates
|
int
|
Number of replicates. |
None
|
factor_levels
|
list of int
|
Number of levels for each factor. Defaults to |
None
|
effect
|
tuple of int
|
Indices of factors forming the effect of interest. |
None
|
Returns:
| Type | Description |
|---|---|
PowerAnalysisResult
|
Power analysis results. |
Source code in src/industrialstats/analysis/power_analysis.py
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
regression_power ¶
regression_power(effect_size: float | None = None, alpha: float = 0.05, power: float | None = None, sample_size: int | None = None, n_predictors: int = 1) -> PowerAnalysisResult
Power analysis for multiple regression.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_size
|
float
|
Cohen's :math: |
None
|
alpha
|
float
|
Type I error rate. Defaults to 0.05. |
0.05
|
power
|
float
|
Statistical power. |
None
|
sample_size
|
int
|
Total sample size. |
None
|
n_predictors
|
int
|
Number of predictors in the model. Defaults to 1. |
1
|
Returns:
| Type | Description |
|---|---|
PowerAnalysisResult
|
Power analysis results. |
Source code in src/industrialstats/analysis/power_analysis.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 | |
power_curve ¶
power_curve(test_type: str, fixed_params: dict[str, Any], varying_param: str, param_range: list[float]) -> dict[str, Any]
Generate power curve by varying one parameter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_type
|
str
|
Type of test ( |
required |
fixed_params
|
dict
|
Fixed parameters for the analysis. |
required |
varying_param
|
str
|
Parameter to vary ( |
required |
param_range
|
list of float
|
Range of values for the varying parameter. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Power curve data and the generated plot. |
Source code in src/industrialstats/analysis/power_analysis.py
375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 | |
factorial_power_curve ¶
factorial_power_curve(effect_sizes: list[float], alpha: float = 0.05, replicates: int = 1, factor_levels: list[int] | None = None, effect: tuple[int, ...] | None = None) -> dict[str, Any]
Generate power curve for factorial designs over effect sizes.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effect_sizes
|
list of float
|
Effect sizes to evaluate. |
required |
alpha
|
float
|
Type I error rate. Defaults to 0.05. |
0.05
|
replicates
|
int
|
Number of replicates per treatment combination. Defaults to |
1
|
factor_levels
|
list of int
|
Number of levels for each factor. Defaults to |
None
|
effect
|
tuple of int
|
Indices of factors forming the effect of interest. Defaults to
|
None
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Power curve data and the generated figure. |
Source code in src/industrialstats/analysis/power_analysis.py
sample_size_table ¶
sample_size_table(test_type: str, effect_sizes: list[float], powers: list[float] | None = None, alpha: float = 0.05, **kwargs) -> DataFrame
Generate sample size table for different effect sizes and powers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_type
|
str
|
Type of test. |
required |
effect_sizes
|
list of float
|
Effect sizes to include. |
required |
powers
|
list of float
|
Power levels to include. Defaults to |
None
|
alpha
|
float
|
Type I error rate. Defaults to 0.05. |
0.05
|
**kwargs
|
Additional parameters for specific tests. |
{}
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
Sample size table. |
Source code in src/industrialstats/analysis/power_analysis.py
minimum_detectable_effect ¶
minimum_detectable_effect(test_type: str, alpha: float = 0.05, power: float = 0.8, sample_size: int = 20, **kwargs) -> PowerAnalysisResult
Calculate minimum detectable effect for a given design.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
test_type
|
str
|
Type of test. |
required |
alpha
|
float
|
Type I error rate. Defaults to 0.05. |
0.05
|
power
|
float
|
Statistical power. Defaults to 0.8. |
0.8
|
sample_size
|
int
|
Sample size. Defaults to 20. |
20
|
**kwargs
|
Additional parameters for specific tests. |
{}
|
Returns:
| Type | Description |
|---|---|
PowerAnalysisResult
|
Analysis with minimum detectable effect. |
Source code in src/industrialstats/analysis/power_analysis.py
summary_report ¶
Generate summary report of all power analyses performed.