sample_sigma2¶
- sample_sigma2(y: Series, X: ndarray, beta: ndarray, k_1: float, theta_0: float) float¶
It draws a sample for the variance from an inverse-gamma conditional posterior distribution at each regression iteration.
Parameters¶
ypandas.SeriesVector of the response variable \(y\). It has a number of rows equal to the number of observed data.
Xnumpy.ndarrayRegressors 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.ndarrayRegressors’ parameters array of the model. It is sampled by the function
sample_betaat each iteration.k_1floatSum of the variance prior
'shape'and the number of observed data.theta_0floatVariance prior
'scale'.
Returns¶
numpy.ndarraySampled variance \(\sigma^2\).
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) .\]See Also