Open fredjaya opened 1 week ago
Need to think about how to deal with optimise_prevalence.fixed_sN()
(previously optimise_sN_prevalence
) when dealing with correlation = NA | 0
.
if (is.na(correlation) || correlation == 0) {
opt <- optimise_s_prevalence(
pool_number = 1, prevalence, cost_unit, cost_pool, cost_cluster,
correlation = NA, x$sensitivity, x$specificity, max_s, form
)
na_or_inf <- ifelse(is.na(correlation), NA, Inf)
out <- fixed_design(
pool_size = opt$s,
pool_number = na_or_inf,
total_units = na_or_inf,
sensitivity = x$sensitivity,
specificity = x$specificity
)
return(out)
}
If correlation = NA
then sample_design
will need to accept numeric, NULL, AND NA.
Related to #40.
Refactor to methods
Now that
sample_design
classes are implemented, refactor theoptimise...
family of functions to be methods offixed_design
andvariable_design
. This eliminates the need for the*random*
in function names.Method dispatch
Once refactored to methods, add new subclasses to dispatch according to
sample_design
attributes that areNULL
, i.e.:pool_size = NULL
->optimise_s_prevalence()
pool_number = NULL
->optimise_N_prevalence()
(Not implemented)pool_size = NULL
andpool_number = NULL
->optimise_sN_prevalence()
Example usage:
Method dispatch will eliminate the individual
random
/s
/sN
functions. Addingsample_design
subclasses according toNULL
vars for dispatching i.e.opt_s
,opt_N
,opt_sN
.When no
NULL
vars, do not add class and return message that all values are optimised. This state is ideal for calculating internal attributestotal_pools
andtotal_units
, else leaveNULL
.Return
sample_design
outputStreamline the
optimise()
topower()
/sample_design()
pipeline by amending the output ofoptimise*
funcs to return asample_design
. Focus on doing all of the above and this part onoptimise_sN_prevalence()
first.Current output is:
Change so it outputs:
Consider adding a general pretty print method that can be propagated directly to PoolTools. But hold off on this, as the returned
fixed_design
will be used for downstreampower()
etc. funcs.The current PoolTools output for the above is: