@@ -78,6 +78,7 @@ Trial <- R6::R6Class("Trial", #nolint
7878 self $ info <- as.list(info )
7979
8080 args <- as.list(formals(self $ summary ))
81+
8182 args [c(" ..." , " estimates" )] <- NULL
8283 private $ summary.args_default <- args
8384
@@ -131,7 +132,7 @@ Trial <- R6::R6Class("Trial", #nolint
131132 },
132133
133134 # ' @description Get, specify or update the summary.args attribute.
134- # ' @param .args (list or character) named list of arguments to update
135+ # ' @param .args (list or character) named list of arguments to update
135136 # ' or set. A single or subset of arguments can be retrieved by passing the
136137 # ' respective argument names as a character or character vector.
137138 # ' @param .reset (logical or character) Reset all or a subset of previously
@@ -513,15 +514,20 @@ Trial <- R6::R6Class("Trial", #nolint
513514 # ' the power of both superiority tests (one-sided or two-sided) and
514515 # ' non-inferiority tests, together with summary statistics of the
515516 # ' different estimators.
517+ # '
518+ # ' Arguments provided to this method call take precedence over argument
519+ # ' values that have been previously set via ([Trial$args_summary()][Trial]).
520+ # ' See the examples for more details.
516521 # ' @param level (numeric) significance level
517522 # ' @param null (numeric) null hypothesis to test
518523 # ' @param ni.margin (numeric) non-inferiority margin
519- # ' @param alternative alternative hypothesis (not equal !=, less <,
520- # ' greater >)
524+ # ' @param alternative (character) alternative hypothesis (not equal !=, less
525+ # ' <, greater >)
521526 # ' @param reject.function Optional function calculating whether to reject
522527 # ' the null hypothesis
523- # ' @param true.value Optional true parameter value
524- # ' @param nominal.coverage Width of confidence limits
528+ # ' @param true.value (numeric) Optional true parameter value
529+ # ' @param nominal.coverage (numeric) Width of confidence limits. The default
530+ # ' behavior is to calculate the coverage for the 1 - `level` CI.
525531 # ' @param estimates Optional trial.estimates object. When provided, these
526532 # ' estimates will be used instead of the object's stored estimates. This
527533 # ' allows calculating summaries for different trial results without
@@ -550,20 +556,37 @@ Trial <- R6::R6Class("Trial", #nolint
550556 # '
551557 # ' # calculate empirical bias, rmse and coverage for true target parameter
552558 # ' trial$summary(estimates = res, true.value = 0)
559+ # '
560+ # ' # use args_summary to set default values
561+ # ' trial$args_summary(true.value = 0)
562+ # ' trial$summary(estimates = res)
563+ # ' # arguments to method call preceed arguments that have been set via
564+ # ' # args_summary method
565+ # ' trial$summary(estimates = res, true.value = 1)
553566 summary = function (level = .05 ,
554567 null = 0 ,
555568 ni.margin = NULL ,
556569 alternative = " !=" ,
557570 reject.function = NULL ,
558571 true.value = NULL ,
559- nominal.coverage = 0.9 ,
572+ nominal.coverage = NULL ,
560573 estimates = NULL ,
561574 ... ) {
562- trial_summary(self = self , level = level , null = null ,
563- ni.margin = ni.margin , alternative = alternative ,
564- reject.function = reject.function , true.value = true.value ,
565- nominal.coverage = nominal.coverage , estimates = estimates , ...
566- )
575+ mc_supplied <- as.list(match.call(expand.dots = FALSE ))[- 1 ]
576+ nm_formals_supplied <- setdiff(names(mc_supplied ), " ..." )
577+ call_args <- if (length(nm_formals_supplied )) {
578+ mget(nm_formals_supplied , inherits = FALSE )
579+ } else {
580+ list ()
581+ }
582+ if (" ..." %in% names(mc_supplied )) call_args <- c(call_args , list (... ))
583+
584+ args <- self $ args_summary()
585+ args [names(call_args )] <- call_args
586+
587+ if (! (" estimates" %in% names(args ))) args <- c(args , list (estimates = NULL ))
588+
589+ do.call(trial_summary , c(list (self = self ), args ))
567590 },
568591
569592 # ' @description Print method for Trial objects
@@ -714,6 +737,7 @@ trial_summary <- function(self, level, null, ni.margin, alternative,
714737 if (! (alternative %in% c(" !=" , " <" , " >" ))) {
715738 rlang :: abort(' alternative should be one of "!=", "<", ">"' )
716739 }
740+ if (is.null(nominal.coverage )) nominal.coverage <- 1 - level
717741
718742 alternative <- gsub(" " , " " , tolower(alternative [1 ]))
719743 q_alpha_cov <- qnorm(1 - (1 - nominal.coverage ) / 2 ) # quantile for
0 commit comments