|
18 | 18 | }
|
19 | 19 | data[[binary]] <- as.vector((data[[binary]] - min(data[[binary]], na.rm = TRUE)) / diff(range(data[[binary]], na.rm = TRUE), na.rm = TRUE))
|
20 | 20 |
|
21 |
| - # Get biserial correlation |
| 21 | + # Get biserial or point-biserial correlation |
22 | 22 | if (method == "biserial") {
|
23 | 23 | out <- .cor_test_biserial_biserial(data, x, y, continuous, binary, ci)
|
24 |
| - |
25 |
| - # Get point-biserial correlation |
26 | 24 | } else {
|
27 |
| - out <- .cor_test_freq(data, continuous, binary, ci = ci, method = "pearson", ...) |
28 |
| - names(out)[names(out) == "r"] <- "rho" |
29 |
| - out$Parameter1 <- x |
30 |
| - out$Parameter2 <- y |
31 |
| - out$Method <- "Point-biserial" |
| 25 | + out <- .cor_test_biserial_pointbiserial(data, x, y, continuous, binary, ci, ...) |
32 | 26 | }
|
33 | 27 |
|
34 | 28 | out
|
35 | 29 | }
|
36 | 30 |
|
37 | 31 |
|
38 | 32 |
|
| 33 | +#' @keywords internal |
| 34 | +.cor_test_biserial_pointbiserial <- function(data, x, y, continuous, binary, ci, ...) { |
39 | 35 |
|
| 36 | + out <- .cor_test_freq(data, continuous, binary, ci = ci, method = "pearson", ...) |
| 37 | + names(out)[names(out) == "r"] <- "rho" |
| 38 | + out$Parameter1 <- x |
| 39 | + out$Parameter2 <- y |
| 40 | + out$Method <- "Point-biserial" |
40 | 41 |
|
41 |
| - |
42 |
| - |
43 |
| - |
44 |
| - |
45 |
| - |
46 |
| - |
| 42 | + out |
| 43 | +} |
47 | 44 |
|
48 | 45 |
|
49 | 46 |
|
50 | 47 | #' @keywords internal
|
51 | 48 | .cor_test_biserial_biserial <- function(data, x, y, continuous, binary, ci) {
|
52 |
| - if (!requireNamespace("psych", quietly = TRUE)) { |
53 |
| - stop("Package `psych` required for biserial correlations. Please install it by running `install.packages('psych').", call. = FALSE) |
54 |
| - } |
55 | 49 |
|
56 | 50 | var_x <- .complete_variable_x(data, continuous, binary)
|
57 | 51 | var_y <- .complete_variable_y(data, continuous, binary)
|
|
0 commit comments