-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
distribution interface to dist_spec
#504
Conversation
1ed6401
to
d0525df
Compare
This comment was marked as outdated.
This comment was marked as outdated.
d0525df
to
e152fe6
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
36575a0
to
7673d3a
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
053f3e4
to
2135b4b
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
f0bbe0d
to
267c8e0
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is good to be merged in after both another site read and a functionality review. A few minor comments outstanding.
I do think that any porting of this for use elsewhere needs to come with a refactor/redesign as the current implementation seems quite brittle (all the ifelse and magic string based detection of distributions).
I also expect there to be a few edge cases this review has missed that will need fixing once this is on main but we will see (and 🤞🏻) .
Nice work on this - a lot of work but worth it as much nicer to use!
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 3a3d8d8 is merged into main:
|
Co-authored-by: Sam Abbott <[email protected]>
This is how benchmark results would change (along with a 95% confidence interval in relative change) if 3a3d8d8 is merged into main:
|
* add distribution functions * deprecate "empty" distribution * make sd S3 * only generate samples if any params aren't natural * update stan model with new dist interface * update lognormal parameters * return mean function to previous functionality * update data * deprecate dist_def functions * use natural parametrisations in dist_def functions * deprecate dist_spec * extract_single_dist function * update fix_dist to work with compsosite dists * extract squash * update parameters to extract * specify lower bounds in function * pass lower bounds to stan model * update sample/report functions * max squash adjust report * update dist functions to new syntax * re-create data * update get_dist to new syntax * fully deprecate get fnuctions * create delay inits separately * max squash again * return correct dist in estimate_truncation * few more examples/docs * fix tests * add documentation to dist interface * add input checks * sd function to work with composite dists * warn when not using natural parameters * ensure bounds are respected in stan * add empty distribution for legacy reasons * add checks to dist_skel * use lapply for parameters * don't calculate sd if length 1 * use uncertain reporting in example * don't add one to sd * return correct parameters * dist_skel: calculate rate everywhere * update dist_skel examples * add missing man file * don't run internal examples * demote warning to message * update syntax everywhere * add news item * turn sd into an internal function * fix distribution documentation * remove obselete default * spell checking * use correct sd function * linting * remove obsolete tests * loop over all parameters * update touchstone arguments * linting * fix regex search/replace gone wrong * remove obsolete space * update strategy for estimating uncertainty * update uncertain parameter transformations * add missing sd to parameter sampling * update / recompile vignettes * update var names * rename argument in docs * update man pages * update test result * add reviewer Co-authored-by: Sam Abbott <[email protected]> * base scaling on variance, not sd * re-render vignettes * full text capitalisation of distributions * separate dist_spec from stan model * adjust tests/code for new dist_spec set up * re-create examples * re-doc * update tests * new dist_spec in estimate_truncation example * update get_seeding_time with updated dist_spec * estimate_truncation and seeding time tests * update truncation dist in estimate_truncation * remove more uses of old dist_spec * SD explicitly to zero for fixed * give names * fix typo * fix indent * fix another typo * squash bugs highlighted by tests * remove missing variable * linting * add missing docs * import transpose * ensure sd is positive * fix estimate_truncation example * make tolerance user-settable * use purrr::map instead of lapply * fix stan dist test * fix plotting * Apply suggestions from code review Co-authored-by: Sam Abbott <[email protected]> * rate and scale examples for Gamma Co-authored-by: Sam Abbott <[email protected]> * capitalise gamma and lognormal Co-authored-by: Sam Abbott <[email protected]> * change to single hash * use bar in normal_cdf * remove estraneous backticks * remove space before left parenthesis * split up dist.R * move deprecated `dist_spec` function * add examples * initial design sketch * make parameter conversion more flexible * add test for alternative gama params * update syntax in simulate_infections * add missing tag * update man pages * update estimate_secondary tests * update simulate_infections for new interface * udpate snapshots * get_dist deprecation test with natural params * update phi syntax * hide internal example * update deprecations * use toString * pmf -> NonParametric * add american spelling * fix gamma deprecation * add new functions to pkgdown * update vignette * recompile vignettes --------- Co-authored-by: Sam Abbott <[email protected]>
* add distribution functions * deprecate "empty" distribution * make sd S3 * only generate samples if any params aren't natural * update stan model with new dist interface * update lognormal parameters * return mean function to previous functionality * update data * deprecate dist_def functions * use natural parametrisations in dist_def functions * deprecate dist_spec * extract_single_dist function * update fix_dist to work with compsosite dists * extract squash * update parameters to extract * specify lower bounds in function * pass lower bounds to stan model * update sample/report functions * max squash adjust report * update dist functions to new syntax * re-create data * update get_dist to new syntax * fully deprecate get fnuctions * create delay inits separately * max squash again * return correct dist in estimate_truncation * few more examples/docs * fix tests * add documentation to dist interface * add input checks * sd function to work with composite dists * warn when not using natural parameters * ensure bounds are respected in stan * add empty distribution for legacy reasons * add checks to dist_skel * use lapply for parameters * don't calculate sd if length 1 * use uncertain reporting in example * don't add one to sd * return correct parameters * dist_skel: calculate rate everywhere * update dist_skel examples * add missing man file * don't run internal examples * demote warning to message * update syntax everywhere * add news item * turn sd into an internal function * fix distribution documentation * remove obselete default * spell checking * use correct sd function * linting * remove obsolete tests * loop over all parameters * update touchstone arguments * linting * fix regex search/replace gone wrong * remove obsolete space * update strategy for estimating uncertainty * update uncertain parameter transformations * add missing sd to parameter sampling * update / recompile vignettes * update var names * rename argument in docs * update man pages * update test result * add reviewer Co-authored-by: Sam Abbott <[email protected]> * base scaling on variance, not sd * re-render vignettes * full text capitalisation of distributions * separate dist_spec from stan model * adjust tests/code for new dist_spec set up * re-create examples * re-doc * update tests * new dist_spec in estimate_truncation example * update get_seeding_time with updated dist_spec * estimate_truncation and seeding time tests * update truncation dist in estimate_truncation * remove more uses of old dist_spec * SD explicitly to zero for fixed * give names * fix typo * fix indent * fix another typo * squash bugs highlighted by tests * remove missing variable * linting * add missing docs * import transpose * ensure sd is positive * fix estimate_truncation example * make tolerance user-settable * use purrr::map instead of lapply * fix stan dist test * fix plotting * Apply suggestions from code review Co-authored-by: Sam Abbott <[email protected]> * rate and scale examples for Gamma Co-authored-by: Sam Abbott <[email protected]> * capitalise gamma and lognormal Co-authored-by: Sam Abbott <[email protected]> * change to single hash * use bar in normal_cdf * remove estraneous backticks * remove space before left parenthesis * split up dist.R * move deprecated `dist_spec` function * add examples * initial design sketch * make parameter conversion more flexible * add test for alternative gama params * update syntax in simulate_infections * add missing tag * update man pages * update estimate_secondary tests * update simulate_infections for new interface * udpate snapshots * get_dist deprecation test with natural params * update phi syntax * hide internal example * update deprecations * use toString * pmf -> NonParametric * add american spelling * fix gamma deprecation * add new functions to pkgdown * update vignette * recompile vignettes --------- Co-authored-by: Sam Abbott <[email protected]>
The aim of this PR is to introduce a new distribution interface to replace the current
dist_spec
interface. This should make user interaction more intuitive and be more easily extensible if developers want to add more distributions (Weibull seems an obvious candidate). Eventually (following a deprecation cycle asdist_spec
became part of a release necessitated by updates torstan
)dist_spec
would become an internal function and the user would only interact with it via the distribution functions.Examples of the new interface:
Created on 2024-01-11 with reprex v2.0.2
Somewhat sad to be masking
base::gamma
andstats::sd
but perhaps unavoidable - or of course could name them differently.To do following initial review:
dist_spec
in examples / vignettesadjust_infection_to_report
to use this and deprecategamma_dist_def
andlnorm_dist_def
Tests etc are expected to fail at initial state.
Closes #382
Closes #498