I am trying to understand regression using the Weibull family using brms. I would like to be able to compute the fitted values (mean from regression line) manually using the posterior samples.
The mean should be equal to scale*gamma(1 + 1/shape).
In brms, a log link for mu is used and an identity link for shape is used. For the simplest model with only an Intercept, the exp(Intercept) should recover the scale parameter. The shape parameter is identity.
Now, I would have thought to get the mean, I would do:
exp(samples$b_Intercept)*gamma(1 + 1/samples$shape)
But this does not seem to work.
So I have tried these two:
mean(exp(samples$b_Intercept * (gamma(1 + 1/exp(samples$shape)))))
mean(exp(samples$b_Intercept * (gamma(1 + 1/(samples$shape)))))
And depending on the values used in the simulation for shape and scale, one is sometimes closer than the other.
But neither recover the values of doing fitted(model)
Thanks for the response!
Actually, I was trying to figure out how to use the parameters from the model and the formula for the mean for a weibull regression model to obtain the same answers as using the functions in Stan.
For example, using my example code above, it looks like I should be able to do:
Right, to mimic posterior_linpred() you shouldn’t use any inverse link function.
I would also like to know how to mimic, fitted() though, in which case it would be helpful to know where to apply exp() in the formula.