Created
January 12, 2024 12:39
-
-
Save CnrLwlss/5f1c30ecfee7f0872a7630e80038a6ea to your computer and use it in GitHub Desktop.
Sometimes zero correlation does not mean "randomly distributed", rather just "no effect".
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
seed(99) | |
N = 100 | |
x = runif(N) | |
noise = rnorm(N,mean=0,sd=0.1) | |
y_corr = 1*x + noise | |
y_nocorr = noise | |
rsq_corr = cor(x,y_corr) | |
rsq_nocorr = cor(x,y_nocorr) | |
plot(x,y_corr,xlim=c(0,1),ylim=c(-0.3,1.0),pch=16,xlab="x",ylab="y",cex.lab=1.55) | |
points(x,y_nocorr,pch=16,col="red") | |
legend("topleft",c(paste("Corr:",format(round(rsq_corr,3),nsmall=3)),paste("Corr:",format(round(rsq_nocorr,3),nsmall=3))),pch=16,col=c("black","red")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment