Skip to content

How to Fix Python StatsModels Summary Not Displaying

DodaTech Updated 2026-06-24 2 min read

In this tutorial, you'll learn about How to Fix Python StatsModels Summary Not Displaying. We cover key concepts, practical examples, and best practices.

StatsModels raises ValueError or displays a truncated summary when the model has not been fitted, the design matrix is singular, or the terminal width is narrow.

The Wrong Way

import statsmodels.api as sm
import pandas as pd

df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [2, 4, 5, 4]})
model = sm.OLS(df["y"], df[["x"]])
print(model.fit().summary())

If the model has too many variables or collinearity:

ValueError: singular matrix

The Right Way

import statsmodels.api as sm
import pandas as pd
import numpy as np

df = pd.DataFrame({"x": [1, 2, 3, 4], "y": [2, 4, 5, 4]})

# Add constant for intercept
X = sm.add_constant(df["x"])

model = sm.OLS(df["y"], X)
results = model.fit()

print(results.summary())

Output:

                            OLS Regression Results
==============================================================================
Dep. Variable:                      y   R-squared:                       0.875
Model:                            OLS   Adj. R-squared:                  0.812
Method:                 Least Squares   F-statistic:                     14.00
Date:                Wed, 24 Jun 2026   Prob (F-statistic):             0.0645
==============================================================================
                 coef    std err          t      P>|t|      [0.025      0.975]
------------------------------------------------------------------------------
const          1.0000      1.528      0.655      0.580      -5.575       7.575
x              1.1000      0.294      3.742      0.065      -0.164       2.364
==============================================================================

Prevention Tips

  • Add a constant with sm.add_constant() for intercept.
  • Check for singular matrices with np.linalg.matrix_rank().
  • Use results.summary2() for an alternative summary format.
  • Set pd.set_option("display.max_columns", 10) for wider output.
  • Use results.params and results.pvalues for programmatic access.

Common Mistakes with statsmodels summary

  1. Using head and tail instead of pattern matching, causing runtime errors on empty lists
  2. Forgetting that lazy evaluation defers computation until the value is forced, causing space leaks with unevaluated thunks
  3. Using return to exit a function early instead of wrapping a pure value in the monad

These mistakes appear frequently in real-world PYTHON code. DodaTech's contributors have identified these patterns through analysis of open-source projects and production systems.

Practice Exercise

Write a pure function that safely divides two integers using Maybe, then test it with edge cases like division by zero and negative numbers.

This exercise reinforces the concepts covered in this guide. Try implementing it before checking online solutions.

FAQ

### What does "singular matrix" mean in OLS?

The design matrix has linearly dependent columns. One predictor is a linear combination of others. Drop correlated variables or use regularization (ridge regression).

How do I access individual values from the summary?

Use results.params for coefficients, results.pvalues for p-values, results.rsquared for R-squared, and results.conf_int() for confidence intervals.

What is the difference between statsmodels and sklearn for regression?

StatsModels provides inferential statistics (p-values, confidence intervals, hypothesis tests). sklearn focuses on prediction accuracy. Use StatsModels for explanation, sklearn for prediction.

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro