Specifying prior over many variables

I am trying to carry out a simple linear regression with p predictor variables. If the coefficients follow normal distribution individually then how to concisely define the prior over all these coefficients in most efficient way suppose inside a loop? For example,

    beta0 = Normal("beta0", mu=0, sigma=20) # Intercept
    beta1 = Normal("beta1",mu=0, sigma=20) # Coefficient1
    beta2 = Normal("beta2", mu=0, sigma=20) # Coefficient2
    beta3 = Normal("beta3", mu=0, sigma=20) # Coefficient3

For small problems specifying the priors in above way is not a challenge. But for bigger problems its quite challenging.
In this case how to specify the priors over the coefficients in a concise form like the following?

    for jj in range(3):
          beta[jj] = Normal("beta", mu=0, sigma=20) 

Thanks in advance.

you can do it with declaring a vector of the shape = 4

1 Like

It worked. Thanks a lot.

1 Like

Specifying shape works to get you a parameter array. You can now instead use dimensions and coordinates if you wish and are often easier to deal with (e.g., when processing the posterior). Relevant blog posts here and here.

2 Likes