Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Type: Package
Package: correlation
Title: Methods for Correlation Analysis
Version: 0.8.8
Version: 0.8.8.1
Authors@R:
c(person(given = "Dominique",
family = "Makowski",
Expand Down Expand Up @@ -88,7 +88,7 @@ VignetteBuilder:
knitr
Encoding: UTF-8
Language: en-US
RoxygenNote: 7.3.2
RoxygenNote: 7.3.3
Roxygen: list(markdown = TRUE)
Config/testthat/edition: 3
Config/Needs/website:
Expand Down
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
# correlation 0.8.9

## Bug Fixes

- `cormatrix_to_excel()` now works correctly with openxlsx2 v1.16+. Fixed
conditional formatting rule ordering to accommodate openxlsx2's new waterfall
strategy (#361).

# correlation 0.8.8

- `correlation()` gains a `missing=` argument, similar to `stats::cor(use=)`, for controlling how missing data is handled.
Expand Down
124 changes: 66 additions & 58 deletions R/cormatrix_to_excel.R
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@
#' \dontshow{
#' setwd(.old_wd)
#' }
cormatrix_to_excel <- function(data,
filename,
overwrite = TRUE,
print.mat = TRUE,
...) {
cormatrix_to_excel <- function(
data,
filename,
overwrite = TRUE,
print.mat = TRUE,
...
) {
if (missing(filename)) {
insight::format_error("Argument 'filename' required (as per CRAN policies).")
insight::format_error(
"Argument 'filename' required (as per CRAN policies)."
)
}

insight::check_if_installed("openxlsx2")
Expand Down Expand Up @@ -241,52 +245,61 @@ cormatrix_to_excel <- function(data,
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
# Compute the cell range for styling
dims_fmt <- openxlsx2::wb_dims(cols = all.columns, rows = all.columns)

# gray diagonal (most specific, must be first to win for r = 1)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= .2, r_values!B2 > 0, p_values!B2 < .05)",
style = "one_star_pink"
rule = "r_values!B2 = 1",
style = "gray_style"
)

# three stars (p < .001) - most specific color ranges first
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= .2, p_values!B2 < .05)",
style = "one_star_peach"
rule = "AND(r_values!B2 >= .4, p_values!B2 < .001)",
style = "three_stars_red"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= .4, p_values!B2 < .05)",
style = "one_star_red"
rule = "AND(r_values!B2 >= .2, p_values!B2 < .001)",
style = "three_stars_peach"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= -.2, r_values!B2 < 0, p_values!B2 < .05)",
style = "one_star_lightblue"
rule = "AND(r_values!B2 <= .2, r_values!B2 > 0, p_values!B2 < .001)",
style = "three_stars_pink"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= -.2, p_values!B2 < .05)",
style = "one_star_midblue"
rule = "AND(r_values!B2 <= -.4, p_values!B2 < .001)",
style = "three_stars_darkblue"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= -.4, p_values!B2 < .05)",
style = "one_star_darkblue"
rule = "AND(r_values!B2 <= -.2, p_values!B2 < .001)",
style = "three_stars_midblue"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= -.2, r_values!B2 < 0, p_values!B2 < .001)",
style = "three_stars_lightblue"
)

# two stars
# two stars (p < .01) - most specific color ranges first
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= .2, r_values!B2 > 0, p_values!B2 < .01)",
style = "two_stars_pink"
rule = "AND(r_values!B2 >= .4, p_values!B2 < .01)",
style = "two_stars_red"
)
wb$add_conditional_formatting(
"r_values",
Expand All @@ -297,14 +310,14 @@ cormatrix_to_excel <- function(data,
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= .4, p_values!B2 < .01)",
style = "two_stars_red"
rule = "AND(r_values!B2 <= .2, r_values!B2 > 0, p_values!B2 < .01)",
style = "two_stars_pink"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= -.02, r_values!B2 < 0, p_values!B2 < .01)",
style = "two_stars_lightblue"
rule = "AND(r_values!B2 <= -.4, p_values!B2 < .01)",
style = "two_stars_darkblue"
)
wb$add_conditional_formatting(
"r_values",
Expand All @@ -315,74 +328,68 @@ cormatrix_to_excel <- function(data,
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= -.4, p_values!B2 < .01)",
style = "two_stars_darkblue"
rule = "AND(r_values!B2 >= -.2, r_values!B2 < 0, p_values!B2 < .01)",
style = "two_stars_lightblue"
)

# three stars
# one star (p < .05) - most specific color ranges first
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= .2, r_values!B2 > 0, p_values!B2 < .001)",
style = "three_stars_pink"
rule = "AND(r_values!B2 >= .4, p_values!B2 < .05)",
style = "one_star_red"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= .2, p_values!B2 < .001)",
style = "three_stars_peach"
rule = "AND(r_values!B2 >= .2, p_values!B2 < .05)",
style = "one_star_peach"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= .4, p_values!B2 < .001)",
style = "three_stars_red"
rule = "AND(r_values!B2 <= .2, r_values!B2 > 0, p_values!B2 < .05)",
style = "one_star_pink"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 >= -.2, r_values!B2 < 0, p_values!B2 < .001)",
style = "three_stars_lightblue"
rule = "AND(r_values!B2 <= -.4, p_values!B2 < .05)",
style = "one_star_darkblue"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= -.2, p_values!B2 < .001)",
style = "three_stars_midblue"
rule = "AND(r_values!B2 <= -.2, p_values!B2 < .05)",
style = "one_star_midblue"
)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 <= -.4, p_values!B2 < .001)",
style = "three_stars_darkblue"
rule = "AND(r_values!B2 >= -.2, r_values!B2 < 0, p_values!B2 < .05)",
style = "one_star_lightblue"
)

# Other formatting
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(r_values!B2 = 1)",
style = "gray_style"
)
# no stars (for non-significant correlations)
wb$add_conditional_formatting(
"r_values",
dims = dims_fmt,
rule = "AND(p_values!B2 >= .05)",
style = "no_star"
)

# p-values
# p-values (most specific first)
wb$add_conditional_formatting(
"p_values",
dims = dims_fmt,
rule = "< 10",
style = "p_style"
rule = "== 0",
style = "gray_style"
)
wb$add_conditional_formatting(
"p_values",
dims = dims_fmt,
rule = "< .05",
style = "p_style1"
rule = "< .001",
style = "p_style3"
)
wb$add_conditional_formatting(
"p_values",
Expand All @@ -393,14 +400,14 @@ cormatrix_to_excel <- function(data,
wb$add_conditional_formatting(
"p_values",
dims = dims_fmt,
rule = "< .001",
style = "p_style3"
rule = "< .05",
style = "p_style1"
)
wb$add_conditional_formatting(
"p_values",
dims = dims_fmt,
rule = "== 0",
style = "gray_style"
rule = "< 10",
style = "p_style"
)

## Freeze Panes
Expand All @@ -409,7 +416,8 @@ cormatrix_to_excel <- function(data,

# Save Excel
cat(paste0(
"\n\n [Correlation matrix '", filename,
"\n\n [Correlation matrix '",
filename,
".xlsx' has been saved to working directory (or where specified).]"
))
openxlsx2::wb_save(wb, file = paste0(filename, ".xlsx"), overwrite = TRUE)
Expand Down
2 changes: 1 addition & 1 deletion man/cor_smooth.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/cormatrix_to_excel.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion man/correlation.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions man/visualisation_recipe.easycormatrix.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions tests/testthat/_snaps/renaming.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
Output
# Correlation Matrix (pearson-method)

Parameter1 | Parameter2 | r | 95% CI | t(9) | p
----------------------------------------------------------------
x1 | x2 | 1.00 | [1.00, 1.00] | Inf | < .001***
Parameter1 | Parameter2 | r | 95% CI | t(9) | p
-------------------------------------------------------------
x1 | x2 | 1 | [1.00, 1.00] | Inf | < .001***

p-value adjustment method: Holm (1979)
Observations: 11
Expand All @@ -19,9 +19,9 @@
Output
# Correlation Matrix (pearson-method)

Parameter1 | Parameter2 | r | 95% CI | t(9) | p
----------------------------------------------------------------
var1 | var2 | 1.00 | [1.00, 1.00] | Inf | < .001***
Parameter1 | Parameter2 | r | 95% CI | t(9) | p
-------------------------------------------------------------
var1 | var2 | 1 | [1.00, 1.00] | Inf | < .001***

p-value adjustment method: Holm (1979)
Observations: 11
Expand Down
Loading
Loading