具有D3(v4)直方图功能的肥尾意味着空箱

时间:2018-06-07 10:54:12

标签: javascript d3.js statistics

我正在努力充分利用D3直方图功能,并且由于笨重的尾部数据分布而陷入困境。下面的data_points数组与多年来的国家人口密度有关。像人口密度高的香港这样的城市负责肥尾。

我想将数据拆分为八个独立的存储桶。我没有指定一个域,我假设直方图函数将使用最小值和最大值。我的代码如下:

var bins = d3.histogram().thresholds(7)(data_points);

直方图功能确实输出了8个桶,它们如下:

Array number 0 --> Lower limit: 1.73 Upper limit:1000
Array number 1 --> Lower limit: 1000 Upper limit:2000
Array number 2 --> Lower limit: 2000 Upper limit:3000
Array number 3 --> Lower limit: 3000 Upper limit:4000
Array number 4 --> Lower limit: 4000 Upper limit:5000
Array number 5 --> Lower limit: 5000 Upper limit:6000
Array number 6 --> Lower limit: 6000 Upper limit:7000
Array number 7 --> Lower limit: 7000 Upper limit:8456.76

不幸的是,经过仔细检查,水桶4-7是空的并且不包含任何值。我应该如何设置该功能,以便每个桶返回更好的值分布?现在我注意到直方图有大小相同的桶(即1000居民/ km2增量)。这不是更不规则,以更好地支持数据的分发吗?

我在其下方添加了一个片段,插入数据并运行直方图功能。让我知道如果我以完全错误的方式解决这个问题,我不是统计学家。

var data_points = [42.79,101.85,99.66,99.47,103.03,1771.43,1013.1,45.83,15,73.29,65.86,68.2,78.13,139.4,78.33,132.2,76.81,29.47,72.4,57.34,107.83,360.18,123.02,44.42,69.01,277.21,64.79,5.95,500.69,195.57,27.29,25.14,33.49,406.33,48.51,81.04,34.91,85.16,1050,105.31,1.73,44.74,71.18,72.71,181.69,16.09,9.32,209.19,46.04,303.4,121.96,143.31,85.74,8.37,12.4,82.85,7200.81,110.19,100.33,41.11,312.08,113.9,52.62,130.26,67.88,92.96,10.26,75.85,98.94,61.19,261.03,44.86,43.86,101.33,99.53,99.7,103.9,1857.14,1024.09,45.76,15.26,72.8,67.07,67.67,79.35,140.07,78.14,132.65,78.61,29.4,73.56,56.58,107.64,365.25,124.78,45,70.84,282.36,66.23,6.03,503.19,201.01,27.6,25.5,32.84,415.33,47.5,81.2,35.91,86.7,1066.67,105.19,1.76,44.82,72.07,73.26,183.6,16.25,9.32,213.61,46.83,308.67,121.6,149.95,85.13,8.37,12.82,82.51,7329.29,110.35,101.07,41.68,315.11,115.53,53.22,131.01,68.59,94.45,10.42,75.54,99.71,62,263.79,46.21,44.95,101.05,99.6,100.04,105.21,1796.99,1035.86,45.67,15.51,72.15,68.11,66.06,80.68,140.75,75.7,132.97,80.38,29.33,74.74,55.81,107.34,370.28,127.06,45.6,72.67,287.63,67.7,6.12,507.08,207.46,27.97,25.86,32.13,419.35,46.44,81.32,36.93,88.13,1083.33,105.19,1.78,44.89,72.96,73.85,185.67,16.34,9.67,218.06,47.62,313.93,121.73,151.53,84.73,8.38,13.2,81.9,7483.76,110.39,101.22,42.28,318.07,54.51,131.59,69.95,95.73,10.6,75.3,102.7,62.97,266.54,47.6,46.06,100.88,99.66,100.48,106.64,1818.05,1048.28,45.59,15.79,71.35,69.15,65.68,82.11,141.45,75.48,133.2,82.28,29.22,75.93,55.05,106.76,375.26,128.86,46.14,74.54,292.96,69.21,6.21,509.75,213.64,28.53,26.24,31.66,423.36,45.83,81.4,37.98,89.49,1103.33,105.16,1.81,44.96,73.85,74.48,187.86,16.44,10.63,222.54,48.44,321.67,121.73,160.27,84.3,8.39,13.58,81.5,7668.54,110.64,101.47,42.89,311.29,55.65,132.21,71.51,96.89,10.79,75.17,105.79,66.55,269.48,49.03,47.18,100.7,100,101.09,108.05,1884.21,1061.16,45.59,16.04,70.51,70.19,65.33,83.34,142.14,75.27,133.34,84.58,29.11,77.15,54.27,106.51,380.2,130.64,46.69,76.46,298.48,70.75,6.3,512.07,218.41,29.1,26.61,31.34,423.36,45.37,81.55,39.05,91.63,1120,105.13,1.84,44.96,74.75,75.13,190.14,16.63,11.61,227.04,49.24,327.3,121.73,175.22,83.98,8.4,13.95,81.11,7794.14,110.78,101.66,43.53,313.65,56.83,132.87,73.26,98.22,10.99,74.96,108.96,67.6,272.36,50.5,48.31,100.49,100.17,101.89,109.43,1977.44,1072.15,45.61,16.3,69.75,71.23,64.94,84.59,142.88,74.95,133.29,86.57,29.03,78.38,53.51,106.17,385.2,132.4,47.62,82.38,304.26,72.32,6.39,515.3,226.66,29.7,27,30.98,423.36,44.97,81.67,40.15,93.13,1140,105.04,1.87,45.03,75.62,75.78,192.44,16.92,12.01,231.6,50.04,332.93,121.59,193.76,83.7,8.41,14.31,80.71,7896.64,110.88,101.76,44.19,316.58,58.02,133.57,75.15,99.54,11.2,70.84,112.23,68.75,275.3,52.01,49.43,100.22,100.34,102.91,110.77,2060.15,1083.26,45.67,16.57,69.16,72.27,64.5,85.86,143.59,74.35,133.62,88.87,28.96,79.64,53.37,105.94,390.27,134.13,48.23,84.5,310.37,73.93,6.49,518.02,237.88,30.32,27.42,30.75,423.36,44.55,81.75,41.28,94.57,1160,104.98,1.9,45.03,76.42,76.41,194.7,17.26,12.21,236.17,50.83,338.53,121.55,213.17,83.38,8.42,14.43,80.3,7990.47,110.98,101.86,44.88,319.55,59.24,133.93,76.9,100.87,11.4,70.56,115.6,69.96,278.29,53.57,53.52,100.04,100.37,104.22,112.08,2141.35,1094.48,45.75,16.83,68.79,73.31,64.03,87.14,144.44,73.75,133.82,90.07,28.94,80.91,53.1,105.66,395.4,135.83,48.82,86.68,316.52,75.58,6.58,520.37,240.52,30.93,27.81,30.49,427.38,43.99,81.87,42.44,95.93,1180,104.93,1.93,45.11,77.23,77.01,197,17.63,12.95,240.76,51.62,344.13,121.42,228.91,82.89,8.42,14.77,79.88,8094.41,111.09,101.91,45.59,323.16,60.48,134.2,78.65,102.25,11.56,70.27,118.92,71.18,281.26,55.18,54.87,100.04,100.37,105.12,113.42,2183.46,1105.83,45.53,17.11,68.59,74.35,63.66,88.45,145.21,73.38,134.14,94.66,28.87,82.21,53,105.4,400.61,137.56,49.41,88.91,322.68,77.26,6.68,522.48,247.19,31.55,28.21,30.19,431.5,43.33,81.95,43.63,97.19,1200,104.81,1.95,45.11,78.05,77.59,199.33,17.99,13.35,245.37,52.4,351.02,121.44,239.14,82.4,8.42,15.06,79.56,8101.63,111.19,102.01,46.33,326.84,61.75,134.43,80.47,103.53,11.7,70.12,122.33,71.79,284.15,56.78,55.63,99.97,100.37,105.95,114.78,2227.07,1117.28,45.29,17.38,68.53,75.22,63.3,89.78,145.93,73.03,134.31,96.84,28.78,83.52,53,105.13,405.88,139.31,49.98,91.19,328.79,78.98,6.78,524.6,254.1,32.19,28.62,30.1,435.71,42.67,82.07,44.85,98.48,1220,104.72,1.98,45.11,78.87,77.87,201.68,18.38,13.77,250.06,53.18,358.04,121.4,242.72,81.92,8.42,15.36,79.24,8172.37,111.29,102.11,47.07,330.55,63.05,134.6,82.35,104.88,11.82,69.97,125.84,72.67,286.97,58.37,56.39,99.83,100.37,106.73,116.15,2272.18,1128.86,45.07,17.66,68.49,76.26,62.94,91.13,146.6,72.65,134.48,99.07,28.69,84.86,53.01,104.85,411.21,141.07,50.53,93.54,335.05,80.74,6.88,526.75,261.22,32.83,29.03,30.01,439.82,42.02,82.15,46.09,99.75,1240,104.66,2.01,45.18,79.69,78.14,204.06,18.75,14.2,254.84,53.95,365.2,121.35,245.78,81.43,8.42,15.67,78.93,8243.11,111.39,102.16,47.82,334.3,64.37,134.73,84.3,106.18,11.94,69.82,129.69,73.55,289.76,59.94,57.14,99.66,100.4,107.47,117.55,2317.29,1140.56,44.84,17.96,68.42,77.12,62.58,92.49,147.22,72.28,134.64,101.35,28.61,86.21,52.98,104.58,416.63,142.87,51.06,95.94,341.42,82.54,6.98,528.89,268.46,33.49,29.45,29.96,444.13,41.4,82.22,47.35,101.02,1260,104.57,2.04,45.18,80.51,78.67,206.47,19.09,14.65,259.71,54.72,372.5,121.27,246.39,80.94,8.41,15.98,78.61,8313.84,111.5,102.26,48.58,338.11,65.72,134.83,86.24,107.48,12.06,69.68,133.65,74.43,292.53,61.5,57.94,99.52,100.4,108.15,118.96,2363.91,1152.38,44.62,18.23,68.3,77.99,62.21,93.88,147.78,71.93,134.81,103.68,28.52,87.59,52.9,104.31,422.11,144.68,51.57,98.41,347.91,84.37,7.08,531.04,275.98,34.16,29.87,29.9,448.34,40.77,82.3,48.65,102.31,1280,104.48,2.07,45.25,81.32,79.18,208.91,19.41,15.11,264.67,55.8,379.95,121.17,247.01,80.44,8.4,16.3,78.29,8384.58,111.6,102.36,49.35,341.95,67.1,134.91,88.19,108.77,12.18,69.53,137.74,75.13,295.28,63.04,58.73,99.35,100.4,108.78,120.39,2410.53,1164.31,44.4,18.53,68.14,79.03,61.83,95.29,148.28,71.58,134.96,106.06,28.43,89,52.77,104.04,427.66,146.52,52.07,100.94,354.5,86.24,7.19,533.19,283.67,34.85,30.3,29.83,452.64,40.15,82.34,49.96,103.61,1303.33,104.42,2.11,45.25,82.12,79.66,211.37,19.7,15.6,269.73,56.92,387.55,121.05,247.62,79.92,8.39,16.63,77.99,8456.76,111.7,102.4,50.13,345.84,68.51,134.96,90.14,110.06,12.3,69.39,141.95,75.82,297.99,64.55]

var bins = d3.histogram().thresholds(7)(data_points);

console.log(bins);
<script src="//d3js.org/d3.v4.min.js"></script>

0 个答案:

没有答案