Kalkulator tes bartlett
Uji Bartlett digunakan untuk menguji apakah sampel berasal dari populasi dengan varian yang sama. Beberapa uji statistik, seperti ANOVA satu arah , mengasumsikan bahwa varians antar sampel adalah sama. Uji Bartlett dapat digunakan untuk memverifikasi hipotesis ini.
Untuk melakukan tes Bartlett hingga lima sampel, cukup masukkan nilai data di bawah ini dan klik tombol “Hitung”. Statistik uji dan nilai p yang sesuai akan disajikan di bawah ini. Nilai p yang kurang dari 0,05 merupakan bukti kuat bahwa varians antar sampel tidak sama.
//create function that performs t test calculations function calc() {
//define addition function function add(a, b) { return a + b; }
//get raw data //group a // var values_a_input = document.getElementsByClassName('a'); //var values_a_array = []; //for (var i = 0; i < values_a_input.length; i++) { // values_a_array[i] = values_a_input[i].innerText; // } //values_a_array = values_a_array.filter(n => n); //var group_a = values_a_array.map(Number); if(document.getElementById("a").value == '') { var group_a = ''; } else { var group_a = document.getElementById('a').value.match(/\d+/g).map(Number); }
if(document.getElementById("b").value == '') { var group_b = ''; } else { var group_b = document.getElementById('b').value.match(/\d+/g).map(Number); }
if(document.getElementById("c").value == '') { var group_c = ''; } else { var group_c = document.getElementById('c').value.match(/\d+/g).map(Number); }
if(document.getElementById("d").value == '') { var group_d = ''; } else { var group_d = document.getElementById('d').value.match(/\d+/g).map(Number); }
if(document.getElementById("e").value == '') { var group_e = ''; } else { var group_e = document.getElementById('e').value.match(/\d+/g).map(Number); }
var all_groups = (group_a.concat(group_b, group_c, group_d, group_e)).filter(n => n);
//get summary stats of each group if (group_a.length > 0) { var mean_group_a = math.mean(group_a); }; if (group_b.length > 0) { var mean_group_b = math.mean(group_b); }; if (group_c.length > 0) { var mean_group_c = math.mean(group_c); }; if (group_d.length > 0) { var mean_group_d = math.mean(group_d); }; if (group_e.length > 0) { var mean_group_e = math.mean(group_e); };
if (group_a.length > 0) { var var_group_a = math.var(group_a); }; if (group_b.length > 0) { var var_group_b = math.var(group_b); }; if (group_c.length > 0) { var var_group_c = math.var(group_c); }; if (group_d.length > 0) { var var_group_d = math.var(group_d); }; if (group_e.length > 0) { var var_group_e = math.var(group_e); };
if (group_a.length > 0) { var lnvar_group_a = Math.log(var_group_a); } else { var lnvar_group_a = 0;}; if (group_b.length > 0) { var lnvar_group_b = Math.log(var_group_b); } else { var lnvar_group_b = 0;}; if (group_c.length > 0) { var lnvar_group_c = Math.log(var_group_c); } else { var lnvar_group_c = 0;}; if (group_d.length > 0) { var lnvar_group_d = Math.log(var_group_d); } else { var lnvar_group_d = 0;}; if (group_e.length > 0) { var lnvar_group_e = Math.log(var_group_e); } else { var lnvar_group_e = 0;};
if (group_a.length > 0) { var df_group_a = group_a.length-1; } else { var df_group_a = 0;}; if (group_b.length > 0) { var df_group_b = group_b.length-1; } else { var df_group_b = 0;}; if (group_c.length > 0) { var df_group_c = group_c.length-1; } else { var df_group_c = 0;}; if (group_d.length > 0) { var df_group_d = group_d.length-1; } else { var df_group_d = 0;}; if (group_e.length > 0) { var df_group_e = group_e.length-1; } else { var df_group_e = 0;};
var total_df = [df_group_a, df_group_b, df_group_c, df_group_d, df_group_e].reduce(add, 0); var total_df1 = 1 / total_df;
var lnvar_array = [lnvar_group_a, lnvar_group_b, lnvar_group_c, lnvar_group_d, lnvar_group_e]; var df_array = [df_group_a, df_group_b, df_group_c, df_group_d, df_group_e]; var lnvar_df_array = [] for (var i = 0; i < lnvar_array.length; i++) { lnvar_df_array.push(lnvar_array[i] * df_array[i]); } var sum_lnvar_df_array = lnvar_df_array.reduce(add, 0); if (group_a.length > 0) { var flag_group_a = 1; } else { var flag_group_a = 0;}; if (group_b.length > 0) { var flag_group_b = 1; } else { var flag_group_b = 0;}; if (group_c.length > 0) { var flag_group_c = 1; } else { var flag_group_c = 0;}; if (group_d.length > 0) { var flag_group_d = 1; } else { var flag_group_d = 0;}; if (group_e.length > 0) { var flag_group_e = 1; } else { var flag_group_e = 0;};
if (group_a.length > 0) { var df1_group_a = 1/df_group_a; } else { var df1_group_a = 0;}; if (group_b.length > 0) { var df1_group_b = 1/df_group_b; } else { var df1_group_b = 0;}; if (group_c.length > 0) { var df1_group_c = 1/df_group_c; } else { var df1_group_c = 0;}; if (group_d.length > 0) { var df1_group_d = 1/df_group_d; } else { var df1_group_d = 0;}; if (group_e.length > 0) { var df1_group_e = 1/df_group_e; } else { var df1_group_e = 0;};
var df1_array = [df1_group_a, df1_group_b, df1_group_c, df1_group_d, df1_group_e]; var df1_array_sum = df1_array.reduce(add, 0);
var treatments = [flag_group_a, flag_group_b, flag_group_c, flag_group_d, flag_group_e].reduce(add, 0) - 1;
if (treatments == 1) { var total_var = jStat.pooledvariance([group_a, group_b]); var total_lnvar = Math.log(total_var); } else if (treatments == 2) { var total_var = jStat.pooledvariance([group_a, group_b, group_c]); var total_lnvar = Math.log(total_var); } else if (treatments == 3) { var total_var = jStat.pooledvariance([group_a, group_b, group_c, group_d]); var total_lnvar = Math.log(total_var); } else if (treatments == 4) { var total_var = jStat.pooledvariance([group_a, group_b, group_c, group_d, group_e]); var total_lnvar = Math.log(total_var); } //calculate test statistic var b_numerator = total_df * total_lnvar - sum_lnvar_df_array; var b_denominator = 1 - (-1 / (3*treatments)) * (df1_array_sum - total_df1); var b = b_numerator / b_denominator; var p = 1 - jStat.chisquare.cdf(b, treatments); console.log(df1_array, lnvar_array, total_df, total_var, total_lnvar, total_df1); //output results document.getElementById('B').innerHTML = "Test Statistic B: " + b.toFixed(5); document.getElementById('p').innerHTML = "p-value: " + p.toFixed(5); }