Created
February 19, 2013 09:12
-
-
Save benmarwick/4984250 to your computer and use it in GitHub Desktop.
Three ways to calculate correlation in R. Basics of the common correlation statistic (pearson/kendall/spearman), the newer distance correlation statistic (Brownian distance covariance) and the ever newer maximal information coefficient (a maximal information-based nonparametric exploration (MINE) statistic) in R
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
# three correlation methods | |
duration = faithful$eruptions # the eruption durations | |
waiting = faithful$waiting # the waiting period | |
plot(duration, waiting) | |
cor(duration, waiting) | |
cor.test(duration, waiting) | |
# distance correlation statistic | |
library("energy") | |
dcor(duration, waiting) | |
dcov.test(duration, waiting) | |
# maximal information coefficient | |
# http://www.exploredata.net/Usage-instructions | |
# download MINE.jar and MINE.r | |
# see here if problems with rJava | |
# http://stackoverflow.com/q/2399027/1036500 | |
setwd("C:/Users/marwick/Downloads") | |
source("MINE.R") | |
rMINE(t(cbind(duration, waiting)), "matrix", 'all.pairs') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment