Last active
March 17, 2022 20:50
-
-
Save hakyim/a925fea01b365a8c605e to your computer and use it in GitHub Desktop.
Plots observed R^2 vs expected R2 under null of 0 correlation
This file contains 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
qqR2 <- function(corvec,nn,pad_neg_with_0 = FALSE,...) | |
{ | |
## nn is the sample size, number of individuals used to compute correlation. | |
## needs correlation vector as input. | |
## nullcorvec generates a random sample from correlation distributions, under the null hypothesis of 0 correlation using Fisher's approximation. | |
if(pad_neg_with_0) corvec[corvec < 0 | is.na(corvec) ]=0 | |
mm <- length(corvec) | |
nullcorvec = tanh(rnorm(mm)/sqrt(nn-3)) ## null correlation vector | |
qqplot(nullcorvec^2,corvec^2,...); abline(0,1); grid() | |
} | |
qqR <- function(corvec,nn,...) | |
{ | |
## nn is the sample size, number of individuals used to compute correlation. | |
## needs correlation vector as input. | |
## nullcorvec generates a random sample from correlation distributions, under the null hypothesis of 0 correlation using Fisher's approximation. | |
mm <- length(corvec) | |
nullcorvec = tanh(rnorm(mm)/sqrt(nn-3)) ## null correlation vector | |
qqplot(nullcorvec,corvec,...); abline(0,1); grid() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment