Write in matrix multiplication form

For a Bayesian linear regression problem like the following

basic_model = pm.Model()

with basic_model:

    # Priors for unknown model parameters
    alpha = pm.Normal("alpha", mu=0, sigma=10)
    beta = pm.Normal("beta", mu=0, sigma=10, shape=2)
    sigma = pm.HalfNormal("sigma", sigma=1)

    # Expected value of outcome
    mu = alpha + beta[0] * X1 + beta[1] * X2

    # Likelihood (sampling distribution) of observations
    Y_obs = pm.Normal("Y_obs", mu=mu, sigma=sigma, observed=Y)

How can one write

 mu = alpha + beta[0] * X1 + beta[1] * X2

in matrix form, like, for example

mu = alpha + np.matmul(X,beta)

where X = [X1,X2]?

Aesara tensors have a .dot method that lets you easily do matrix multiplications:

mu = alpha + X.dot(beta)

So will need to make sure your design matrix (X) is an aesara tensor. Using pm.Data is probably the cleanest way.

1 Like

Really helpful, thanks a lot!!