Generating histogram for highly skewed data

久未见 提交于 2019-12-04 12:36:25

You could use an outlier test to trim out your, well outliers and then add them back into the extreme bins. I'd also change the text on those bins to y, but that can easily be done by passing a custom set of ticks to the axis.

I've mocked up an example using the Chauvenet's criterion, one of a number of outlier tests. I'd originally thought to use the Grubbs test (or even better the multiple Grubbs Beck test) but there's a bit of work to code that. Chauvenet's criterion works quite simply by assuming that any value greater then m standard deviations from your mean is an outlier.

I've put this all together here and the function is:

function chauvenet (x) {
    var dMax = 3;
    var mean = d3.mean(x);
    var stdv = Math.sqrt(variance(x));
    var counter = 0;
    var temp = [];

    for (var i = 0; i < x.length; i++) {
        if(dMax > (Math.abs(x[i] - mean))/stdv) {
            temp[counter] = x[i]; 
            counter = counter + 1;
        }
    };

    return temp
}

The terms are all fairly obvious, dMax is the number of standard deviations, mean is the mean and stdv is the standard deviation (or square root of the variance).

Note I've not added the outliers back into the histogram, but that should be quite easy to do.

If d3 is giving you a hard time .. Try this http://imaginea.github.com/uvCharts :) You must already be aware of nvd3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!