$ vi JRITest15.java
$ javac JRITest15.java
$ java -Djava.library.path=/usr/lib64/R/library/rJava/jri/ JRITest15
[VECTOR ([REAL* (-3.842989125314249)], [REAL* (42.0)], [REAL* (4.0495738809968483E-4)], [REAL* (-6.5858030454480865, -2.0505605909155538)], [REAL* (40.22727272727273, 44.54545454545455)], [REAL* (0.0)], [STRING "two.sided"], [STRING " Two Sample t-test"], [STRING "c_group1 and c_group2"])]
この場合, p-value = 4.0495738809968483E-4 となり帰無仮説が棄却。2つの期間グループに差があることがわかる。
今回利用するSQL文
SELECT * FROM operations WHERE category = 0 and operator =6
public class JRITest15 {
public static void main(String[] args)
{
MySQL mysql = new MySQL();
Rengine re = new Rengine( new String[]{"--no-save"}, false, null );
ResultSet rs = mysql.selectOperations();
int N = 44;
double group1 [] = new double[N/2];
double group2 [] = new double[N/2];//**注意i:奇数の時は+1**
int index = 0;
try {
while(rs.next()){
if(index < (int)(N/2)){
group1[index] = rs.getDouble("value");
}else if(index >= (int)(N/2)){
group2[index-(int)(N/2)] = rs.getDouble("value");
}
index ++;
}
} catch (SQLException e) {
e.printStackTrace();
}
System.out.println(Arrays.toString(group1));
System.out.println(Arrays.toString(group2));
StringBuffer buf1 = new StringBuffer();
buf1.append("c_group1<-c(");
for(int i = 0; i < group1.length; i++){
if(i == group1.length-1)
buf1.append(group1[i]+")");
else
buf1.append(group1[i]+",");
}
String c_group1 = buf1.toString();
re.eval(c_group1);
REXP x1 = re.eval("summary(c_group1)");
System.out.println(x1);
double [] ary1 = x1.asDoubleArray();
for (int i = 0; i < ary1.length; i++) {
System.out.println(ary1[i]);
}
StringBuffer buf2 = new StringBuffer();
buf2.append("c_group2<-c(");
for(int i = 0; i < group2.length; i++){
if(i == group2.length-1)
buf2.append(group2[i]+")");
else
buf2.append(group2[i]+",");
}
String c_group2 = buf2.toString();
re.eval(c_group2);
REXP x2 = re.eval("summary(c_group2)");
System.out.println(x2);
double [] ary2 = x2.asDoubleArray();
for (int i = 0; i < ary2.length; i++) {
System.out.println(ary2[i]);
}
REXP x3 = re.eval("t.test(c_group1, c_group2, var.equal=T)");
System.out.println(x3);
re.end();
}
}
p
0 件のコメント:
コメントを投稿