F検定:対象37件
帰無仮説:2群間の分散に差がない(等分散である)
今回の2つの群は
[39.0, 40.0, 39.0, 38.0, 38.0, 43.0, 48.0, 43.0, 41.0, 44.0, 35.0, 36.0, 37.0, 30.0, 46.0, 40.0, 44.0, 40.0]
[45.0, 36.0, 45.0, 38.0, 39.0, 45.0, 40.0, 44.0, 48.0, 45.0, 45.0, 46.0, 40.0, 44.0, 37.0, 45.0, 48.0, 44.0, 43.0]
となり、
一つ目のsummaryは、意味は(Min 最小値, 1st Qu 第一四分位数, Median 中央値, Mean 平均値, 3rd Qu 第三四分位数, Max 最大値)
(30.0, 38.0, 40.0, 40.06, 43.0, 48.0)
2つ目は
(36.0, 40.0, 44.0, 43.0, 45.0, 48.0)
最小値も平均も高いので、後半の方が良さそうだけど、t検定をする予定。そのために等分散を検定しておく。
$ vi JRITest14.java
$ javac JRITest14.java
$ java -Djava.library.path=/usr/lib64/R/library/rJava/jri/ JRITest14
[VECTOR ([REAL* (1.4314578005115088)], [INT* (17, 18)], [REAL* (0.45734976337721367)], [REAL* (0.547029015180649, 3.7965176255066506)], [REAL* (1.4314578005115088)], [REAL* (1.0)], [STRING "two.sided"], [STRING "F test to compare two variances"], [STRING "c_group1 and c_group2"])]
p-value = 0.45734976337721367
なので帰無仮説が採択。よって等分散が言える。
[JRITest14.java]
今回のSQL文
String sql = "SELECT * FROM operations WHERE category = 0 AND evaluator <=15 and operator =6";
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
import java.sql.*;
import java.util.Arrays;
public class JRITest14 {
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 = 37;
double group1 [] = new double[N/2];
double group2 [] = new double[N/2+1];//**注意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("var.test(c_group1, c_group2)");
System.out.println(x3);
re.end();
}
}
参考
http://kusuri-jouhou.com/statistics/fkentei.html
http://cse.naro.affrc.go.jp/takezawa/r-tips/r/65.html
http://monge.tec.fukuoka-u.ac.jp/r_analysis/test_t03.html
0 件のコメント:
コメントを投稿