|
| 1 | +#' Summary for Simulation Results |
| 2 | +#' @description Generates a summary of the simulation results, specifying the sample size for each comparator-endpoint |
| 3 | +#' @param object An object of class `"simss"` returned by a sampleSize function |
| 4 | +#' @param ... Additional arguments (currently unused). |
| 5 | +#' |
| 6 | +#' @return A named numeric vector with the sample size of each arm and also the total (Total) sample size. |
| 7 | +#' @export |
| 8 | +#' @examples |
| 9 | +#' # Assume `res` is a result from `sampleSize()` |
| 10 | +#' # summary(res) |
| 11 | +summary.simss <- function(object, ...) { |
| 12 | + # Equivalent margins |
| 13 | + margins <- data.table(names = names(unlist(object[["param.d"]][["list_lequi.tol"]])), |
| 14 | + Lower= unlist(object[["param.d"]][["list_lequi.tol"]]), |
| 15 | + Upper = unlist(object[["param.d"]][["list_uequi.tol"]])) |
| 16 | + margins[, c("Comparison", "Endpoint") := tstrsplit(names, "\\.")] |
| 17 | + |
| 18 | + cat("Sample Size Summary\n") |
| 19 | + cat("--------------------\n") |
| 20 | + |
| 21 | + # Sample size table |
| 22 | + ss <- as.data.frame(N_ss[["response"]][, !c("power","power_LCI", "power_UCI","n_iter", "n_drop"), with = FALSE]) |
| 23 | + ss_names <- sub("^n_", "", colnames(ss)) |
| 24 | + ss_names <- ifelse(ss_names == "total", "Total", ss_names) |
| 25 | + colnames(ss) <- ss_names |
| 26 | + |
| 27 | + if (!inherits(object, "simss")) { |
| 28 | + stop("Object must be of class 'simss'") |
| 29 | + } |
| 30 | + |
| 31 | + cat("Design:", object[["param.d"]][["dtype"]], "\n") |
| 32 | + cat("Comparison type:", object[["param.d"]][["ctype"]]) |
| 33 | + cat("Equivalence Margins:\n") |
| 34 | + print(as.data.frame(margins[, c("Comparison", "Endpoint", "Lower", "Upper")]), row.names = FALSE) |
| 35 | + cat("Alpha:", object[["param.d"]][["alpha"]], "\n") |
| 36 | + cat("Target Power:", sprintf("%.4f",object[["param.d"]][["power"]]), "\n") |
| 37 | + cat("Achieved Power:", sprintf("%.4f",object[["response"]][["power"]]), "\n") |
| 38 | + cat("Estimated Sample Size:\n") |
| 39 | + print(ss, row.names = FALSE) |
| 40 | + if (!is.null(object$method)) { |
| 41 | + cat("Method:", object$method, "\n") |
| 42 | + } |
| 43 | + invisible(ss) |
| 44 | +} |
| 45 | + |
0 commit comments