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