3

我正在尝试使用 Javascript(d3 和 dc 库)(类似于 R 的密度函数)创建数据集的概率密度函数,但我还没有找到该怎么做。

可以做到吗?

谢谢

PD:jqplot 是这样的:http ://services.mbi.ucla.edu/jqplot/examples/kcp_pdf.html

4

1 回答 1

2

最后,我必须能够使用 KDE 算法(在science.js库中实现)

图书馆 dc 需要如何调整数据。当在具有所有外观及其频率的对象中减少数据时,必须将对象转换为每个外观都有一个条目的数组。需要这些组,因为 dc 需要一个组来绘制。

我的解决方案是:

// Creating the group
var group = dimension.group().reduceSum();
......
// Process the object. 
groups = group.all()
var newValues = []
for (var i = 0; i < groups.length; i++) {
    for (var j = 0; j < groups[i].value;j++){
        if (groups[i].key == "null" ||
            groups[i].key == null ||
            (groups[i].key - start < 0) ||
            (groups[i].key - end > 0)) {
        } else {
            newValues.push(parseFloat(groups[i].key))
        }
    }
}
.....
// Creating the new data that represent a density function. 
var kde = science.stats.kde().sample(newValues);
// I have replaced the bandwidth method (Multivariate Density Estimation)
// because this method works better than previous (Density Estimation) 
// min and max are calculated previously 
kde.bandwidth(science.stats.bandwidth.nrd0);
var frequency = Math.abs(parseFloat(max) - parseFloat(min)) / 512
var newData = kde(d3.range(min,max,frequency));

.....
// The array that is inside of the group is a reference (obviously but it is important)
// Deleting the contains of the array
groups.splice(0,groups.length) 
// add the new data
for (var key in newData) {
    groups.push({key:newData[key][0],value:newData[key][2]
})
于 2014-07-30T12:33:48.437 回答