priors¶
- property LinearModel.priors: dict[str, dict[str, float | int]]
Priors for the regressors’ and variance parameters. Each prior is a key-value pair, where the value is a
dictwith:hyperparameter names as keys
hyperparameter values as values.
Returns¶
dictPriors for each random variable. It must contain an
'intercept'and a'variance'keys. Each value must be adictwith hyperparameter names as key and hyperparameter values as values.
Raises
TypeErrorValueErrorKeyErrorIf
priorsdoes not contain both'intercept'and'variance'keys,- if a prior’s hyperparameters are not:
'mean'and'variance'for a regression parameter \(\beta_j\) or'shape'and'scale'forvariance\(\sigma^2\).
Notes
To each random variables is assigned a prior distribution:
to each regressor parameter \(\beta_j\) is assigned a normal prior distribution with hyperparameters
'mean'\(\beta_j^0\) and'variance'\(\Sigma_{\beta_j}^0\):\[\beta_j \sim N(\beta_j^0 , \Sigma_{\beta_j}^0)\]to variance \(\sigma^2\) is assigned an inverse gamma distribution with hyperparameters
'shape'\(\kappa^0\) and'scale'\(\theta^0\):\[\sigma^2 \sim \text{Inv-}\Gamma(\kappa^0, \theta^0)\]
Examples
Consider a linear regression of the
response_variable\(y\) with respect to regressors \(x_1\), \(x_2\) and \(x_3\), according to the following model:\[y \sim N(\mu, \sigma^2)\]\[\mu = \beta_0 + \beta_1 x_1 + \beta_2 x_2 + \beta_3 x_3\]- then the sampler would require priors for:
parameter \(\beta_0\) of variable
'intercept', with'mean'\(\beta_0^0\) and'variance'\(\Sigma_{\beta_0}^0\)parameter \(\beta_1\) of variable \(x_1\), with
'mean'\(\beta_1^0\) and'variance'\(\Sigma_{\beta_1}^0\)parameter \(\beta_2\) of variable \(x_2\), with
'mean'\(\beta_2^0\) and'variance'\(\Sigma_{\beta_2}^0\)parameter \(\beta_3\) of variable \(x_3\), with
'mean'\(\beta_3^0\) and'variance'\(\Sigma_{\beta_3}^0\)variable \(\sigma^2\), with
'shape'\(\kappa^0\) and'scale'\(\theta^0\)
>>> model = baypy.model.LinearModel() >>> model.priors = { ... 'intercept': {'mean': 0, 'variance': 1e6}, ... 'x_1': {'mean': 0, 'variance': 1e6}, ... 'x_2': {'mean': 0, 'variance': 1e6}, ... 'x_3': {'mean': 0, 'variance': 1e6}, ... 'variance': {'shape': 1, 'scale': 1e-6} ... }