Constant variables in a bambi model (original) (raw)
It seems bambi
does not allow constant variables as input:
df = pd.DataFrame({"y": [1,3,5,8],
"x1": [25,8,6,9],
"x2": [5,5,5,5]})
model = bmb.Model(
formula="y ~ x1 + x2",
data=df,
noncentered=True
).fit()
ValueError: The term ‘x2’ is constant!
Is there a way to make it ignore this check for constants?
IMO a warning would be fine but it should still compute the model (brms
allows this).
The workaround I found so far was adding small amounts of noise to x2
.
Hi @Harryg, it’s not possible to do that for now. But I don’t think it’s a good idea to have a constant predictor, it will be confounded with the intercept. What is the reason for having a constant term?
Harryg June 3, 2024, 6:55am 4
Thanks for your reply @tcapretto . My use case is that I need to apply a multivariate mixture prior to my linear model, derived from the posterior of an earlier model with a different dataset. The earlier model lacks one variable, so I’ll introduce a fixed dummy variable to make this prior transferable to the new model.
It’s probably a very unique use case, but maybe one can imagine a scenario where you have a constant variable in your data but want to define a very strong prior shifting this constant in a certain direction.