Skip to content

Commit 32e70d6

Browse files
authored
Add linear regression model example to README
1 parent cdc8b2f commit 32e70d6

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

README.md

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,22 @@ You can define models using the `@model` macro, and then perform Markov chain Mo
2222
```julia
2323
julia> using Turing
2424

25-
julia> @model function my_first_model(data)
26-
mean ~ Normal(0, 1)
27-
sd ~ truncated(Cauchy(0, 3); lower=0)
28-
data ~ Normal(mean, sd)
25+
julia> @model function linear_regression(x)
26+
# Priors
27+
α ~ Normal(0, 1)
28+
β ~ Normal(0, 1)
29+
σ² ~ truncated(Cauchy(0, 3); lower=0)
30+
31+
# Likelihood
32+
μ = α .+ β .* x
33+
y ~ MvNormal(μ, σ² * I)
2934
end
3035

31-
julia> model = my_first_model(randn())
36+
julia> x, y = rand(10), rand(10)
3237

33-
julia> chain = sample(model, NUTS(), 1000)
38+
julia> posterior = linear_regression(x) | (; y = y)
39+
40+
julia> chain = sample(posterior, NUTS(), 1000)
3441
```
3542

3643
You can find the main TuringLang documentation at [**https://turinglang.org**](https://turinglang.org), which contains general information about Turing.jl's features, as well as a variety of tutorials with examples of Turing.jl models.

0 commit comments

Comments
 (0)