Closed kaitejohnson closed 2 months ago
Without fully understanding the details, I think the key here is leveraging S3 methods:
plot
and summary
to provide post-processing information. You also have the coef
, vcov
, and confint
generics you can use to allow the user to intuitively extract information from the model.get_draws_df()
, you can always write a generic method so the function may take a fitted model or something else, giving flexibility without much of a hurdle.Edit:
I would also add:
wwinferece
as a structure with a class attribute, e.g., "wwinference_fit"
. (see here)print.wwinference_fit
.coef
, vcov
, and confint
methods for the class.@gvegayon I am currently writing a bunch of tests of the functions and thinking now would be a good time to do some of this since it will require reworking wwinference()
and the post-processing a bit (so get_draws_df()
and get_model_diagnostic_flags()
. I'm going to start a new PR for this which will include tests for everything from fitting to post-processing. Might tag you if I have questions on how to do the function overloading/creation of the class attribute if that's ok!
Goal
Before a first release (checklist here), we will want to make sure that the main model fitting wrapper function,
wwinference()
returns a stable set of contents. Right now, we are returning a post-processeddraws
dataframe + mappings to sites and labs, dates, and maps to the subpopulations. We are also doing a diagnostic check internally within the wrapper function, while also showing the user how to do this from the stan fit object separately in the vignette.I think it would be best that we don't mix post-processing and model fit at all, and instead write the
wwinference()
function such that it returns a nested list,ww_fit
containingraw_stan_fit_obj
,input_data
, andstan_data_args
. Only the first two will be used in downstream functions, but it might be helpful, similar to the passing around the input data, to pass around the inputs to the stan model (e.g. the priors) for comparing outputs with different priors.From this, we would overload downstream functions to take in the
ww_fit
object and generate the draws dataframe, run the diagnostics, plot the results, and (eventually) evaluate the results. The main change from the current workflow right now would be to adjustget_draws_df()
to take in theww_fit
object and remove the internal calls toget_draws_df()
andget_model_diagnostic_flags()
The goal of all of this would be to 1 modularize the codebase so each function performs one step in the workflow, and 2 put the onus on us to demonstrate the workflow of the package step-by-step and the user to perform each action on the fitted model object.
Requirements
wwinference()
:raw_stan_fit_obj
,input_data
andstan_data_args
. All will be lists. Optionally, we could separate theww_data
andhosp_data
and pass back both as dataframesget_draws_df()
(perhaps rename toextract_posterior_draws()
) to take in theww_fit
object as an output and return something that looks likedraws_df()
currently. Allow user to pass in args to only include certain variables among a set of allowed variables.@seabbs @gvegayon @dylanhmorris Curious any other thoughts here