sample_sigma2¶
- sample_sigma2(y: Series, X: ndarray, beta: ndarray, k_1: float, theta_0: float) float¶
Draws a sample for the variance from an inverse-gamma conditional posterior distribution at each regression iteration.
Parameters¶
- ypd.Series
Vector of the response variable \(y\). It has a number of rows equal to the number of observed data.
- Xnumpy.ndarray
Regressors matrix \(X\). It has a number of rows equal to the number of observed data and a number of columns equal to the number of regressors.
- betanumpy.ndarray
Regressors’ parameters array of the model. It is sampled by the function
sample_betaat each iteration.- k_1float
Sum of the variance prior
shapeand the number of observed data.- theta_0float
Variance prior
scale.
Returns¶
- numpy.ndarray
Sampled variance \(\sigma^2\).
See Also¶
Notes¶
The variance is drawn from an inverse-gamma distribution. The conditional posterior distribution is:
\[H \left( \sigma^2 \left\vert B, y \right. \right) \sim \text{Inv-}\Gamma \left( \frac{\kappa_1}{2}, \frac{\theta_1}{2} \right)\]where \(B\) is the \(\beta_j\) vector, \(\kappa_1\) is:
\[\kappa_1 = \kappa_0 + n\]where \(n\) is the number of observed data and \(\theta_1\) is:
\[\theta_1 = \theta_0 + \left( y - X B \right)^T \left( y - X B \right) .\]