Total members 11653 |It is currently Wed Jul 26, 2017 7:39 am Login / Join Codemiles

Java

C/C++

PHP

C#

HTML

CSS

ASP

Javascript

JQuery

AJAX

XSD

Python

Matlab

R Scripts

Weka





This example shows how to use Spearman correlation in R with pie charts.
Code:



setwd
("D:/FirstPaper/Eclipse/")


require(
foreign) 
require(ggplot2)
require(
MASS)
require(
boot)

#Read the data first. 
data <- read.csv("Femo_duplicates_X.csv",head=TRUE );
 

require(randomForest)

require(
ROSE)
if(!require(
caret)){
  library(caret)  
}
if(!require(
pROC)){
  library(pROC)
}
library (ROCR);

## get correlation to subset of the data.
cor(data[3:length(data)], method="spearman")

## get correlation to all data. It creates matrix of correlations.
cor(data, method="spearman")

## Draw pie charts 
require(corrgram)
corrgram(data[3:length(data)], method="spearman", upper.panel=panel.pie)


Code snippet first read the data from a .cvs file and load it in a data frame structure. Then, I call the correlation calculation function. In the example above, due to the custom structure of my data I start at column 3. Please note that the cor function does a correlation calculation as a matrix. This means every column will have its own correlation with all the other columns. At the end, I show how to calculate and display the correlation results in a user-friendly look using pie charts.



_________________
Sami
PHD student - SAIL - School Of Computing
Queens' University
Canada


Author:
Site Admin
User avatar Posts: 33
Have thanks: 1 time

updated.


Author:
Mastermind
User avatar Posts: 2707
Have thanks: 74 time
Post new topic Reply to topic  [ 2 posts ] 




Topic Tags

R Analysis







Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
All copyrights reserved to codemiles.com 2007-2011
mileX v1.0 designed by codemiles team