Skip to content

Instantly share code, notes, and snippets.

@benmarwick
Created February 19, 2013 09:12
Show Gist options
  • Save benmarwick/4984250 to your computer and use it in GitHub Desktop.
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
# 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