-
Notifications
You must be signed in to change notification settings - Fork 0
/
CorrelationCoeff.java
72 lines (62 loc) · 2.01 KB
/
CorrelationCoeff.java
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import java.io.*;
import java.util.*;
class CorrelationCoeff
{
public static double correlationCoeff(ArrayList<ArrayList<String>>l,int row1,int row2)
{
int y1count=0,y2count=0,n1count=0,n2count=0,totYcount=0,totNcount=0;
for(int i=0;i<l.get(row1).size();i++)
{
if(l.get(row1).get(i).equals("Y"))
y1count++;
else
n1count++;
}
for(int i=0;i<l.get(row2).size();i++)
{
if(l.get(row2).get(i).equals("Y"))
y2count++;
else
n2count++;
}
for(int i=0;i<l.get(row1).size();i++)
{
if(l.get(row1).get(i).equals("Y")&&l.get(row2).get(i).equals("Y"))
totYcount++;
else
totNcount++;
}
double ans=1.0*totYcount/(y1count*y2count);
ans=Math.round(ans*100.0)/100.0;
return ans;
}
public static void main(String[] args) throws Exception
{
BufferedReader br=new BufferedReader(new FileReader("C://Users/admin/Desktop/corr.csv"));
String []str=br.readLine().trim().split(",");
int n=str.length;
ArrayList<String>location=new ArrayList<>();
ArrayList<ArrayList<String>> l=new ArrayList<>();
while(true)
{
String [] s=new String[n];
try{
s=br.readLine().trim().split(",");
}
catch(NullPointerException e)
{
break;
}
ArrayList<String> temp=new ArrayList<>();
location.add(s[0]);
for(int i=1;i<n;i++)
{
temp.add(s[i]);
}
l.add(temp);
}
System.out.println(l);
double ans=correlationCoeff(l,2,3);
System.out.println("Correlation Coeff is"+ans);
}
}