Skip to main content

Linear Regression Assumption Interpretation Guide

Project description

AssumHelp

Overview

This Jupyter notebook provides a comprehensive framework for testing the fundamental assumptions of linear regression models. It implements automated diagnostic tools to check whether your regression model meets the statistical requirements necessary for valid inference and prediction. Python 3.7+ License: MIT

Purpose

Linear regression models rely on several key assumptions to produce reliable results. Violations of these assumptions can lead to biased estimates, incorrect standard errors, and unreliable predictions. This notebook provides a systematic approach to:

Test regression assumptions using formal statistical tests Visualize diagnostic plots to identify assumption violations Interpret results with clear, actionable guidance Generate comprehensive reports summarizing all diagnostic findings

Key Features

🧪 Statistical Tests Implemented

Ramsey RESET Test - Tests for linearity assumptions

Breusch-Pagan Test - Tests for homoscedasticity (constant variance)

Shapiro-Wilk Test - Tests for normality of residuals

Durbin-Watson Test - Tests for independence of residuals

Developers

[Kirstine Roise G. Moog]

Our distinguish Leader & Inceptionist & Structural Design

[Rodel P. Badilla]

Our Assistant Leader

Leaders Roles

  • Designed clean separation of concerns
  • Implementing codes engine
  • Created visualization tools
  • Enhanced plotting capabilities

[Hannah Dennisse Y. Aque]

[James Walte C. Prollo]

[Zell Caamino]

Roles

Back (support)

  • Built comprehensive test suite
  • Wrote user documentation.
  • Quality assurance

📊 Diagnostic Visualizations

Residuals vs Fitted Plot - Linearity and homoscedasticity assessment

Scale-Location Plot - Homoscedasticity verification

Q-Q Plot - Normality assessment

Residuals vs Order Plot - Independence verification

🎯 Automated Interpretation

Built-in interpretation guides for all statistical tests Clear guidance on what to look for in diagnostic plots Automated result summaries with actionable recommendations

Architecture

Core Classes

Hypothesis (Base Class)

The foundational class that stores regression models and data, providing common functionality for all diagnostic tests.

Linearity

Purpose: Tests the linearity assumption Methods: test_linearity(), plot_linearity() Test: Ramsey RESET test Plot: Residuals vs Fitted values

Homoscedasticity

Purpose: Tests for constant variance of residuals Methods: test_homoscedasticity(), plot_homoscedasticity() Test: Breusch-Pagan test Plot: Scale-Location plot

Normality

Purpose: Tests normality of residuals Methods: test_normality(), plot_normality() Test: Shapiro-Wilk test Plot: Q-Q plot

Independence

Purpose: Tests independence of residuals Methods: test_independence(), plot_independence() Test: Durbin-Watson statistic Plot: Residuals vs Order plot

DiagnosticSummary

Purpose: Comprehensive reporting of all diagnostic results Methods: show_summary() Features: Consolidated results and interpretations

Dependencies

import numpy as np import pandas as pd import scipy.stats as sp from scipy.stats import f import statsmodels.api as sm import matplotlib.pyplot as plt import sklearn as sk import os

Required packages:

numpy - Numerical computations pandas - Data manipulation scipy - Statistical tests statsmodels - Regression analysis and statistical tests matplotlib - Plotting and visualization scikit-learn - Machine learning utilities

Installation

Install the required packages using pip:

pip install AssumpHelp

Usage

Basic Workflow Prepare your data and model

Your regression model (scikit-learn or similar)

model = YourRegressionModel()
X = your_features
y = your_target
Initialize diagnostic classes

linearity_test = Linearity(model, X, y)
homoscedasticity_test = Homoscedasticity(model, X, y)
normality_test = Normality(model, X, y)
independence_test = Independence(model, X, y)
Run tests and generate plots

# Test assumptions
linearity_test.test_linearity()
linearity_test.plot_linearity()

homoscedasticity_test.test_homoscedasticity()
homoscedasticity_test.plot_homoscedasticity()

normality_test.test_normality()
normality_test.plot_normality()

independence_test.test_independence()
independence_test.plot_independence()
Generate comprehensive summary

summary = DiagnosticSummary(linearity_test, homoscedasticity_test, 
                          normality_test, independence_test)
summary.show_summary()

Advanced Features

Feature Scaling

Use the fit_transform() method to standardize features before testing:

linearity_test.fit_transform() Custom Interpretation The notebook includes built-in interpretation guides that provide:

Clear explanations of p-value significance,Visual cues for plot interpretation,Actionable recommendations for addressing violations Statistical Tests Explained

Ramsey RESET Test

Null Hypothesis: The model is correctly specified (linear) Alternative Hypothesis: The model is misspecified (non-linear relationships exist) Interpretation: High p-value (> 0.05) suggests linearity is maintained

Breusch-Pagan Test

Null Hypothesis: Homoscedasticity (constant variance) Alternative Hypothesis: Heteroscedasticity (non-constant variance) Interpretation: High p-value (> 0.05) suggests homoscedasticity is maintained

Shapiro-Wilk Test

Null Hypothesis: Residuals are normally distributed Alternative Hypothesis: Residuals are not normally distributed Interpretation: High p-value (> 0.05) suggests normality is maintained

Durbin-Watson Test

Range: 0 to 4 Interpretation: ~2.0: No autocorrelation < 2.0: Positive autocorrelation 2.0: Negative autocorrelation

Diagnostic Plots Guide

Residuals vs Fitted Plot Look for: Random scatter around zero Problem indicators: Patterns, curves, or funnel shapes Indicates: Linearity and homoscedasticity issues

Scale-Location Plot

Look for: Horizontal line with random spread Problem indicators: Increasing/decreasing spread Indicates: Heteroscedasticity

Q-Q Plot

Look for: Points following the straight line Problem indicators: S-shaped curves or deviations at tails Indicates: Non-normality

Residuals vs Order Plot

Look for: Random scatter with no patterns Problem indicators: Trends, cycles, or autocorrelation Indicates: Independence violations

Common Issues and Solutions

Linearity Violations

Solutions: Transform variables, add polynomial terms, use non-linear models

Heteroscedasticity

Solutions: Transform dependent variable, use weighted least squares, robust standard errors

Non-Normality

Solutions: Transform variables, increase sample size, use non-parametric methods

The framework generates:

Statistical test results with test statistics and p-values Diagnostic plots with interpretation guides Comprehensive summary consolidating all findings Actionable recommendations for addressing violations

Best Practices

Always test assumptions before interpreting regression results Use multiple diagnostic methods (both tests and plots) Consider sample size when interpreting test results Address violations systematically rather than ignoring them Document all diagnostic procedures for reproducibility

Limitations

Tests assume sufficient sample size for reliable results Some tests are sensitive to outliers Visual interpretation requires experience and judgment Multiple testing may increase Type I error rates

Contributing

This framework is designed to be extensible. Common enhancements include:

Additional statistical tests Custom visualization options Integration with other modeling frameworks Automated remediation suggestions

License

This project is licensed under the MIT License – see the LICENSE file for details.

Note: This diagnostic framework helps ensure the validity of your regression analysis by systematically checking fundamental statistical assumptions. Regular use of these tools will improve the reliability and interpretability of your regression models.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

assumphelper-0.1.4.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

assumphelper-0.1.4-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file assumphelper-0.1.4.tar.gz.

File metadata

  • Download URL: assumphelper-0.1.4.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for assumphelper-0.1.4.tar.gz
Algorithm Hash digest
SHA256 9a51ccd4fa1af91d475cb09c2d5fcdd0c1096453d5f5884eb6292db41c5382d5
MD5 04e397a354c3d8cd0059c0959d3a56a5
BLAKE2b-256 61bc87d3011ab980aaad9b16243b6613944ea44baf946e01d7ef994a0d930250

See more details on using hashes here.

File details

Details for the file assumphelper-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: assumphelper-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for assumphelper-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3cc7c68d9dc72fce0b45daf01c580cbe01500fded7791fb01a362f44827385f2
MD5 2885f4a14ae148af7c3bb5e33aed5dfc
BLAKE2b-256 98cdd968f274907a1ea5ce34108e7851d49b0ab792211793eb60b59425a1a53d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page