[帰無仮説]:4群のデータの分散は等質である
p-valueの値>0.05であれば、帰無仮説は棄却されずに採択されるため、4カテゴリの母分散は等しくないとは言えない(等分散性あり)と言えます。
[手順]
1.operationsテーブルから274件を取り込む
2.スタック形式配列 score = [awareness decision communication leadership]の順で配列を作成
3.Rにscoreを渡し、bartlett検定。結果を得る。
$ vi JRITest11.java
import org.rosuda.JRI.REXP;
import org.rosuda.JRI.Rengine;
import java.sql.*;
import java.util.Arrays;
public class JRITest11 {
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 = 274;
double awareness [] = new double[N];
double decision [] = new double[N];
double communication [] = new double[N];
double leadership [] = new double[N];
int index = 0;
try {
while(rs.next()){
awareness[index] = rs.getInt("awareness");
decision[index] = rs.getInt("decision");
communication[index] = rs.getInt("communication");
leadership[index] = rs.getInt("leadership");
index ++;
}
} catch (SQLException e) {
e.printStackTrace();
}
double score[] = new double[awareness.length*4];
int index2 = 0;
for(int i = 0 ; i< awareness.length; i++) score[index2++] = awareness[i];
for(int i = 0 ; i< decision.length; i++) score[index2++] = decision[i];
for(int i = 0 ; i< communication.length; i++) score[index2++] = communication[i];
for(int i = 0 ; i< leadership.length; i++) score[index2++] = leadership[i];
StringBuffer buf = new StringBuffer();
buf.append("score<-c(");
for(int i = 0; i < score.length; i++){
if(i == score.length -1)
buf.append(score[i]+")");
else
buf.append(score[i]+",");
}
String c_value = buf.toString();
re.eval(c_value);
REXP x = re.eval("summary(score)");
System.out.println(x);
double [] ary = x.asDoubleArray();
for (int i = 0; i < ary.length; i++) {
System.out.println(ary[i]);
}
re.eval("group=factor(rep(c('awareness', 'decision', 'communication', 'leadership'), c(274, 274, 274, 274)))");
REXP x1 = re.eval("bartlett.test(score ~ group)");
System.out.println(x1);
re.end();
}
}
$ javac JRITest11.java[notss_analysis@ip-10-0-0-217 rjava]$ java -Djava.library.path=/usr/lib64/R/library/rJava/jri/ JRITest11
[REAL* (0.0, 9.0, 10.0, 9.765, 12.0, 12.0)]
0.0
9.0
10.0
9.765
12.0
12.0
[VECTOR ([REAL* (7.479622753319318)], [REAL* (3.0)], [REAL* (0.05808434871027897)], [STRING "score by group"], [STRING "Bartlett test of homogeneity of variances"])]
この結果からp-value=0.05808434871027897となり、p-value>0.05なので帰無仮説が採択で、等分散性が言えます。
0 件のコメント:
コメントを投稿