| 1 |
#' @templateVar class binWidth |
| 2 |
#' @template title_desc_tidy |
| 3 |
#' |
| 4 |
#' @param x A [binGroup::binWidth()] object. |
| 5 |
#' @template param_unused_dots |
| 6 |
#' |
| 7 |
#' @evalRd return_tidy("ci.width", "alternative", "p", |
| 8 |
#' n = "Total sample size" |
| 9 |
#' ) |
| 10 |
#' |
| 11 |
#' @examplesIf rlang::is_installed("binGroup") |
| 12 |
#' |
| 13 |
#' # load libraries |
| 14 |
#' library(binGroup) |
| 15 |
#' |
| 16 |
#' # fit model |
| 17 |
#' bw <- binWidth(100, .1) |
| 18 |
#' |
| 19 |
#' bw |
| 20 |
#' |
| 21 |
#' # summarize model fit with tidiers |
| 22 |
#' tidy(bw) |
| 23 |
#' |
| 24 |
#' @export |
| 25 |
#' @family bingroup tidiers |
| 26 |
#' @aliases binwidth_tidiers |
| 27 |
#' @seealso [tidy()], [binGroup::binWidth()] |
| 28 |
tidy.binWidth <- function(x, ...) { |
| 29 |
ret <- as_tibble(unclass(x)) |
| 30 |
rename(ret, ci.width = expCIWidth) |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
#' @templateVar class binDesign |
| 35 |
#' @template title_desc_tidy |
| 36 |
#' |
| 37 |
#' @param x A [binGroup::binDesign()] object. |
| 38 |
#' @template param_unused_dots |
| 39 |
#' |
| 40 |
#' @evalRd return_tidy( |
| 41 |
#' n = "Number of trials in given iteration.", |
| 42 |
#' power = "Power achieved for given value of n." |
| 43 |
#' ) |
| 44 |
#' |
| 45 |
#' @examplesIf rlang::is_installed(c("binGroup", "ggplot2")) |
| 46 |
#' |
| 47 |
#' library(binGroup) |
| 48 |
#' des <- binDesign( |
| 49 |
#' nmax = 300, delta = 0.06, |
| 50 |
#' p.hyp = 0.1, power = .8 |
| 51 |
#' ) |
| 52 |
#' |
| 53 |
#' glance(des) |
| 54 |
#' tidy(des) |
| 55 |
#' |
| 56 |
#' # the ggplot2 equivalent of plot(des) |
| 57 |
#' library(ggplot2) |
| 58 |
#' ggplot(tidy(des), aes(n, power)) + |
| 59 |
#' geom_line() |
| 60 |
#' |
| 61 |
#' @export |
| 62 |
#' @family bingroup tidiers |
| 63 |
#' @aliases bindesign_tidiers |
| 64 |
#' @seealso [tidy()], [binGroup::binDesign()] |
| 65 |
tidy.binDesign <- function(x, ...) { |
| 66 |
ret <- tibble(n = x$nit, power = x$powerit) |
| 67 |
# only up to the number of iterations performed |
| 68 |
head(ret, x$maxit) |
| 69 |
} |
| 70 |
|
| 71 |
#' @templateVar class binDesign |
| 72 |
#' @template title_desc_glance |
| 73 |
#' |
| 74 |
#' @param x A [binGroup::binDesign] object. |
| 75 |
#' @template param_unused_dots |
| 76 |
#' |
| 77 |
#' @evalRd return_glance( |
| 78 |
#' power = "Power achieved by the analysis.", |
| 79 |
#' n = "Sample size used to achieve this power.", |
| 80 |
#' power.reached = "Whether the desired power was reached.", |
| 81 |
#' maxit = "Number of iterations performed." |
| 82 |
#' ) |
| 83 |
#' |
| 84 |
#' @examplesIf rlang::is_installed(c("binGroup", "ggplot2")) |
| 85 |
#' |
| 86 |
#' # load libraries for models and data |
| 87 |
#' library(binGroup) |
| 88 |
#' |
| 89 |
#' des <- binDesign( |
| 90 |
#' nmax = 300, delta = 0.06, |
| 91 |
#' p.hyp = 0.1, power = .8 |
| 92 |
#' ) |
| 93 |
#' |
| 94 |
#' glance(des) |
| 95 |
#' tidy(des) |
| 96 |
#' |
| 97 |
#' library(ggplot2) |
| 98 |
#' |
| 99 |
#' ggplot(tidy(des), aes(n, power)) + |
| 100 |
#' geom_line() |
| 101 |
#' |
| 102 |
#' @export |
| 103 |
#' @family bingroup tidiers |
| 104 |
#' @seealso [glance()], [binGroup::binDesign()] |
| 105 |
glance.binDesign <- function(x, ...) { |
| 106 |
ux <- unclass(x) |
| 107 |
|
| 108 |
as_glance_tibble( |
| 109 |
power = ux$powerout, |
| 110 |
n = ux$nout, |
| 111 |
power.reached = ux$power.reached, |
| 112 |
maxit = ux$maxit, |
| 113 |
na_types = "riri" |
| 114 |
) |
| 115 |
} |