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.6.tar.gz (11.0 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.6-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: assumphelper-0.1.6.tar.gz
  • Upload date:
  • Size: 11.0 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.6.tar.gz
Algorithm Hash digest
SHA256 35387a7dc7859d6034c846576643875eb5d8c67f0cc980e35c4f2bc22bb46272
MD5 7a06a4f19177d7260bdaf43e3ee73bae
BLAKE2b-256 3bae3ecae78a468795d16af722534359c4b7946d2b2fa3afe891960d1ff57133

See more details on using hashes here.

File details

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

File metadata

  • Download URL: assumphelper-0.1.6-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.6-py3-none-any.whl
Algorithm Hash digest
SHA256 017520ce5583ddbc83ef6622e12c45704ddce564f3f4e491cb9d5e03e440fb2c
MD5 8fa6e197835c01a357070132f47f4671
BLAKE2b-256 a00d364e8806ecf0e665a4e2ad8e7b7c1cac2acbfdbc7b2bf9f26e903d4c2a48

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