[Feature] cor_diff() : test for differences between correlations#338
Open
DominiqueMakowski wants to merge 6 commits intomainfrom
Open
[Feature] cor_diff() : test for differences between correlations#338DominiqueMakowski wants to merge 6 commits intomainfrom
DominiqueMakowski wants to merge 6 commits intomainfrom
Conversation
Member
Author
|
@bwiernik @mattansb do you know of any way to compute a Bayes factor for that? |
strengejacke
requested changes
Jan 29, 2025
strengejacke
requested changes
Jan 29, 2025
|
|
||
| # If pairs are passed | ||
| if(length(x) == 2 & length(y) == 2) { | ||
| if(length(x) == 2 && length(y) == 2) { |
Member
|
I'm unfamiliar with a Bayes factor for such a comparison. |
Member
Author
|
|
Contributor
|
Didn't look into code yet. The straightforward approach to these tests is to do a Fisher z transform and then do a z test for the difference (potentially accounting for covariance). So BF methods analogous to a z test would work |
Member
Author
|
Test: library(ggplot2)
library(correlation)
rez <- data.frame()
for(r in seq(0, 0.6, length.out=200)) {
for(n in seq(20, 100, by=30)) {
data <- bayestestR::simulate_correlation(
n = n,
r = matrix(c(
1.0, r, 0.0,
r, 1.0, 0.0,
0.0, 0.0, 1.0), nrow = 3))
rez <- cor_diff(data, x="V1", y="V2", x2="V1", y2="V3", method = "parametric") |>
datawizard::data_rename("t", "z") |>
rbind(cor_diff(data, x="V1", y="V2", x2="V1", y2="V3", method = "bootstrapping", iterations=2000)) |>
datawizard::data_modify(n = n, r = r) |>
rbind(rez)
}
}
rez |>
datawizard::reshape_longer(select=-c("r", "n", "Method")) |>
datawizard::data_modify(type = ifelse(name %in% c("p"), "p-value", "z-value")) |>
ggplot(aes(x=r, y=value)) +
geom_smooth(aes(group=interaction(Method, n), color=n), method="loess", se=FALSE, formula = 'y ~ x') +
geom_point(aes(color=n), alpha=0.1) +
facet_grid(type~Method, scales="free_y", switch="y") +
theme_minimal() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Simple function with parametric vs. bootstrapped approaches. I ran some simulations and it seems to nicely work.
Created on 2025-01-29 with reprex v2.1.1