statsmodels
ScienceStatistical analysis
What is statsmodels?
Statsmodels is a Python library that provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests and exploring statistical data. It complements SciPy with a higher-level interface for regression, time-series analysis, nonparametric statistics, and more.
With PyRun, you can fit OLS regression models, run hypothesis tests, and explore statistical summaries directly in your browser. Statsmodels is bundled in the Pyodide distribution, so you can start analysing data immediately without any local Python setup.
Code Example
Fit and evaluate an ordinary least-squares model.
import statsmodels.api as sm
import numpy as np
np.random.seed(42)
x = np.linspace(0, 10, 50)
y = 3 * x + 7 + np.random.normal(0, 2, size=50)
X = sm.add_constant(x)
model = sm.OLS(y, X).fit()
print("OLS Regression Results")
print("=" * 40)
print(f"R-squared : {model.rsquared:.4f}")
print(f"Intercept : {model.params[0]:.4f} (true: 7)")
print(f"Slope : {model.params[1]:.4f} (true: 3)")
print(f"P-values : {model.pvalues.round(4).tolist()}")
print(f"AIC : {model.aic:.2f}")Why run statsmodels in PyRun?
- ✦ Zero setup — no pip install, no virtual environment, no Python download
- ✦ Instant results — powered by WebAssembly, runs locally in your browser
- ✦ Share your code — generate a link and anyone can run it instantly
- ✦ Works offline — after first load, PyRun runs without internet
Related Packages
Recommended Python Resources
Expand your knowledge with related interactive tutorials, cheat sheets, and code comparisons.
Python Loops
Learn how to use Python loops to iterate over data. Master for loops, while loops, break, continue, and loop best practices with interactive examples.
How to Sort a List in Python
Learn how to sort a list in Python using the sort() method and the sorted() function. Discover custom key sorting and reverse order examples.
Python String Methods
A complete reference guide for Python string manipulation. Master formatting, searching, splitting, replacing, and checking string properties.
Python vs JavaScript: Which Programming Language is Best?
A comprehensive comparison between Python and JavaScript. Explore syntax differences, performance, use cases (backend vs frontend), and coding examples.