-
Notifications
You must be signed in to change notification settings - Fork 0
/
CorrelationTest.R
55 lines (39 loc) · 1.32 KB
/
CorrelationTest.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env Rscript
library(tseries)
# TEST DE CORRELACIÓN
# Test que obtiene el coeficiente de correlación utilizando varios métodos
# USAGE
# ./CorrelationTest.R datafile_path init_col end_col target_col
# eg: ./CorrelationTest.R data.csv 2 -1 3
# OUTPUT
# - Screen log, showing the flow and info about the analysis procedure
args<-commandArgs(trailingOnly=TRUE)
if(length(args)==0){
stop("Invalid arguments: datafile_path init_col (2) end_col (-1) target_col (1).")
}
dataset<-read.csv( args[1] )
init_col<-as.numeric(args[2])
end_col<-as.numeric(args[3])
target_col<-as.numeric(args[4])
target_name<-names(dataset)[target_col]
if( end_col == -1 )
{
end_col<-ncol(dataset)
}
if(init_col>end_col)
{
stop("Wrong INIT (",init_col,") and/or END (",end_col,") columns value.")
}
message("# CORRELATION COEFFICIENTS #####################")
for( i in init_col:end_col )
{
if( i == target_col )
{
next
}
col_name<-names(dataset)[i]
cor_coef_pearson<-cor(dataset[,target_col], dataset[,i], method="pearson")
cor_coef_spearman<-cor(dataset[,target_col], dataset[,i], method="spearman")
cor_coef_kendall<-cor(dataset[,target_col], dataset[,i], method="kendall")
message("... ",target_name," - ",col_name,": ",cor_coef_pearson," (Pearson), ",cor_coef_spearman," (Spearman), ",cor_coef_kendall," (Kendall)")
}