sample_beta

sample_beta(Xt_X: ndarray, Xt_y: ndarray, sigma2: float, Sigma_0_inv: ndarray, Sigma_0_inv_Beta_0: ndarray) ndarray

it draws a sample for each regressor parameter from a normal conditional posterior distribution at each regression iteration.

Parameters

Xt_Xnumpy.ndarray

Dot product of transposed regressors with themselves: \(X^T X\). It is a symmetric matrix with a number of rows and columns equal to the number of regressors.

Xt_ynumpy.ndarray

Dot product of transposed regressors with the response variable: \(X^T y\). It is a one-dimensional array with a number of rows equal to the number of regressors.

sigma2float

Variance of the model. It is sampled by the function sample_sigma2 at each iteration.

Sigma_0_invnumpy.ndarray

Regressors’ parameters variance priors matrix. It is a symmetric matrix with a number of rows and columns equal to the number of regressors. It is the inverse of a matrix which has regressors’ parameters’ prior variances on the diagonal and 0 everywhere else.

Sigma_0_inv_Beta_0numpy.ndarray

Dot product of Sigma_0_inv with a one-dimensional vector which has regressors’ parameters’ prior means on rows.

Returns

numpy.ndarray

Array of the sampled regressors’ parameters \(B\). It has a number of element equal to the number of regressors.

Notes

The regressors’ parameters are drawn from a multivariate normal distribution. The conditional posterior distribution is:

\[H \left( B \left\vert \sigma^2, y \right. \right) \sim N(M, V)\]

where \(M\) is a one-dimensional vector with a number of rows equal to the number of regressors:

\[M = \left( \Sigma_0^{-1} + \frac{1}{\sigma^2} X^T X \right)^{-1} \left( \Sigma_0^{-1} B_0 + \frac{1}{\sigma^2} X^T y \right)\]

and \(V\) is a symmetric matrix with a number of rows and columns equal to the number of regressors:

\[V = \left( \Sigma_0^{-1} + \frac{1}{\sigma^2} X^T X \right)^{-1} .\]

\(B_0\) is:

\[\begin{split}B_0 = \begin{bmatrix} \beta_0^0 \\ \beta_1^0 \\ \vdots \\ \beta_m^0 \end{bmatrix}\end{split}\]

and \(\Sigma_0^{-1}\) is:

\[\begin{split}\Sigma_0^{-1} = \begin{bmatrix} \Sigma_{\beta_0}^0 & 0 & \dots & 0 \\ 0 & \Sigma_{\beta_1}^0 & \dots & 0 \\ \vdots & \vdots & \ddots & 0 \\ 0 & 0 & 0 & \Sigma_{\beta_m}^0 \end{bmatrix}\end{split}\]

See Also

sample_sigma2