I have been using the wonderful package by Joshua Wiley, to calculate AME for my model.
However, I run into two problems:
-
This might be straightforward: I am unsure how to “add_new_levels = T” to the brmsmargins function, when prediction of unobserved data is of interest.
-
The marginal effects are currently calculated based on predictions from the “fitted” function, however, it might be useful to also be able to calculate the AME based on the “predict” function. I guess the mean estimate would stay the same, however the variability in the AME estimate would be larger as the residual error Sigma is also accounted for in the fit. Is there a way to do this?
@Joshua_Wiley
Best,
Jinesh
1 Like
@Jinesh glad it is proving useful.
- If you use
effects = "integrateoutRE"
I don’t think the ID levels really matter any more. The AMEs are calculated by getting fixed effects only predictions from fitted()
and then taking the estimate of the covariance matrix of random effects, drawing random values from that (multivariate) normal distribution, adding those to the fixed effects, and back transforming, and averaging. Nowhere in that process does the specific ID matter. There is a … argument that should let you pass additional arguments to fitted()
but a workaround if that doesn’t work would be to just set the ID to one that was included in the model.
- That is an interesting idea. It is not currently implemented, but I don’t think it would be very difficult to do. The part I am not sure about is what should and should not get marginalized in that instance. For example, right now we generate monte carlo samples from the model estimated (multivariate) normal distribution and average across those samples. If you want prediction intervals, I think you would not want that averaging, because you’d want not only variation from the residual variance but also the variation between individuals / units (captured in the random effects) to expand the interval, not be averaged out. I’m open to implementing something like that if you can outline a bit more of what you are after or point to some other paper(s) / book chapters or the like that describe what is needed.
Cheers,
Josh