Best practices for including extra data in stanfit object?


I’ve coded an R library that uses Stan for estimation. The estimation function that runs sampling() and vb() currently returns a stanfit object. I would like, however, to include additional data in that object for post-processing, e.g. the arguments that the user gave to call the estimation function. However, I also want to maintain the ability of the object to be analyzed with standard Stan software such as shiny_stan. Can someone let me know what the best practices are to include extra data in a stanfit object? Add a unique slot for these extra data? If so, how would one do that? Thanks!

The way most packages do it, their function returns a classed list and the stanfit object is one element of that list. Then define S3 methods for that class that operate on the stanfit object.

1 Like