priors¶
- property LinearModel.priors: dict
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¶
- dict
Priors for each random variable. It must contain an
interceptand avariancekeys. Each value must be adictwith hyperparameter names as key and hyperparameter values as values.
Raises¶
- TypeError
- ValueError
- KeyError
If
priorsdoes not contain bothinterceptandvariancekeys,- if a prior’s hyperparameters are not:
meanandvariancefor a regression parameter \(\beta_j\) orshapeandscaleforvariance\(\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\) andvariance\(\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\) andscale\(\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, withmean\(\beta_0^0\) andvariance\(\Sigma_{\beta_0}^0\)parameter \(\beta_1\) of variable \(x_1\), with
mean\(\beta_1^0\) andvariance\(\Sigma_{\beta_1}^0\)parameter \(\beta_2\) of variable \(x_2\), with
mean\(\beta_2^0\) andvariance\(\Sigma_{\beta_2}^0\)parameter \(\beta_3\) of variable \(x_3\), with
mean\(\beta_3^0\) andvariance\(\Sigma_{\beta_3}^0\)variable \(\sigma^2\), with
shape\(\kappa^0\) andscale\(\theta^0\)
>>> model = baypy.model.LinearModel() >>> model.set_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}})