Skip to content

Instantly share code, notes, and snippets.

@terrycojones
Created July 17, 2023 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save terrycojones/8f9f38d877ef570d0c4229a5547c9620 to your computer and use it in GitHub Desktop.
Save terrycojones/8f9f38d877ef570d0c4229a5547c9620 to your computer and use it in GitHub Desktop.
import numpy as np
import pandas as pd
import pymc as pm
from pymc import HalfCauchy, Model, Normal, sample
print(f"Running on PyMC v{pm.__version__}")
RANDOM_SEED = 8927
rng = np.random.default_rng(RANDOM_SEED)
size = 200
true_intercept = 1
true_slope = 2
x = np.linspace(0, 1, size)
true_regression_line = true_intercept + true_slope * x
y = true_regression_line + rng.normal(scale=0.5, size=size)
data = pd.DataFrame(dict(x=x, y=y))
with Model() as model:
sigma = HalfCauchy("sigma", beta=10)
intercept = Normal("Intercept", 0, sigma=20)
slope = Normal("slope", 0, sigma=20)
likelihood = Normal("y", mu=intercept + slope * x, sigma=sigma, observed=y)
idata = sample(3000)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment