idekerlab / jActiveModules

4 stars 2 forks source link

Variance calculation in ParamStatistics.java #2

Open ozanozisik opened 6 years ago

ozanozisik commented 6 years ago

In ParamStatistics.java variance is calculated as follows var = (overall_tallyx_2[i]-(trialsmeans[i]means[i]))/(trials-1); Isn't this (SUM(x^2) - SUM(xmean^2)) / (N-1) , which is wrong as the formula is SUM((x-xmean)^2) / (N-1) ? The calculation can be performed as follows (when N is used instead of N-1): var = overall_tallyx_2[i] / trials - means[i]*means[i];

as var = SUM((x-xmean)^2) / N = SUM(x^2 - 2xmeanx + xmean^2)/N = SUM(x^2)/N - (2xmeanSUM(x))/N + (Nxmean^2)/N = SUM(x^2 )/N - 2xmean^2 + xmean^2 = SUM(x^2 )/N - xmean^2