# Is it possible to model the response variable (reaction time) as lognormal in bambi?

Hello,

I have specified the following model (a varying intercepts model for a reaction time (see figure for the sample data distribution) as a function of condition = [baseline, treatment1, treatment2]) with the bambi package:

b_model = Model(data)

results = b_model.fit(‘reaction_time ~ 1 + condition’, random = [‘1|subject_id’],
samples = 3000, tune = 2000)

As the title says: is there a possibility to model the response variable (in my case a reaction time) as lognormal (or any other right skewed option)? I have seen the possibility to specify a family, but can’t understand how to do it.

Thanks

Not sure if lognormal likelihood is implemented in bambi, @aloctavodia ?

1 Like

You can specify a family by passing the argument `family` to `fit`, the available families are “gaussian”, “bernoulli” and “poisson”.

If your variable `y` is lognormal distributed then `log(y)` is normal distributed, then you can transform your variable `y` and keep the bambi model the same. Even if your data is not really lognormal taking the log can help with right skewed data.

Thanks @aloctavodia,

I will give it a try!

@aloctavodia

Hi,
I’ve fit my model using the log(y) which is fine.

1. Since I’m interested in comparing the means for baseline, treatment 1 and treatment 2, is there any way I can back transform my model parameters to obtain posterior distributions on my original scale (in seconds since I’m working with reaction times)? Modelling reaction time as normally distributed, I would obtain the difference: baseline vs. treatment 1 as the slope1 coefficient and baseline vs. treatment 2 as the slope2 coefficient.

Thanks

Sorry for the delay, yes you can apply the inverse of the (natural) logarithm function, that is you can do `exp(coeff)`.

Thanks @aloctavodia. Would you say the same applies if the transform would be inverse instead (i.e., that if the y is transformed as (y)^(-1) the coefficients can be obtained by (coeff)^(-1)?

In general you can apply one function to the response variable and then its inverse to back-transform the parameters.

1 Like

@aloctavodia Thanks!