You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: myst_nbs/case_studies/spline.myst.md
+4-2
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ jupytext:
6
6
format_version: 0.13
7
7
jupytext_version: 1.13.7
8
8
kernelspec:
9
-
display_name: Python 3.10.4 ('pymc_env')
9
+
display_name: Python 3 (ipykernel)
10
10
language: python
11
11
name: python3
12
12
---
@@ -27,6 +27,8 @@ kernelspec:
27
27
Often, the model we want to fit is not a perfect line between some $x$ and $y$.
28
28
Instead, the parameters of the model are expected to vary over $x$.
29
29
There are multiple ways to handle this situation, one of which is to fit a *spline*.
30
+
Spline fit is effectively a sum of multiple individual curves (piecewise polynomials), each fit to a different section of $x$, that are tied together at their boundaries, often called *knots*.
31
+
30
32
The spline is effectively multiple individual lines, each fit to a different section of $x$, that are tied together at their boundaries, often called *knots*.
31
33
32
34
Below is a full working example of how to fit a spline using PyMC. The data and model are taken from [*Statistical Rethinking* 2e](https://xcelab.net/rm/statistical-rethinking/) by [Richard McElreath's](https://xcelab.net/rm/) {cite:p}`mcelreath2018statistical`.
@@ -158,7 +160,7 @@ Finally, the model can be built using PyMC. A graphical diagram shows the organi
158
160
159
161
```{code-cell} ipython3
160
162
COORDS = {"splines": np.arange(B.shape[1])}
161
-
with pm.Model(coords=COORDS, rng_seeder=RANDOM_SEED) as spline_model:
163
+
with pm.Model(coords=COORDS) as spline_model:
162
164
a = pm.Normal("a", 100, 5)
163
165
w = pm.Normal("w", mu=0, sigma=3, size=B.shape[1], dims="splines")
164
166
mu = pm.Deterministic("mu", a + pm.math.dot(np.asarray(B, order="F"), w.T))
0 commit comments