Skip to content

Commit 0f2b394

Browse files
committed
fix errors
1 parent 951d2d3 commit 0f2b394

File tree

5 files changed

+92
-27
lines changed

5 files changed

+92
-27
lines changed

R/summary.simss.R

Lines changed: 38 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,57 @@
11
#' 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.
45
#' @param ... Additional arguments (currently unused).
56
#'
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
813
#' @examples
914
#' # Assume `res` is a result from `sampleSize()`
1015
#' # summary(res)
1116
summary.simss <- function(object, ...) {
17+
18+
if (!inherits(object, "simss")) {
19+
stop("Input must be of class 'simss'")
20+
}
21+
1222
# 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, "\\.")]
1729

30+
# Header
1831
cat("Sample Size Summary\n")
19-
cat("--------------------\n")
32+
cat(strrep("-", 22), "\n")
2033

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])
2336
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))
2638

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")
2947
}
3048

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")
3953
print(ss, row.names = FALSE)
40-
if (!is.null(object$method)) {
41-
cat("Method:", object$method, "\n")
42-
}
54+
4355
invisible(ss)
4456
}
4557

R/zzz.R

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
utils::globalVariables(c(":=", "setNames"))

man/confint.simss.Rd

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/print.simss.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/summary.simss.Rd

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)