First Approach
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
data(iris) | |
cor(iris[,1:4]) |
Sepal.Length 1.0000000 -0.1175698 0.8717538 0.8179411
Sepal.Width -0.1175698 1.0000000 -0.4284401 -0.3661259
Petal.Length 0.8717538 -0.4284401 1.0000000 0.9628654
Petal.Width 0.8179411 -0.3661259 0.9628654 1.0000000
Second Approach
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
pairs(iris[,1:4]) |
Third Approach
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
panel.cor <- function(x, y, digits = 2, cex.cor, ...) | |
{ | |
usr <- par("usr"); on.exit(par(usr)) | |
par(usr = c(0, 1, 0, 1)) | |
# correlation coefficient | |
r <- cor(x, y) | |
txt <- format(c(r, 0.123456789), digits = digits)[1] | |
txt <- paste("r= ", txt, sep = "") | |
text(0.5, 0.6, txt) | |
# p-value calculation | |
p <- cor.test(x, y)$p.value | |
txt2 <- format(c(p, 0.123456789), digits = digits)[1] | |
txt2 <- paste("p= ", txt2, sep = "") | |
if(p<0.01) txt2 <- paste("p= ", "<0.01", sep = "") | |
text(0.5, 0.4, txt2) | |
} | |
pairs(iris, upper.panel = panel.cor) |
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
library(GGally) | |
ggpairs(iris[,1:4]) |
This comment has been removed by the author.
ReplyDeleteAnother way to look at correlation is with correlograms. An overview is here: http://www.statmethods.net/advgraphs/correlograms.html
ReplyDeleteTry
corrgram(iris, upper.panel=panel.pts, lower.panel=panel.ellipse, diag.panel=panel.density)
This comment has been removed by the author.
ReplyDeleteHello, you show us three great approaches for correlations, thanks! I wonder about two optional things.
ReplyDelete1) In third approach, is there a possible set up which marks all significant correlations with * / ** / ***, depending on the given significance niveau?
2) (General question) Does it make sense to add a regression line into each correlation diagram, and if yes (specific question), how can this be done best way (e.g. in solution 3)?
Is there is any ways to convert scatterplot into plotly interactive graph.
ReplyDeletei am taliking about pair() function approach for scatter plot
Amazing article. Your blog helped me to improve myself in many ways thanks for sharing this kind of wonderful informative blogs in live. I have bookmarked more article from this website. Such a nice blog you are providing ! Kindly Visit Us R Programming institutes in Chennai | R Programming Training in Chennai
ReplyDelete
ReplyDeleteThis is most informative and also this post most user friendly and super navigation to all posts... Thank you so much for giving this information to me.. Trending Software Technologies in 2018 | Hadoop Training in Chennai