Model Diagnostics

After fitting, verify that OLS assumptions hold.

Box-Cox

ravix.box_cox(model)

Ravix Box-Cox log-likelihood plot for selecting a variance-stabilizing transformation

Heteroscedasticity — ravix.bp() and ravix.ncv()

Two complementary tests for non-constant residual variance. bp() runs the Modified Breusch-Pagan test; ncv() runs the Cook-Weisberg score test.

ravix.bp(model)
Breusch-Pagan Test for Heteroscedasticity
=======================================================
Test Statistic      : 1.1226
p-value             : 0.7716
Result              : Homoscedastic (p >= 0.05)
=======================================================
ravix.ncv(model)
Nonconstant Variance Test
=======================================================
Test Statistic      : 1.3498
p-value             : 0.2453
Result              : Constant variance (p >= 0.05)
=======================================================

Normality — ravix.shapiro()

ravix.shapiro(model)
Shapiro-Wilk Test for Normality
=======================================================
Test Statistic      : 0.9842
p-value             : 0.2769
Result              : Normal (p >= 0.05)
=======================================================

Residual histogram — ravix.hist()

ravix.hist(model)

Ravix residual histogram for regression diagnostics

ravix.hist(model, norm = False, bins = 20)

Ravix residual histogram with 20 bins and raw counts instead of a normal curve overlay

Variance Inflation Factors — ravix.vif()

Same call pattern as ravix.ols() — pass a formula and DataFrame directly.

ravix.vif("Price ~ .", df)
      TaxRate  Commercial    Income     Rooms
VIF  1.009601    1.059649  1.215393  1.268351
ravix.vif("Price ~ .", df, plot = True)
      TaxRate  Commercial    Income     Rooms
VIF  1.009601    1.059649  1.215393  1.268351

Ravix variance inflation factor (VIF) bar plot for detecting multicollinearity

Q-Q plot — ravix.qq()

ravix.qq(model)

Ravix Q-Q plot for assessing residual normality

Cook’s distance — ravix.plot_cook()

ravix.plot_cook(model)

Ravix Cook's distance plot for identifying influential observations

Textbook reference: Diagnostics are covered in Chapter 8 of Applied Linear Regression for Business Analytics with Python.

On this page