sample¶
- static LinearRegression.sample(model: Model, n_iterations: int, burn_in_iterations: int, n_chains: int, seed: int | None = None) None
Samples a sequence of observations from the full posterior distribution of regressors’ parameters \(\beta_j\) and
variance\(\sigma^2\). Firstburn_in_iterationsare discarded since they may not accurately represent the desired distribution. For each variable, it generatesn_chainMarkov chains.Parameters¶
- modelbaypy.model.model.Model
The model with data, regressors, response variable and priors to be solved through Monte Carlo sampling.
- n_iterationsint
Number of total sampling iteration for each chain. It must be a strictly positive integer.
- burn_in_iterationsint
Number of burn-in iteration for each chain. It must be a positive integer or
0.- n_chainsint
Number of chains. It must be a strictly positive integer.
- seedint, optional
Random seed to use for reproducibility of the sampling.
Raises¶
- TypeError
If
modelis not abaypy.model.model.Model,if
n_iterationsis not aint,if
burn_in_iterationsis not aint,if
n_chainsis not aint,if
seedis not aint.
- ValueError
If
model.dataisNone,if
model.response_variableisNone,if
model.response_variableis not a column ofmodel.dataif
model.priorsisNone,if a
model.priorskey is not a column ofmodel.data,If
n_iterationsis equal to or less than0,if
burn_in_iterationsis less than0,if
n_chainsis equal to or less than0,if
seedis not between0and2**32 - 1.
Notes¶
The linear regression model of the response variable \(y\) with respect to regressors \(X\) is:
\[y \sim N(\mu, \sigma^2)\]\[\mu = \beta_0 + B X = \beta_0 + \sum_{j = 1}^m \beta_j x_j\]and the likelihood is:
\[p \left( y \left\vert B,\sigma^2 \right. \right) = \frac{1}{\sqrt{2 \pi \sigma^2}} \exp{- \frac{\left(y - \mu \right)^2}{2 \sigma^2}} .\]