Skip to content

Commit 11aa925

Browse files
committed
fix formula rendering
1 parent 7ea2c11 commit 11aa925

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

causalpy/pymc_models.py

Lines changed: 42 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
- LinearRegression model
66
77
Models are intended to be used from inside an experiment
8-
class (see `pymc_experiments.py
8+
class (see :py:mod:`pymc_experiments.py<.pymc_experiments.py>` old
9+
link `pymc_experiments.py
910
<https://causalpy.readthedocs.io/en/latest/api_pymc_experiments.html>`_).
1011
This is why the examples require some extra
1112
manipulation input data, often to ensure `y` has the correct shape.
@@ -31,7 +32,7 @@ class ModelBuilder(pm.Model):
3132
- build_model: must be implemented by subclasses
3233
- fit: populates idata attribute
3334
- predict: returns predictions on new data
34-
- score: returns Bayesian R^2
35+
- score: returns Bayesian :math: `R^2`
3536
"""
3637

3738
def __init__(self, sample_kwargs: Optional[Dict[str, Any]] = None):
@@ -208,10 +209,15 @@ class WeightedSumFitter(ModelBuilder):
208209
209210
Defines the PyMC model:
210211
211-
- y ~ Normal(mu, sigma)
212-
- sigma ~ HalfNormal(1)
213-
- mu = X * beta
214-
- beta ~ Dirichlet(1,...,1)
212+
.. math::
213+
214+
sigma \sim HalfNormal(1)
215+
216+
beta \sim Dirichlet(1,...,1)
217+
218+
mu = X * beta
219+
220+
y \sim Normal(mu, sigma)
215221
216222
Example
217223
--------
@@ -224,18 +230,23 @@ class WeightedSumFitter(ModelBuilder):
224230
>>> wsf = WeightedSumFitter(sample_kwargs={"progressbar": False})
225231
>>> wsf.fit(X,y)
226232
Inference ...
227-
"""
233+
""" # noqa: W605
228234

229235
def build_model(self, X, y, coords):
230236
"""
231237
Defines the PyMC model:
232238
233-
- y ~ Normal(mu, sigma)
234-
- sigma ~ HalfNormal(1)
235-
- mu = X * beta
236-
- beta ~ Dirichlet(1,...,1)
239+
.. math::
237240
238-
"""
241+
sigma \sim HalfNormal(1)
242+
243+
beta \sim Dirichlet(1,...,1)
244+
245+
mu = X * beta
246+
247+
y \sim Normal(mu, sigma)
248+
249+
""" # noqa: W605
239250
with self:
240251
self.add_coords(coords)
241252
n_predictors = X.shape[1]
@@ -261,10 +272,14 @@ class LinearRegression(ModelBuilder):
261272
262273
Defines the PyMC model
263274
264-
- y ~ Normal(mu, sigma)
265-
- mu = X * beta
266-
- beta ~ Normal(0, 50)
267-
- sigma ~ HalfNormal(1)
275+
.. math::
276+
beta \sim Normal(0, 50)
277+
278+
sigma \sim HalfNormal(1)
279+
280+
mu = X * beta
281+
282+
y \sim Normal(mu, sigma)
268283
269284
Example
270285
--------
@@ -281,17 +296,22 @@ class LinearRegression(ModelBuilder):
281296
... },
282297
... )
283298
Inference...
284-
"""
299+
""" # noqa: W605
285300

286301
def build_model(self, X, y, coords):
287302
"""
288303
Defines the PyMC model
289304
290-
- y ~ Normal(mu, sigma)
291-
- mu = X * beta
292-
- beta ~ Normal(0, 50)
293-
- sigma ~ HalfNormal(1)
294-
"""
305+
.. math::
306+
beta \sim Normal(0, 50)
307+
308+
sigma \sim HalfNormal(1)
309+
310+
mu = X * beta
311+
312+
y \sim Normal(mu, sigma)
313+
314+
""" # noqa: W605
295315
with self:
296316
self.add_coords(coords)
297317
X = pm.MutableData("X", X, dims=["obs_ind", "coeffs"])

causalpy/tests/test_integration_pymc_examples.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def test_did_banks_simple():
3939
"""
4040
Test simple Differences In Differences Experiment on the 'banks' data set.
4141
42-
formula="bib ~ 1 + district * post_treatment"
42+
:code: `formula="bib ~ 1 + district * post_treatment"`
4343
4444
Loads, transforms data and checks:
4545
1. data is a dataframe
@@ -92,7 +92,7 @@ def test_did_banks_multi():
9292
Test multiple regression Differences In Differences Experiment on the 'banks'
9393
data set.
9494
95-
formula="bib ~ 1 + year + district + post_treatment + district:post_treatment"
95+
:code: `formula="bib ~ 1 + year + district + post_treatment + district:post_treatment"` # noqa: E501
9696
9797
Loads, transforms data and checks:
9898
1. data is a dataframe

0 commit comments

Comments
 (0)