diff --git a/R/cor_sort.R b/R/cor_sort.R index c761ceaa..7c30d22f 100644 --- a/R/cor_sort.R +++ b/R/cor_sort.R @@ -26,9 +26,9 @@ cor_sort <- function(x, distance = "correlation", hclust_method = "complete", .. #' @export cor_sort.easycorrelation <- function(x, distance = "correlation", hclust_method = "complete", ...) { - order <- .cor_sort_order(as.matrix(x), distance = distance, hclust_method = hclust_method, ...) - x$Parameter1 <- factor(x$Parameter1, levels = order) - x$Parameter2 <- factor(x$Parameter2, levels = order) + col_order <- .cor_sort_order(as.matrix(x), distance = distance, hclust_method = hclust_method, ...) + x$Parameter1 <- factor(x$Parameter1, levels = col_order) + x$Parameter2 <- factor(x$Parameter2, levels = col_order) reordered <- x[order(x$Parameter1, x$Parameter2), ] # Restore class and attributes @@ -55,11 +55,11 @@ cor_sort.easycormatrix <- function(x, distance = "correlation", hclust_method = m <- x row.names(m) <- x$Parameter m <- as.matrix(m[names(m)[names(m) != "Parameter"]]) - order <- .cor_sort_order(m, distance = distance, hclust_method = hclust_method, ...) + col_order <- .cor_sort_order(m, distance = distance, hclust_method = hclust_method, ...) # Reorder - x$Parameter <- factor(x$Parameter, levels = order) - reordered <- x[order(x$Parameter), c("Parameter", order)] + x$Parameter <- factor(x$Parameter, levels = col_order) + reordered <- x[order(x$Parameter), c("Parameter", col_order)] # Restore class and attributes attributes(reordered) <- utils::modifyList( @@ -76,8 +76,8 @@ cor_sort.easycormatrix <- function(x, distance = "correlation", hclust_method = #' @export cor_sort.matrix <- function(x, distance = "correlation", hclust_method = "complete", ...) { - order <- .cor_sort_order(x, distance = distance, hclust_method = hclust_method, ...) - reordered <- x[order, order] + col_order <- .cor_sort_order(x, distance = distance, hclust_method = hclust_method, ...) + reordered <- x[col_order, col_order] # Restore class and attributes attributes(reordered) <- utils::modifyList( diff --git a/R/cor_test.R b/R/cor_test.R index 481dc782..60d31cdc 100644 --- a/R/cor_test.R +++ b/R/cor_test.R @@ -112,7 +112,9 @@ #' #' # Partial #' cor_test(iris, "Sepal.Length", "Sepal.Width", partial = TRUE) -#' cor_test(iris, "Sepal.Length", "Sepal.Width", multilevel = TRUE) +#' if (require("lme4", quietly = TRUE)) { +#' cor_test(iris, "Sepal.Length", "Sepal.Width", multilevel = TRUE) +#' } #' cor_test(iris, "Sepal.Length", "Sepal.Width", partial_bayesian = TRUE) #' } #' @export diff --git a/R/cor_test_bayes.R b/R/cor_test_bayes.R index 288b5a2c..d3519b25 100644 --- a/R/cor_test_bayes.R +++ b/R/cor_test_bayes.R @@ -17,7 +17,7 @@ var_x <- datawizard::ranktransform(var_x, sign = TRUE, method = "average") var_y <- datawizard::ranktransform(var_y, sign = TRUE, method = "average") method <- "Bayesian Spearman" - } else if (tolower(method) %in% "gaussian") { + } else if (tolower(method) == "gaussian") { var_x <- stats::qnorm(rank(var_x) / (length(var_x) + 1)) var_y <- stats::qnorm(rank(var_y) / (length(var_y) + 1)) method <- "Bayesian Gaussian rank" diff --git a/R/cor_test_biserial.R b/R/cor_test_biserial.R index f6aea4d4..99ecda53 100644 --- a/R/cor_test_biserial.R +++ b/R/cor_test_biserial.R @@ -56,11 +56,11 @@ m1 <- mean(var_x[var_y == 1]) m0 <- mean(var_x[var_y == 0]) - q <- mean(var_y) - p <- 1 - q - zp <- stats::dnorm(stats::qnorm(q)) + quan <- mean(var_y) + p <- 1 - quan + zp <- stats::dnorm(stats::qnorm(quan)) - r <- (((m1 - m0) * (p * q / zp)) / stats::sd(var_x)) + r <- (((m1 - m0) * (p * quan / zp)) / stats::sd(var_x)) p <- cor_to_p(r, n = length(var_x)) ci_vals <- cor_to_ci(r, n = length(var_x), ci = ci) diff --git a/R/cor_test_distance.R b/R/cor_test_distance.R index 2eb1c863..da35cb8a 100644 --- a/R/cor_test_distance.R +++ b/R/cor_test_distance.R @@ -3,21 +3,7 @@ var_x <- .complete_variable_x(data, x, y) var_y <- .complete_variable_y(data, x, y) - if (!corrected) { - rez <- .cor_test_distance_raw(var_x, var_y, index = 1) - rez <- data.frame( - Parameter1 = x, - Parameter2 = y, - r = rez$r, - CI_low = NA, - CI_high = NA, - t = NA, - df_error = NA, - p = NA, - Method = "Distance", - stringsAsFactors = FALSE - ) - } else { + if (corrected) { rez <- .cor_test_distance_corrected(var_x, var_y, ci = ci) rez <- data.frame( Parameter1 = x, @@ -31,6 +17,20 @@ Method = "Distance (Bias Corrected)", stringsAsFactors = FALSE ) + } else { + rez <- .cor_test_distance_raw(var_x, var_y, index = 1) + rez <- data.frame( + Parameter1 = x, + Parameter2 = y, + r = rez$r, + CI_low = NA, + CI_high = NA, + t = NA, + df_error = NA, + p = NA, + Method = "Distance", + stringsAsFactors = FALSE + ) } rez @@ -60,14 +60,14 @@ M <- n * (n - 3) / 2 dof <- M - 1 - t <- sqrt(M - 1) * r / sqrt(1 - r^2) - p <- 1 - stats::pt(t, df = dof) + tstat <- sqrt(M - 1) * r / sqrt(1 - r^2) + p <- 1 - stats::pt(tstat, df = dof) ci_vals <- cor_to_ci(r, n = n, ci = ci) list( r = r, - t = t, + t = tstat, df_error = dof, p = p, CI_low = ci_vals$CI_low, @@ -91,16 +91,16 @@ A <- .A_kl(x, index) B <- .A_kl(y, index) - cov <- sqrt(mean(A * B)) + cov_ab <- sqrt(mean(A * B)) dVarX <- sqrt(mean(A * A)) dVarY <- sqrt(mean(B * B)) V <- sqrt(dVarX * dVarY) if (V > 0) { - r <- cov / V + r <- cov_ab / V } else { r <- 0 } - list(r = r, cov = cov) + list(r = r, cov = cov_ab) } diff --git a/R/cor_test_freq.R b/R/cor_test_freq.R index 0d43056f..7ea4d175 100644 --- a/R/cor_test_freq.R +++ b/R/cor_test_freq.R @@ -42,10 +42,10 @@ .extract_corr_parameters <- function(model) { - names <- unlist(strsplit(model$data.name, " and ", fixed = TRUE)) + data_names <- unlist(strsplit(model$data.name, " and ", fixed = TRUE)) out <- data.frame( - "Parameter1" = names[1], - "Parameter2" = names[2], + Parameter1 = data_names[1], + Parameter2 = data_names[2], stringsAsFactors = FALSE ) diff --git a/R/cor_text.R b/R/cor_text.R index 481dc118..fa3d0ded 100644 --- a/R/cor_text.R +++ b/R/cor_text.R @@ -20,28 +20,28 @@ cor_text <- function(x, show_ci = TRUE, show_statistic = TRUE, show_sig = TRUE, # Estimate candidates <- c("rho", "r", "tau", "Difference", "r_rank_biserial") estimate <- candidates[candidates %in% names(x)][1] - text <- paste0(tolower(estimate), " = ", insight::format_value(x[[estimate]])) + out_text <- paste0(tolower(estimate), " = ", insight::format_value(x[[estimate]])) # CI if (show_ci && all(c("CI_high", "CI_low") %in% names(x))) { if (!is.null(attributes(x$conf.int)$conf.level)) { # htest - text <- paste0( - text, + out_text <- paste0( + out_text, ", ", insight::format_ci(x$CI_low, x$CI_high, ci = attributes(x$conf.int)$conf.level) ) } else if ("CI" %in% names(x)) { # param - text <- paste0( - text, + out_text <- paste0( + out_text, ", ", insight::format_ci(x$CI_low, x$CI_high, ci = x$CI) ) } else if ("ci" %in% names(attributes(x))) { # param - text <- paste0( - text, + out_text <- paste0( + out_text, ", ", insight::format_ci(x$CI_low, x$CI_high, ci = attributes(x)$ci) ) @@ -51,36 +51,36 @@ cor_text <- function(x, show_ci = TRUE, show_statistic = TRUE, show_sig = TRUE, # Statistic if (show_statistic) { if ("t" %in% names(x)) { - text <- paste0( - text, + out_text <- paste0( + out_text, ", t(", insight::format_value(x$df, protect_integers = TRUE), ") = ", insight::format_value(x$t) ) } else if ("S" %in% names(x)) { - text <- paste0(text, ", S = ", insight::format_value(x$S)) + out_text <- paste0(out_text, ", S = ", insight::format_value(x$S)) } else if ("z" %in% names(x)) { - text <- paste0(text, ", z = ", insight::format_value(table$z)) + out_text <- paste0(out_text, ", z = ", insight::format_value(table$z)) } else if ("W" %in% names(x)) { - text <- paste0("W = ", insight::format_value(x$W)) + out_text <- paste0("W = ", insight::format_value(x$W)) } else if ("Chi2" %in% names(x)) { - text <- paste0(text, ", Chi2 = ", insight::format_value(x$Chi2)) + out_text <- paste0(out_text, ", Chi2 = ", insight::format_value(x$Chi2)) } } # Significance if (show_sig) { if ("p" %in% names(x)) { - text <- paste0(text, ", ", insight::format_p(x$p, digits = "apa", ...)) + out_text <- paste0(out_text, ", ", insight::format_p(x$p, digits = "apa", ...)) } else if ("BF" %in% names(x)) { exact <- match.call()[["exact"]] if (is.null(exact)) exact <- TRUE - text <- paste0(text, ", ", insight::format_bf(x$BF, exact = exact, ...)) + out_text <- paste0(out_text, ", ", insight::format_bf(x$BF, exact = exact, ...)) } else if ("pd" %in% names(x)) { - text <- paste0(text, ", ", insight::format_pd(x$pd, ...)) + out_text <- paste0(out_text, ", ", insight::format_pd(x$pd, ...)) } } - text + out_text } diff --git a/R/cor_to_cov.R b/R/cor_to_cov.R index f876c9c6..9ba75ff7 100644 --- a/R/cor_to_cov.R +++ b/R/cor_to_cov.R @@ -43,8 +43,8 @@ cor_to_cov <- function(cor, sd = NULL, variance = NULL, tol = .Machine$double.ep is_symmetric <- FALSE } p <- dim(cor)[1] - q <- p * (p - 1) / 2 - if (isTRUE(all.equal(cor[lower.tri(cor)], rep(0, q))) || isTRUE(all.equal(cor[upper.tri(cor)], rep(0, q)))) { + quan <- p * (p - 1) / 2 + if (isTRUE(all.equal(cor[lower.tri(cor)], rep(0, quan))) || isTRUE(all.equal(cor[upper.tri(cor)], rep(0, quan)))) { is_triangular <- TRUE } else { is_triangular <- FALSE @@ -53,7 +53,7 @@ cor_to_cov <- function(cor, sd = NULL, variance = NULL, tol = .Machine$double.ep insight::format_error("'cor' should be either a symmetric or a triangular matrix") } - cov <- diag(sd) %*% cor %*% diag(sd) - colnames(cov) <- rownames(cov) <- colnames(cor) - cov + cov_matrix <- diag(sd) %*% cor %*% diag(sd) + colnames(cov_matrix) <- rownames(cov_matrix) <- colnames(cor) + cov_matrix } diff --git a/R/cor_to_pcor.R b/R/cor_to_pcor.R index b0bc1512..1837b980 100644 --- a/R/cor_to_pcor.R +++ b/R/cor_to_pcor.R @@ -52,10 +52,10 @@ cor_to_pcor.matrix <- function(cor, tol = .Machine$double.eps^(2 / 3)) { #' @export cor_to_pcor.easycormatrix <- function(cor, tol = .Machine$double.eps^(2 / 3)) { - if (!inherits(cor, "matrix")) { - .cor_to_pcor_easycormatrix(cor = cor, tol = tol) - } else { + if (inherits(cor, "matrix")) { NextMethod() + } else { + .cor_to_pcor_easycormatrix(cor = cor, tol = tol) } } @@ -86,10 +86,10 @@ pcor_to_cor.matrix <- function(pcor, tol = .Machine$double.eps^(2 / 3)) { #' @export pcor_to_cor.easycormatrix <- function(pcor, tol = .Machine$double.eps^(2 / 3)) { - if (!inherits(pcor, "matrix")) { - .cor_to_pcor_easycormatrix(pcor = pcor, tol = tol) - } else { + if (inherits(pcor, "matrix")) { NextMethod() + } else { + .cor_to_pcor_easycormatrix(pcor = pcor, tol = tol) } } @@ -114,28 +114,28 @@ pcor_to_cor.easycorrelation <- function(pcor, tol = .Machine$double.eps^(2 / 3)) # Extract info p_adjust <- attributes(cor)$p_adjust - nobs <- as.matrix(attributes(summary(cor, redundant = TRUE))$n_Obs[-1]) + number_obs <- as.matrix(attributes(summary(cor, redundant = TRUE))$n_Obs[-1]) # Get Statistics - p <- cor_to_p(r, n = nobs, method = "pearson") - ci_vals <- cor_to_ci(r, n = nobs, ci = attributes(cor)$ci) + p <- cor_to_p(r, n = number_obs, method = "pearson") + ci_vals <- cor_to_ci(r, n = number_obs, ci = attributes(cor)$ci) # Replace newdata <- data.frame() for (i in seq_len(nrow(cor))) { - row <- row.names(r) == cor[i, "Parameter1"] - col <- colnames(r) == cor[i, "Parameter2"] + row_index <- row.names(r) == cor[i, "Parameter1"] + col_index <- colnames(r) == cor[i, "Parameter2"] newdata <- rbind( newdata, data.frame( - r = r[row, col], - CI_low = ci_vals$CI_low[row, col], - CI_high = ci_vals$CI_high[row, col], - t = p$statistic[row, col], - df_error = nobs[row, col] - 2, - p = p$p[row, col], + r = r[row_index, col_index], + CI_low = ci_vals$CI_low[row_index, col_index], + CI_high = ci_vals$CI_high[row_index, col_index], + t = p$statistic[row_index, col_index], + df_error = number_obs[row_index, col_index] - 2, + p = p$p[row_index, col_index], Method = "Pearson", - n_Obs = nobs[row, col], + n_Obs = number_obs[row_index, col_index], stringsAsFactors = FALSE ) ) @@ -183,10 +183,10 @@ pcor_to_cor.easycorrelation <- function(pcor, tol = .Machine$double.eps^(2 / 3)) } p_adjust <- attributes(cor)$p_adjust - nobs <- as.matrix(attributes(cor)$n_Obs[-1]) + number_obs <- as.matrix(attributes(cor)$n_Obs[-1]) - p <- cor_to_p(r, n = nobs, method = "pearson") - ci_vals <- cor_to_ci(r, n = nobs, ci = attributes(cor)$ci) + p <- cor_to_p(r, n = number_obs, method = "pearson") + ci_vals <- cor_to_ci(r, n = number_obs, ci = attributes(cor)$ci) r <- cbind(data.frame(Parameter = row.names(r)), r) row.names(r) <- NULL @@ -247,15 +247,12 @@ pcor_to_cor.easycorrelation <- function(pcor, tol = .Machine$double.eps^(2 / 3)) # Get Cormatrix if (is.null(cor)) { if (is.null(cov)) { - stop("A correlation or covariance matrix is required.", call. = FALSE) - } else { - cor <- stats::cov2cor(cov) - } - } else { - if (inherits(cor, "easycormatrix") && colnames(cor)[1] == "Parameter") { - row.names(cor) <- cor$Parameter - cor <- as.matrix(cor[-1]) + insight::format_error("A correlation or covariance matrix is required.") } + cor <- stats::cov2cor(cov) + } else if (inherits(cor, "easycormatrix") && colnames(cor)[1] == "Parameter") { + row.names(cor) <- cor$Parameter + cor <- as.matrix(cor[-1]) } cor } diff --git a/R/cormatrix_to_excel.R b/R/cormatrix_to_excel.R index a028ad56..700f4673 100644 --- a/R/cormatrix_to_excel.R +++ b/R/cormatrix_to_excel.R @@ -47,19 +47,19 @@ cormatrix_to_excel <- function(data, print.mat = TRUE, ...) { if (missing(filename)) { - stop("Argument 'filename' required (as per CRAN policies)") + insight::format_error("Argument 'filename' required (as per CRAN policies).") } insight::check_if_installed("openxlsx2") # create correlation matrix with p values - cm <- correlation::correlation(data, ...) - cm <- summary(cm, redundant = TRUE) - all.columns <- 2:(ncol(cm)) + cormatrix <- correlation::correlation(data, ...) + cormatrix <- summary(cormatrix, redundant = TRUE) + all.columns <- 2:(ncol(cormatrix)) if (isTRUE(print.mat)) { - print(cm) + print(cormatrix) } - pf <- attr(cm, "p") + p_val <- attr(cormatrix, "p") # Define colours style_gray <- c(rgb = "C1CDCD") @@ -237,8 +237,8 @@ cormatrix_to_excel <- function(data, # wb$styles_mgr$dxf # create the worksheets and write the data to the worksheets. - wb$add_worksheet("r_values")$add_data(x = cm) - wb$add_worksheet("p_values")$add_data(x = pf) + wb$add_worksheet("r_values")$add_data(x = cormatrix) + wb$add_worksheet("p_values")$add_data(x = p_val) # create conditional formatting for the stars (as well as colours as we have no) # one star diff --git a/R/correlation.R b/R/correlation.R index 4297cefe..c450d6c9 100644 --- a/R/correlation.R +++ b/R/correlation.R @@ -369,19 +369,19 @@ correlation <- function(data, attributes(out) <- c( attributes(out), list( - "data" = data, - "data2" = data2, - "modelframe" = rez$data, - "ci" = ci, - "n" = nrow(data), - "method" = method, - "bayesian" = bayesian, - "p_adjust" = p_adjust, - "partial" = partial, - "multilevel" = multilevel, - "partial_bayesian" = partial_bayesian, - "bayesian_prior" = bayesian_prior, - "include_factors" = include_factors + data = data, + data2 = data2, + modelframe = rez$data, + ci = ci, + n = nrow(data), + method = method, + bayesian = bayesian, + p_adjust = p_adjust, + partial = partial, + multilevel = multilevel, + partial_bayesian = partial_bayesian, + bayesian_prior = bayesian_prior, + include_factors = include_factors ) ) @@ -429,39 +429,38 @@ correlation <- function(data, if (!is.null(data2)) { if (inherits(data2, "grouped_df")) { groups2 <- setdiff(colnames(attributes(data2)$groups), ".rows") - if (all.equal(groups, groups2)) { - ungrouped_y <- as.data.frame(data2) - ylist <- split(ungrouped_y, ungrouped_y[groups], sep = " - ") - modelframe <- data.frame() - out <- data.frame() - for (i in names(xlist)) { - xlist[[i]][groups] <- NULL - ylist[[i]][groups] <- NULL - rez <- .correlation( - xlist[[i]], - data2 = ylist[[i]], - method = method, - p_adjust = p_adjust, - ci = ci, - bayesian = bayesian, - bayesian_prior = bayesian_prior, - bayesian_ci_method = bayesian_ci_method, - bayesian_test = bayesian_test, - redundant = redundant, - include_factors = include_factors, - partial = partial, - partial_bayesian = partial_bayesian, - multilevel = multilevel, - ranktransform = ranktransform, - winsorize = winsorize - ) - modelframe_current <- rez$data - rez$params$Group <- modelframe_current$Group <- i - out <- rbind(out, rez$params) - modelframe <- rbind(modelframe, modelframe_current) - } - } else { - stop("'data2' should have the same grouping characteristics as data.", call. = FALSE) + if (!all.equal(groups, groups2)) { + insight::format_error("'data2' should have the same grouping characteristics as data.") + } + ungrouped_y <- as.data.frame(data2) + ylist <- split(ungrouped_y, ungrouped_y[groups], sep = " - ") + modelframe <- data.frame() + out <- data.frame() + for (i in names(xlist)) { + xlist[[i]][groups] <- NULL + ylist[[i]][groups] <- NULL + rez <- .correlation( + xlist[[i]], + data2 = ylist[[i]], + method = method, + p_adjust = p_adjust, + ci = ci, + bayesian = bayesian, + bayesian_prior = bayesian_prior, + bayesian_ci_method = bayesian_ci_method, + bayesian_test = bayesian_test, + redundant = redundant, + include_factors = include_factors, + partial = partial, + partial_bayesian = partial_bayesian, + multilevel = multilevel, + ranktransform = ranktransform, + winsorize = winsorize + ) + modelframe_current <- rez$data + rez$params$Group <- modelframe_current$Group <- i + out <- rbind(out, rez$params) + modelframe <- rbind(modelframe, modelframe_current) } } # else diff --git a/R/methods_format.R b/R/methods_format.R index c30d910c..24300db7 100644 --- a/R/methods_format.R +++ b/R/methods_format.R @@ -45,7 +45,7 @@ format.easycormatrix <- function(x, # If it's a real matrix if (!"Parameter" %in% colnames(x)) { m <- as.data.frame(x) - return(cbind(data.frame("Variables" = row.names(x)), m)) + return(cbind(data.frame(Variables = row.names(x)), m)) } # Find attributes @@ -105,7 +105,7 @@ format.easycormatrix <- function(x, } if (!stars_only) { - sig[, nums] <- sapply(sig[, nums], function(x) ifelse(x != "", paste0(" (", x, ")"), "")) + sig[, nums] <- sapply(sig[, nums], function(x) ifelse(x != "", paste0(" (", x, ")"), "")) # nolint } if (include_significance || stars) { @@ -146,11 +146,11 @@ format.easycormatrix <- function(x, # N-obs if (!is.null(x$n_Obs)) { if (length(unique(x$n_Obs)) == 1) { - nobs <- unique(x$n_Obs) + number_obs <- unique(x$n_Obs) } else { - nobs <- paste0(min(x$n_Obs), "-", max(x$n_Obs)) + number_obs <- paste0(min(x$n_Obs), "-", max(x$n_Obs)) } - footer <- paste0(footer, "\nObservations: ", nobs) + footer <- paste0(footer, "\nObservations: ", number_obs) } # final new line @@ -158,8 +158,8 @@ format.easycormatrix <- function(x, # for html/markdown, create list if (!is.null(format) && format != "text") { - footer <- unlist(strsplit(footer, "\n")) - footer <- as.list(footer[nchar(footer) > 0]) + footer <- unlist(strsplit(footer, "\n", fixed = TRUE)) + footer <- as.list(footer[nzchar(footer, keepNA = TRUE)]) } footer diff --git a/inst/WORDLIST b/inst/WORDLIST index ad94ff56..101ffc38 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -94,6 +94,7 @@ pinv polychoric pracma rOpenSci +rempsyc rescaled ressembles rmarkdown diff --git a/man/cor_test.Rd b/man/cor_test.Rd index faa3a768..a4e18f39 100644 --- a/man/cor_test.Rd +++ b/man/cor_test.Rd @@ -271,7 +271,9 @@ if (require("psych", quietly = TRUE) && require("rstanarm", quietly = TRUE)) { # Partial cor_test(iris, "Sepal.Length", "Sepal.Width", partial = TRUE) -cor_test(iris, "Sepal.Length", "Sepal.Width", multilevel = TRUE) +if (require("lme4", quietly = TRUE)) { + cor_test(iris, "Sepal.Length", "Sepal.Width", multilevel = TRUE) +} cor_test(iris, "Sepal.Length", "Sepal.Width", partial_bayesian = TRUE) } } diff --git a/tests/testthat/test-cor_test_na_present.R b/tests/testthat/test-cor_test_na_present.R index 8e1b0c4e..5f8d6502 100644 --- a/tests/testthat/test-cor_test_na_present.R +++ b/tests/testthat/test-cor_test_na_present.R @@ -11,7 +11,7 @@ test_that("cor_test kendall", { skip_if_not_or_load_if_installed("ggplot2") out <- cor_test(ggplot2::msleep, "brainwt", "sleep_rem", method = "kendall") - out2 <- stats::cor.test(ggplot2::msleep$brainwt, ggplot2::msleep$sleep_rem, method = "kendall") + out2 <- suppressWarnings(stats::cor.test(ggplot2::msleep$brainwt, ggplot2::msleep$sleep_rem, method = "kendall")) expect_equal(out$tau, out2$estimate[[1]], tolerance = 0.001) expect_equal(out$p, out2$p.value[[1]], tolerance = 0.001) @@ -31,8 +31,8 @@ test_that("cor_test tetrachoric", { skip_if_not_or_load_if_installed("ggplot2") data <- ggplot2::msleep - data$brainwt_binary <- ifelse(data$brainwt > 3, 1, 0) - data$sleep_rem_binary <- ifelse(data$sleep_rem > 1.2, 1, 0) + data$brainwt_binary <- as.numeric(data$brainwt > 3) + data$sleep_rem_binary <- as.numeric(data$sleep_rem > 1.2) # With Factors / Binary expect_error(cor_test(data, "brainwt_binary", "sleep_rem_binary", method = "tetrachoric")) @@ -40,7 +40,7 @@ test_that("cor_test tetrachoric", { data$sleep_rem_ordinal <- as.factor(round(data$sleep_rem)) data$brainwt_ordinal <- as.factor(round(data$brainwt)) - out <- cor_test(data, "brainwt", "brainwt_ordinal", method = "polychoric") + out <- suppressWarnings(cor_test(data, "brainwt", "brainwt_ordinal", method = "polychoric")) expect_equal(out$rho, 0.9999, tolerance = 0.01) # Biserial