Fixed Effects
Fixed-Effect Priors
Set priors for the intercept and for specific fixed-effect coefficients via control['fixed'] using label-specific keys (e.g., {'mean': {'z': ...}, 'prec': {'z': ...}}).
Overview
- Use prior names as strings (e.g.,
normal). Refer to the model and API documentation for available prior names and their parameters. - Defaults: the intercept uses a Gaussian prior with mean
0and precision0.0(flat). All other fixed effects use Gaussian priors with mean0and precision0.001. - Configure priors via
control['fixed']. Keys accept either dotted or underscored forms (e.g.,mean.interceptormean_intercept).
Set Global Priors
# Apply the same Gaussian prior to all non-intercept coefficients
prior_fixed = {
'mean.intercept': 0.0, # intercept prior mean
'prec.intercept': 0.0, # intercept prior precision (0.0 ~ flat)
'mean': 0.0, # prior mean for all non-intercepts
'prec': 0.001 # prior precision for all non-intercepts
}
res = pyinla(formula=formula, data=df, family='gaussian', control={'fixed': prior_fixed})Label-Specific Priors
Set priors for specific coefficients by name using dictionaries under mean and prec. Names must match the fixed-effect labels (e.g., 'x', 'z1', or expanded names like 'group_B').
# Different priors for 'x1' and 'x2'; others use the global defaults
control = {
'fixed': {
'mean': {'x1': 0.5},
'prec': {'x1': 2.0, 'x2': 5.0},
'mean.intercept': 0.0,
'prec.intercept': 0.0,
'mean': 0.0,
'prec': 0.001,
}
}
res = pyinla(formula=formula, data=df, family='gaussian', control=control)Intercept-Only Priors
Set a prior for the intercept independently from other fixed effects.
control = {'fixed': {'mean.intercept': 1.0, 'prec.intercept': 1.0}}
res = pyinla(formula=formula, data=df, family='gaussian', control=control)Matrix Inputs and Expanded Names
If you supply an n×p matrix via ('z', Z) inside model['fixed'], columns are named z1..zp. You can assign priors to these expanded labels individually:
# Suppose model['fixed'] includes ('z', Z) with p columns -> labels z1..zp
control = {'fixed': {'prec': {'z1': 10.0, 'z2': 5.0}}}Notes
- Use
control['fixed']['correlation_matrix'] = Trueif you want the posterior correlation matrix of fixed effects reported in the output. This does not set a prior; it controls reporting. - For correlated priors across multiple slopes, consider a latent model that supports multivariate structure (e.g.,
slmwithQ.beta), or keep terms as standard fixed effects and set independent priors per label. - When working with categorical variables, pyINLA expands levels to dummies (e.g.,
group_A,group_B); target those expanded names if you need level-specific priors.