overall (i = x for : ) // Compute probability
for (int j = 0; j<NUM_RESPONSES; j++) {
double exp = Math.exp(1.7 * par[j, 0] * (tht[i]  par[j, 1])) ;
prob[i, j] = par[j, 2] + (1.0  par[j, 2]) * exp / (1.0 + exp) ;
}
overall (i = x for : ) // Calculate the difference scores
for (int j = 0; j<NUM_RESPONSES; j++)
diff[i, j] = raw[i, j]  prob[i, j] ;
Adlib.sumDim(sum_diff, diff, 0) ; // sum(di) / n
for (int i = 0; i<NUM_RESPONSES; i++)
sum_diff[i] /= NUM_STUDENTS ;
overall (i = x for : ) // sum(power(di, 2)) / n
for (int j = 0; j<NUM_RESPONSES; j++)
power_diff_2[i, j] = diff[i, j] * diff[i, j] / NUM_STUDENTS ;
Adlib.sumDim(sum_power_diff_2, power_diff_2, 0) ;
overall (k = x for : ) // calculating didj
for (int i = 0; i<NUM_RESPONSES; i++)
for (int j = 0; j<NUM_RESPONSES; j++)
if (i != j)
didj[k, i*NUM_RESPONSES + j] = diff[k, i] * diff[k, j] / NUM_STUDENTS ;
Adlib.sumDim(sum_didj, didj, 0) ; // sum(di * dj) / n
for (int i=0; i<NUM_RESPONSES; i++) // covariance
for (int j=0; j<NUM_RESPONSES; j++)
if (i != j)
cov[i][j] = sum_didj[i*NUM_RESPONSES + j]  sum_diff[i] * sum_diff[j] ;
for (int i=0; i<NUM_RESPONSES; i++) // variance
var[i] = sum_power_diff_2[i]  sum_diff[i] * sum_diff[i] ;
for (int i = 0; i<NUM_RESPONSES; i++) // Calculate Q3
for (int j = 0; j<NUM_RESPONSES; j++)
if (i != j) {
q3[i][j] = cov[i][j] / Math.sqrt(var[i] * var[j]) ;
avg += q3[i][j] ;
}
