# ReactiveMP: How to run linear model with multiple predictors and an intercept

**URL:** https://discourse.julialang.org/t/reactivemp-how-to-run-linear-model-with-multiple-predictors-and-an-intercept/85290
**Category:** Probabilistic Programming
**Tags:** question, package, bayesian-inference, forneylab
**Created:** [August 4, 2022, 10:01am UTC](https://discourse.julialang.org/t/reactivemp-how-to-run-linear-model-with-multiple-predictors-and-an-intercept/85290 "2022-08-04T10:01:47Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![EvoArt](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/evoart/32/25357_2.png) [@EvoArt](https://discourse.julialang.org/u/EvoArt)
#### Post date: [August 4, 2022, 11:18pm UTC](https://discourse.julialang.org/t/reactivemp-how-to-run-linear-model-with-multiple-predictors-and-an-intercept/85290/2 "2022-08-04T23:18:23Z")

</div>

This works (runs at least, haven’t tested thoroughly)

```julia
@model function linear_regression(n,m)
    a ~ MvNormalMeanCovariance(zeros(m), diagm(ones(m)))
    b ~ NormalMeanVariance(0.0,1.0)
    c ~ ones(n)*b
    x = datavar(Matrix{Float64})
    y = datavar(Vector{Float64})
    z ~ x*a+c
    y ~ MvNormalMeanCovariance(z , tiny .*diagm(ones(n)))

    return a, y
end
results = inference(
    model = Model(linear_regression, n,m),
    data = (y = randn(n), x = randn(n,m)),
    returnvars = (a = KeepLast(),),
    iterations = 20
);

```

Guess I just need to get my head around the datavar/randomvar as vectors/matrices vs vectors/matrices of datavars/randomvars, and nrush up on very basic linear algebra!

---

_[View the full topic](https://discourse.julialang.org/t/reactivemp-how-to-run-linear-model-with-multiple-predictors-and-an-intercept/85290)._
