slimp: linear models with Stan and Pandas
slimp estimates linear models using Stan and Pandas. Think rstanarm or brms, but in Python and faster.
Create the model:
import matplotlib.pyplot
import numpy
import pandas
import slimp
y, x = numpy.mgrid[0:10, 0:10]
z = 10 + x + 2*y + numpy.random.normal(0, 2, (10, 10))
data = pandas.DataFrame({"x": x.ravel(), "y": y.ravel(), "z": z.ravel()})
model = slimp.Model("z ~ 1 + x + y", data, num_chains=4)
# Also possible to specify random seed
# model = slimp.Model("z ~ 1 + x + y", data, seed=42)
Sample the parameters, check the results:
model.sample()
print(model.hmc_diagnostics)
print(model.summary()[["N_Eff", "R_hat"]].describe().loc[["min", "max"], :])
r_squared = slimp.r_squared(model)
print(r_squared.quantile([0.05, 0.95]))
Plot prior and posterior predictive checks:
figure, plots = matplotlib.pyplot.subplots(1, 2, layout="tight", figsize=(8, 4))
slimp.predictive_plot(model, use_prior=True, plot_kwargs={"ax":plots[0]})
slimp.predictive_plot(model, use_prior=False, plot_kwargs={"ax":plots[1]})
Plot the credible intervals of the parameters and their distributions:
slimp.parameters_plot(model, include=["x", "y"])
slimp.KDEPlot(model.draws["sigma"], prob=0.90)
Use a custom Stan model: have a look here
Metadata
Release files for slimp 1.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| slimp-1.1.1.tar.gz | 31.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| slimp-1.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 1.3 MB
Release files / slimp-1.1.1.tar.gz
| Download URL | slimp-1.1.1.tar.gz |
|---|---|
| Size | 31.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a964c0d3c4007c382a7f4432ac718625e79aa6a62409f762e484bae45e0e4e9a
|
|
BLAKE2b-256 checksum How to use checksums |
17141c0f32ebd14975af2c21eef44a44f2ff4ece09265fd30e5ea61de3d9cdbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|
Release files / slimp-1.1.1-py3-none-any.whl
| Download URL | slimp-1.1.1-py3-none-any.whl |
|---|---|
| Size | 1.3 MB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
48722463d6440a3a09f8274719cbe3b8c1cd3331cdc77808646bbe9f510b9160
|
|
BLAKE2b-256 checksum How to use checksums |
7883b1c5166340043ca35d4e30dbbb7f093ef91df6f374372fb53a74603b2939
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.5
|