x<-rnorm(100,100,8)
y<-rnorm(100,82,2)
y1<-y+5
y2<-y+log(y)
y3<-y+sign(y-mean(y))*log(y)+2.5
plot(x,y,ylim=c(75,100),xlim=c(80,120),col="blue")
lines(x,y1,col="red",type="p")
lines(x,y2,col="green",type="p")
lines(x,y3,col="black",type = "p")
cor(x,y)
## [1] -0.07020073
cor(x,y2)
## [1] -0.07017265
cor(y,y1)
## [1] 1
cor(y,y2)
## [1] 1
cor(y,y3)
## [1] 0.8759635
legend(x = "topleft", legend = c("y vs x","(y+5) vs x","(y+log(y)) vs x","(y+sign(y-avg(y))*log(y)) vs x"),
col = c("blue","red","green","black"), pch=c(1,1,1,1), cex = 0.85)
text(x = 100,y=100.5,pos=4,labels = "cor(x,yi)", cex = 0.85)
text(x = 100,y=99,pos = 4,labels = paste(round(cor(x,y),3)), cex = 0.85)
text(x = 100,y=97.5,pos = 4,labels = paste(round(cor(x,y1),3)), cex = 0.85)
text(x = 100,y=96,pos = 4,labels = paste(round(cor(x,y2),3)), cex = 0.85)
text(x = 100,y=94.5,pos = 4,labels = paste(round(cor(x,y3),3)), cex = 0.85)
text(x = 115,y=100.5,pos=4,labels = "cor(y0,yi)", cex = 0.85)
text(x = 115,y=99,pos = 4,labels = "---", cex = 0.85)
text(x = 115,y=97.5,pos = 4,labels = paste(round(cor(y,y1),3)), cex = 0.85)
text(x = 115,y=96,pos = 4,labels = paste(round(cor(y,y2),3)), cex = 0.85)
text(x = 115,y=94.5,pos = 4,labels = paste(round(cor(y,y3),3)), cex = 0.85)

qqplot(x=y,y=y, ylim=c(70,100),xlim=c(75,90), ylab = "yi", xlab = "y0", col="blue")
lines(x=y,y=y1,col="red",type = "p")
lines(x=y,y=y2,col="green",type = "p")
lines(x=y,y=y3,col="black",type = "p")
y4<-y*log(y)-280
lines(x=y,y=y4,col="magenta",type = "p")
cor(y,y4)
## [1] 0.9999938
legend(x = "topleft", legend = c("y vs y","(y+5) vs y","(y+log(y)) vs y","(y+sign(y-avg(y))*log(y)) vs y",
"y*log(y)-280 vs y"),
col = c("blue","red","green","black","magenta"), pch=c(1,1,1,1,1), cex = 0.85)
text(x = 88,y=100.5,pos=4,labels = "cor(y0,yi)", cex = 0.85)
text(x = 88,y=99,pos = 4,labels = "---", cex = 0.85)
text(x = 88,y=97.5,pos = 4,labels = paste(round(cor(y,y1),3)), cex = 0.85)
text(x = 88,y=96,pos = 4,labels = paste(round(cor(y,y2),3)), cex = 0.85)
text(x = 88,y=94.5,pos = 4,labels = paste(round(cor(y,y3),3)), cex = 0.85)
text(x = 88,y=93,pos = 4,labels = paste(round(cor(y,y4),3)), cex = 0.85)
