From 9dcc2cfcff8c4376c17cee18991b293d69bf129b Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 24 Jul 2024 13:41:42 +0200 Subject: [PATCH 1/4] Fix CRAN note Fixes #323 --- DESCRIPTION | 24 +++++++++---------- R/cor_test.R | 58 ++++++++++++++++++++++------------------------ man/cor_test.Rd | 58 ++++++++++++++++++++++------------------------ man/cor_to_p.Rd | 23 +++++++++--------- man/correlation.Rd | 58 ++++++++++++++++++++++------------------------ 5 files changed, 107 insertions(+), 114 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 749e4e2a..2e01870b 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Type: Package Package: correlation Title: Methods for Correlation Analysis -Version: 0.8.5 -Authors@R: +Version: 0.8.5.1 +Authors@R: c(person(given = "Dominique", family = "Makowski", role = c("aut", "inv"), @@ -28,19 +28,19 @@ Authors@R: role = "aut", email = "matanshm@post.bgu.ac.il", comment = c(ORCID = "0000-0002-4287-4801", Twitter = "@mattansb")), - person(given = "Rémi", + person(given = "Rémi", family = "Thériault", - role = c("aut"), + role = c("aut"), email = "remi.theriault@mail.mcgill.ca", comment = c(ORCID = "0000-0003-4315-6788", Twitter = "@rempsyc")), - person(given = "Mark", - family = "White", + person(given = "Mark", + family = "White", email = "markhwhiteii@gmail.com", role = "rev"), - person(given = "Maximilian M.", - family = "Rabe", - email = "maximilian.rabe@uni-potsdam.de", - role = "rev", + person(given = "Maximilian M.", + family = "Rabe", + email = "maximilian.rabe@uni-potsdam.de", + role = "rev", comment = c(ORCID = "0000-0002-2556-5644"))) Maintainer: Brenton M. Wiernik Description: Lightweight package for computing different kinds @@ -84,11 +84,11 @@ Suggests: wdm, WRS2, openxlsx2 -VignetteBuilder: +VignetteBuilder: knitr Encoding: UTF-8 Language: en-US -RoxygenNote: 7.3.1 +RoxygenNote: 7.3.2 Roxygen: list(markdown = TRUE) Config/testthat/edition: 3 Config/Needs/website: diff --git a/R/cor_test.R b/R/cor_test.R index 787caf23..73dba68d 100644 --- a/R/cor_test.R +++ b/R/cor_test.R @@ -8,18 +8,17 @@ #' @param ci Confidence/Credible Interval level. If `"default"`, then it is #' set to `0.95` (`95%` CI). #' @param method A character string indicating which correlation coefficient is -#' to be used for the test. One of `"pearson"` (default), -#' `"kendall"`, `"spearman"` (but see also the `robust` argument), `"biserial"`, -#' `"polychoric"`, `"tetrachoric"`, `"biweight"`, -#' `"distance"`, `"percentage"` (for percentage bend correlation), -#' `"blomqvist"` (for Blomqvist's coefficient), `"hoeffding"` (for -#' Hoeffding's D), `"gamma"`, `"gaussian"` (for Gaussian Rank -#' correlation) or `"shepherd"` (for Shepherd's Pi correlation). Setting -#' `"auto"` will attempt at selecting the most relevant method -#' (polychoric when ordinal factors involved, tetrachoric when dichotomous -#' factors involved, point-biserial if one dichotomous and one continuous and -#' pearson otherwise). See below the **details** section for a description of -#' these indices. +#' to be used for the test. One of `"pearson"` (default), `"kendall"`, +#' `"spearman"` (but see also the `robust` argument), `"biserial"`, +#' `"polychoric"`, `"tetrachoric"`, `"biweight"`, `"distance"`, `"percentage"` +#' (for percentage bend correlation), `"blomqvist"` (for Blomqvist's +#' coefficient), `"hoeffding"` (for Hoeffding's D), `"gamma"`, `"gaussian"` +#' (for Gaussian Rank correlation) or `"shepherd"` (for Shepherd's Pi +#' correlation). Setting `"auto"` will attempt at selecting the most relevant +#' method (polychoric when ordinal factors involved, tetrachoric when +#' dichotomous factors involved, point-biserial if one dichotomous and one +#' continuous and pearson otherwise). See below the **details** section for a +#' description of these indices. #' @param bayesian If `TRUE`, will run the correlations under a Bayesian #' framework. #' @param partial_bayesian If partial correlations under a Bayesian framework @@ -28,30 +27,29 @@ #' pseudo-Bayesian partial correlations (i.e., Bayesian correlation based on #' frequentist partialization). #' @param include_factors If `TRUE`, the factors are kept and eventually -#' converted to numeric or used as random effects (depending of -#' `multilevel`). If `FALSE`, factors are removed upfront. -#' @param partial Can be `TRUE` or `"semi"` for partial and -#' semi-partial correlations, respectively. +#' converted to numeric or used as random effects (depending of `multilevel`). +#' If `FALSE`, factors are removed upfront. +#' @param partial Can be `TRUE` or `"semi"` for partial and semi-partial +#' correlations, respectively. #' @inheritParams datawizard::adjust #' @param bayesian_prior For the prior argument, several named values are -#' recognized: `"medium.narrow"`, `"medium"`, `"wide"`, and -#' `"ultrawide"`. These correspond to scale values of `1/sqrt(27)`, -#' `1/3`, `1/sqrt(3)` and `1`, respectively. See the -#' `BayesFactor::correlationBF` function. +#' recognized: `"medium.narrow"`, `"medium"`, `"wide"`, and `"ultrawide"`. +#' These correspond to scale values of `1/sqrt(27)`, `1/3`, `1/sqrt(3)` and +#' `1`, respectively. See the `BayesFactor::correlationBF` function. #' @param bayesian_ci_method,bayesian_test See arguments in -#' [`model_parameters()`][parameters] for `BayesFactor` tests. +#' [`parameters::model_parameters()`] for `BayesFactor` tests. #' @param ranktransform If `TRUE`, will rank-transform the variables prior to #' estimating the correlation, which is one way of making the analysis more -#' resistant to extreme values (outliers). Note that, for instance, a Pearson's -#' correlation on rank-transformed data is equivalent to a Spearman's rank -#' correlation. Thus, using `robust=TRUE` and `method="spearman"` is -#' redundant. Nonetheless, it is an easy option to increase the robustness of the -#' correlation as well as flexible way to obtain Bayesian or multilevel -#' Spearman-like rank correlations. +#' resistant to extreme values (outliers). Note that, for instance, a +#' Pearson's correlation on rank-transformed data is equivalent to a +#' Spearman's rank correlation. Thus, using `robust=TRUE` and +#' `method="spearman"` is redundant. Nonetheless, it is an easy option to +#' increase the robustness of the correlation as well as flexible way to +#' obtain Bayesian or multilevel Spearman-like rank correlations. #' @param winsorize Another way of making the correlation more "robust" (i.e., -#' limiting the impact of extreme values). Can be either `FALSE` or a -#' number between 0 and 1 (e.g., `0.2`) that corresponds to the desired -#' threshold. See the [`winsorize()`][winsorize] function for more details. +#' limiting the impact of extreme values). Can be either `FALSE` or a number +#' between 0 and 1 (e.g., `0.2`) that corresponds to the desired threshold. +#' See the [`datawizard::winsorize()`] function for more details. #' @param verbose Toggle warnings. #' @param ... Additional arguments (e.g., `alternative`) to be passed to #' other methods. See `stats::cor.test` for further details. diff --git a/man/cor_test.Rd b/man/cor_test.Rd index b28684c2..9cbb328d 100644 --- a/man/cor_test.Rd +++ b/man/cor_test.Rd @@ -30,18 +30,17 @@ cor_test( \item{x, y}{Names of two variables present in the data.} \item{method}{A character string indicating which correlation coefficient is -to be used for the test. One of \code{"pearson"} (default), -\code{"kendall"}, \code{"spearman"} (but see also the \code{robust} argument), \code{"biserial"}, -\code{"polychoric"}, \code{"tetrachoric"}, \code{"biweight"}, -\code{"distance"}, \code{"percentage"} (for percentage bend correlation), -\code{"blomqvist"} (for Blomqvist's coefficient), \code{"hoeffding"} (for -Hoeffding's D), \code{"gamma"}, \code{"gaussian"} (for Gaussian Rank -correlation) or \code{"shepherd"} (for Shepherd's Pi correlation). Setting -\code{"auto"} will attempt at selecting the most relevant method -(polychoric when ordinal factors involved, tetrachoric when dichotomous -factors involved, point-biserial if one dichotomous and one continuous and -pearson otherwise). See below the \strong{details} section for a description of -these indices.} +to be used for the test. One of \code{"pearson"} (default), \code{"kendall"}, +\code{"spearman"} (but see also the \code{robust} argument), \code{"biserial"}, +\code{"polychoric"}, \code{"tetrachoric"}, \code{"biweight"}, \code{"distance"}, \code{"percentage"} +(for percentage bend correlation), \code{"blomqvist"} (for Blomqvist's +coefficient), \code{"hoeffding"} (for Hoeffding's D), \code{"gamma"}, \code{"gaussian"} +(for Gaussian Rank correlation) or \code{"shepherd"} (for Shepherd's Pi +correlation). Setting \code{"auto"} will attempt at selecting the most relevant +method (polychoric when ordinal factors involved, tetrachoric when +dichotomous factors involved, point-biserial if one dichotomous and one +continuous and pearson otherwise). See below the \strong{details} section for a +description of these indices.} \item{ci}{Confidence/Credible Interval level. If \code{"default"}, then it is set to \code{0.95} (\verb{95\%} CI).} @@ -50,20 +49,19 @@ set to \code{0.95} (\verb{95\%} CI).} framework.} \item{bayesian_prior}{For the prior argument, several named values are -recognized: \code{"medium.narrow"}, \code{"medium"}, \code{"wide"}, and -\code{"ultrawide"}. These correspond to scale values of \code{1/sqrt(27)}, -\code{1/3}, \code{1/sqrt(3)} and \code{1}, respectively. See the -\code{BayesFactor::correlationBF} function.} +recognized: \code{"medium.narrow"}, \code{"medium"}, \code{"wide"}, and \code{"ultrawide"}. +These correspond to scale values of \code{1/sqrt(27)}, \code{1/3}, \code{1/sqrt(3)} and +\code{1}, respectively. See the \code{BayesFactor::correlationBF} function.} \item{bayesian_ci_method, bayesian_test}{See arguments in -\code{\link[=parameters]{model_parameters()}} for \code{BayesFactor} tests.} +\code{\link[parameters:model_parameters]{parameters::model_parameters()}} for \code{BayesFactor} tests.} \item{include_factors}{If \code{TRUE}, the factors are kept and eventually -converted to numeric or used as random effects (depending of -\code{multilevel}). If \code{FALSE}, factors are removed upfront.} +converted to numeric or used as random effects (depending of \code{multilevel}). +If \code{FALSE}, factors are removed upfront.} -\item{partial}{Can be \code{TRUE} or \code{"semi"} for partial and -semi-partial correlations, respectively.} +\item{partial}{Can be \code{TRUE} or \code{"semi"} for partial and semi-partial +correlations, respectively.} \item{partial_bayesian}{If partial correlations under a Bayesian framework are needed, you will also need to set \code{partial_bayesian} to \code{TRUE} to @@ -77,17 +75,17 @@ simple regression model.} \item{ranktransform}{If \code{TRUE}, will rank-transform the variables prior to estimating the correlation, which is one way of making the analysis more -resistant to extreme values (outliers). Note that, for instance, a Pearson's -correlation on rank-transformed data is equivalent to a Spearman's rank -correlation. Thus, using \code{robust=TRUE} and \code{method="spearman"} is -redundant. Nonetheless, it is an easy option to increase the robustness of the -correlation as well as flexible way to obtain Bayesian or multilevel -Spearman-like rank correlations.} +resistant to extreme values (outliers). Note that, for instance, a +Pearson's correlation on rank-transformed data is equivalent to a +Spearman's rank correlation. Thus, using \code{robust=TRUE} and +\code{method="spearman"} is redundant. Nonetheless, it is an easy option to +increase the robustness of the correlation as well as flexible way to +obtain Bayesian or multilevel Spearman-like rank correlations.} \item{winsorize}{Another way of making the correlation more "robust" (i.e., -limiting the impact of extreme values). Can be either \code{FALSE} or a -number between 0 and 1 (e.g., \code{0.2}) that corresponds to the desired -threshold. See the \code{\link[=winsorize]{winsorize()}} function for more details.} +limiting the impact of extreme values). Can be either \code{FALSE} or a number +between 0 and 1 (e.g., \code{0.2}) that corresponds to the desired threshold. +See the \code{\link[datawizard:winsorize]{datawizard::winsorize()}} function for more details.} \item{verbose}{Toggle warnings.} diff --git a/man/cor_to_p.Rd b/man/cor_to_p.Rd index b56a2e44..4867bd4a 100644 --- a/man/cor_to_p.Rd +++ b/man/cor_to_p.Rd @@ -18,18 +18,17 @@ cor_to_p(cor, n, method = "pearson") set to \code{0.95} (\verb{95\%} CI).} \item{method}{A character string indicating which correlation coefficient is -to be used for the test. One of \code{"pearson"} (default), -\code{"kendall"}, \code{"spearman"} (but see also the \code{robust} argument), \code{"biserial"}, -\code{"polychoric"}, \code{"tetrachoric"}, \code{"biweight"}, -\code{"distance"}, \code{"percentage"} (for percentage bend correlation), -\code{"blomqvist"} (for Blomqvist's coefficient), \code{"hoeffding"} (for -Hoeffding's D), \code{"gamma"}, \code{"gaussian"} (for Gaussian Rank -correlation) or \code{"shepherd"} (for Shepherd's Pi correlation). Setting -\code{"auto"} will attempt at selecting the most relevant method -(polychoric when ordinal factors involved, tetrachoric when dichotomous -factors involved, point-biserial if one dichotomous and one continuous and -pearson otherwise). See below the \strong{details} section for a description of -these indices.} +to be used for the test. One of \code{"pearson"} (default), \code{"kendall"}, +\code{"spearman"} (but see also the \code{robust} argument), \code{"biserial"}, +\code{"polychoric"}, \code{"tetrachoric"}, \code{"biweight"}, \code{"distance"}, \code{"percentage"} +(for percentage bend correlation), \code{"blomqvist"} (for Blomqvist's +coefficient), \code{"hoeffding"} (for Hoeffding's D), \code{"gamma"}, \code{"gaussian"} +(for Gaussian Rank correlation) or \code{"shepherd"} (for Shepherd's Pi +correlation). Setting \code{"auto"} will attempt at selecting the most relevant +method (polychoric when ordinal factors involved, tetrachoric when +dichotomous factors involved, point-biserial if one dichotomous and one +continuous and pearson otherwise). See below the \strong{details} section for a +description of these indices.} \item{correction}{Only used if method is 'spearman' or 'kendall'. Can be 'fieller' (default; Fieller et al., 1957), 'bw' (only for Spearman) or diff --git a/man/correlation.Rd b/man/correlation.Rd index 926c705e..413c8f6c 100644 --- a/man/correlation.Rd +++ b/man/correlation.Rd @@ -52,18 +52,17 @@ Note that the number of names should be equal to the number of columns selected. Ignored if \code{data2} is specified.} \item{method}{A character string indicating which correlation coefficient is -to be used for the test. One of \code{"pearson"} (default), -\code{"kendall"}, \code{"spearman"} (but see also the \code{robust} argument), \code{"biserial"}, -\code{"polychoric"}, \code{"tetrachoric"}, \code{"biweight"}, -\code{"distance"}, \code{"percentage"} (for percentage bend correlation), -\code{"blomqvist"} (for Blomqvist's coefficient), \code{"hoeffding"} (for -Hoeffding's D), \code{"gamma"}, \code{"gaussian"} (for Gaussian Rank -correlation) or \code{"shepherd"} (for Shepherd's Pi correlation). Setting -\code{"auto"} will attempt at selecting the most relevant method -(polychoric when ordinal factors involved, tetrachoric when dichotomous -factors involved, point-biserial if one dichotomous and one continuous and -pearson otherwise). See below the \strong{details} section for a description of -these indices.} +to be used for the test. One of \code{"pearson"} (default), \code{"kendall"}, +\code{"spearman"} (but see also the \code{robust} argument), \code{"biserial"}, +\code{"polychoric"}, \code{"tetrachoric"}, \code{"biweight"}, \code{"distance"}, \code{"percentage"} +(for percentage bend correlation), \code{"blomqvist"} (for Blomqvist's +coefficient), \code{"hoeffding"} (for Hoeffding's D), \code{"gamma"}, \code{"gaussian"} +(for Gaussian Rank correlation) or \code{"shepherd"} (for Shepherd's Pi +correlation). Setting \code{"auto"} will attempt at selecting the most relevant +method (polychoric when ordinal factors involved, tetrachoric when +dichotomous factors involved, point-biserial if one dichotomous and one +continuous and pearson otherwise). See below the \strong{details} section for a +description of these indices.} \item{p_adjust}{Correction method for frequentist correlations. Can be one of \code{"holm"} (default), \code{"hochberg"}, \code{"hommel"}, @@ -78,23 +77,22 @@ set to \code{0.95} (\verb{95\%} CI).} framework.} \item{bayesian_prior}{For the prior argument, several named values are -recognized: \code{"medium.narrow"}, \code{"medium"}, \code{"wide"}, and -\code{"ultrawide"}. These correspond to scale values of \code{1/sqrt(27)}, -\code{1/3}, \code{1/sqrt(3)} and \code{1}, respectively. See the -\code{BayesFactor::correlationBF} function.} +recognized: \code{"medium.narrow"}, \code{"medium"}, \code{"wide"}, and \code{"ultrawide"}. +These correspond to scale values of \code{1/sqrt(27)}, \code{1/3}, \code{1/sqrt(3)} and +\code{1}, respectively. See the \code{BayesFactor::correlationBF} function.} \item{bayesian_ci_method, bayesian_test}{See arguments in -\code{\link[=parameters]{model_parameters()}} for \code{BayesFactor} tests.} +\code{\link[parameters:model_parameters]{parameters::model_parameters()}} for \code{BayesFactor} tests.} \item{redundant}{Should the data include redundant rows (where each given correlation is repeated two times).} \item{include_factors}{If \code{TRUE}, the factors are kept and eventually -converted to numeric or used as random effects (depending of -\code{multilevel}). If \code{FALSE}, factors are removed upfront.} +converted to numeric or used as random effects (depending of \code{multilevel}). +If \code{FALSE}, factors are removed upfront.} -\item{partial}{Can be \code{TRUE} or \code{"semi"} for partial and -semi-partial correlations, respectively.} +\item{partial}{Can be \code{TRUE} or \code{"semi"} for partial and semi-partial +correlations, respectively.} \item{partial_bayesian}{If partial correlations under a Bayesian framework are needed, you will also need to set \code{partial_bayesian} to \code{TRUE} to @@ -108,17 +106,17 @@ simple regression model.} \item{ranktransform}{If \code{TRUE}, will rank-transform the variables prior to estimating the correlation, which is one way of making the analysis more -resistant to extreme values (outliers). Note that, for instance, a Pearson's -correlation on rank-transformed data is equivalent to a Spearman's rank -correlation. Thus, using \code{robust=TRUE} and \code{method="spearman"} is -redundant. Nonetheless, it is an easy option to increase the robustness of the -correlation as well as flexible way to obtain Bayesian or multilevel -Spearman-like rank correlations.} +resistant to extreme values (outliers). Note that, for instance, a +Pearson's correlation on rank-transformed data is equivalent to a +Spearman's rank correlation. Thus, using \code{robust=TRUE} and +\code{method="spearman"} is redundant. Nonetheless, it is an easy option to +increase the robustness of the correlation as well as flexible way to +obtain Bayesian or multilevel Spearman-like rank correlations.} \item{winsorize}{Another way of making the correlation more "robust" (i.e., -limiting the impact of extreme values). Can be either \code{FALSE} or a -number between 0 and 1 (e.g., \code{0.2}) that corresponds to the desired -threshold. See the \code{\link[=winsorize]{winsorize()}} function for more details.} +limiting the impact of extreme values). Can be either \code{FALSE} or a number +between 0 and 1 (e.g., \code{0.2}) that corresponds to the desired threshold. +See the \code{\link[datawizard:winsorize]{datawizard::winsorize()}} function for more details.} \item{verbose}{Toggle warnings.} From c1f02c29e86ae3c09b3bc9d722f9018a3df582fa Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 24 Jul 2024 13:42:04 +0200 Subject: [PATCH 2/4] dw version --- DESCRIPTION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 2e01870b..db52bf54 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -56,7 +56,7 @@ Depends: Imports: bayestestR (>= 0.13.2), datasets, - datawizard (>= 0.11.0), + datawizard (>= 0.10.0), insight (>= 0.20.0), parameters (>= 0.21.7), stats From 2733d68f2db728d0f1dfd01b6008fba4c8e135ef Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 24 Jul 2024 21:10:51 +0200 Subject: [PATCH 3/4] fix warnings --- R/cor_test_bayes.R | 12 ++++++++++-- tests/testthat/test-correlation.R | 2 +- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/R/cor_test_bayes.R b/R/cor_test_bayes.R index d3519b25..e9acaa5c 100644 --- a/R/cor_test_bayes.R +++ b/R/cor_test_bayes.R @@ -58,7 +58,11 @@ if (x == y) { # Avoid error in the case of perfect correlation - rez <- BayesFactor::correlationBF(stats::rnorm(1000), stats::rnorm(1000), rscale = bayesian_prior) + rez <- suppressWarnings(BayesFactor::correlationBF( + stats::rnorm(1000), + stats::rnorm(1000), + rscale = bayesian_prior + )) params <- parameters::model_parameters( rez, dispersion = FALSE, @@ -79,7 +83,11 @@ if ("ROPE_Percentage" %in% names(params)) params$ROPE_Percentage <- 0 if ("BF" %in% names(params)) params$BF <- Inf } else { - rez <- BayesFactor::correlationBF(var_x, var_y, rscale = bayesian_prior) + rez <- suppressWarnings(BayesFactor::correlationBF( + var_x, + var_y, + rscale = bayesian_prior + )) params <- parameters::model_parameters( rez, dispersion = FALSE, diff --git a/tests/testthat/test-correlation.R b/tests/testthat/test-correlation.R index 8a7cce48..7478e11c 100644 --- a/tests/testthat/test-correlation.R +++ b/tests/testthat/test-correlation.R @@ -177,7 +177,7 @@ test_that("specific types", { y = as.ordered(sample(letters[1:5], 20, TRUE)) ) - correlation(data, method = "polychoric") + expect_warning(correlation(data, method = "polychoric"), regex = "It seems like") }) test_that("correlation doesn't fail when BFs are NA", { From 8b638d81bea05a54ea740267748469b3f911bdd3 Mon Sep 17 00:00:00 2001 From: Daniel Date: Wed, 24 Jul 2024 21:11:26 +0200 Subject: [PATCH 4/4] news --- NEWS.md | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/NEWS.md b/NEWS.md index 272e6406..7a5aa60f 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +# correlation 0.8.6 + +- Fix CRAN check issues. + # correlation 0.8.5 - New `cormatrix_to_excel()` function for exporting correlation matrices to Excel with color formatting. @@ -206,4 +210,3 @@ - Fixed issue in `correlation()` for correlation coefficients with less than four complete pairs of observations (in such cases, `cor_test()` now returns `NA` for the confidence intervals). -