n8thangreen / BCEA

Bayesian Cost Effectiveness Analysis. Given the results of a Bayesian model (possibly based on MCMC) in the form of simulations from the posterior distributions of suitable variables of costs and clinical benefits for two or more interventions, produces a health economic evaluation. Compares one of the interventions (the "reference") to the others ("comparators"). Produces many summary and plots to analyse the results
https://n8thangreen.github.io/BCEA/
GNU General Public License v3.0
3 stars 2 forks source link

use interface-type top-level graph function #58

Open n8thangreen opened 3 years ago

n8thangreen commented 3 years ago

could have:

# replace top-level functions with sub-classes:

ceac.plot <- function(he, graph = "base", <fn specific args>) {
   he <- structure(he, class = list("ceac", class(he))
   bcea_plot(he, graph, <plot specific args>)
}

ceplane.plot <- function(he, graph = "base", <fn specific args>) {
   he <- structure(he, class = list("ceplane", class(he))
   bcea_plot(he, graph, <plot specific args>)
}

# then don't have to repeat this structure every time:

bcea_plot <- function(he, graph, ...) {
   params <- make_plot_params(he, ...)
   data <- make_plot_data(he, ...)

   if (is_baseplot(graph))
      plot_base(he, data, params)
   if (is_ggplot(graph))
      plot_ggplot(he, data, params)
...
}

make_plot_params.ceac <- function(he, <fn specific args>) {
   ...
}

make_plot_data.ceac <- function(he, <fn specific args>) {
   ...
}

plot_base.ceac <- function(he, <fn specific args>) {
   ...
}

plot_base.ceplane <- function(he) {
   ...
}

etc

n8thangreen commented 3 years ago

i.e. all the plot types (ceac, ceplane, ib, eib, ...) have the same methods (make_plot_params, make_plot_data, plot_base, plot_ggplot)

multiple inheritence? base class?

n8thangreen commented 3 years ago

not doing something like double-dispatch since there are only 3 types of plot and I don't imagine there will be any need to extend it in the future => over-engineered, premature generalisation leads to bloated software.

n8thangreen commented 3 years ago

this will force me to make all of the bcea_plot() functions the same for all plots. At the moment they are certainly very similar but have some differences, especially in terms of input arguments. This could be a a good exercise if its not too much trouble..

n8thangreen commented 3 years ago

use factory-type pattern instead?

structure()
.new_plottype(he, "ceac")

then can reuse in other plot types because pattern the same e. g. create function

ceac.plot <- .new_plot("ceac")

because ceac.plot(), ceplane.plot() etc are duplicated too.

Then

.new_plot <- function(plottype) {
   function (he, graph, ...) {
      he <- .new_plottype(he, plottype) 
     .bcea_plot(he, graph, ...)
  } 
}

Can we do a function factory which defines arguments like ...?

args_names <- default_args[[plottype]]
dot_list <- keep(list(...), args_names)