-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_t_paired.R
59 lines (47 loc) · 1.24 KB
/
test_t_paired.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#' Paired t-test
#'
#' @param x x
#' @param y y
#' @param ... other arguments passed to paired t-test
#' @return results
#' @export
#'
test_t_paired <- function(x, y, ...) {
lower_ci <- upper_ci <- X1 <- X2 <- NULL
result <- stats::t.test(x, y, paired = TRUE, ...)
result2 <- result$estimate |>
data.frame() |>
t() |>
data.frame()
ci <- result$conf.int |>
t() |>
data.frame() |>
dplyr::rename(
lower_ci = X1,
upper_ci = X2
) |>
dplyr::mutate(
lower_ci = round(lower_ci, 2),
upper_ci = round(upper_ci, 2)
)
ci_level <- attributes(result$conf.int) |> unlist()
cli::cli_h1(result$method)
result2 <- result2 |>
dplyr::mutate(
t = round(result$statistic, 2),
p = scales::pvalue(result$p.value),
df = round(result$parameter),
ci_level = ci_level
) |>
dplyr::bind_cols(tibble::tibble(ci)) |>
t() |>
data.frame() |>
tibble::rownames_to_column(" ") |>
data.frame()
result2 <- result2 |> huxtable::as_hux()
huxtable::position(result2) <- "left"
result2 <- huxtable::map_align(result2, huxtable::by_cols("left", "right"))
huxtable::print_screen(result2, colnames = FALSE)
result3 <- data.frame(result2)
return(invisible(result3))
}