-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
875 lines (708 loc) · 27.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<head>
<title>Fat Tails</title>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<div class = "columns">
<h1 class="title">Normal vs. Fat-tailed Distributions</h1>
<div class = "left column">
<h3> Normal</h3>
<p>A normal distribution varies a lot in the neighborhood of its average, but produces few examples beyond three standard deviations from that average.</p>
<p>Normal distributions are common in biology. Human height, for example: men average 5' 10," and their population has a standard deviation of 4". That means the chance of a man exceeding eight feet (6.5 standard deviations from the average) is astronomically small. And, in point of fact, among the billions of men ever measured, only about 20 have stood over eight feet. </p>
<h3> Fat-tailed</h3>
<p>A fat-tailed distribution looks normal but the parts far away from the average are thicker, meaning a higher chance of huge deviations.</p>
<p>Fat-tailed distributions are common in society. Since I love documentaries, <a href="http://www.boxofficemojo.com/genres/chart/?id=documentary.htm">here's a list </a>of the highest-grossing documentaries. Look how the top three highest-grossing documentaries earned dozens of times what any others did. If earnings were normal, these films would be like fifty-foot men. Moreover, a single person, Michael Moore, made four of the top ten! Among documentary directors, he's a thousand-foot man.</p>
</div>
<div class = "right column">
<h3>Don't get confused</h3>
<p>Fat tails don't mean <em>more</em> variance; just <em>different</em> variance. For a given variance, a higher chance of extreme deviations implies a lower chance of medium ones. To paraphrase <a href="https://docs.google.com/file/d/0B_31K_MP92hURjZxTkxUTFZnMVk/edit?pli=1">Nicholas Nassim Taleb</a>:</p>
<p style="margin-left: 10px;"><i>The normal distribution spends 68% of the time within one standard deviation of its mean. If finance has fat tails, how much time do stocks spend within one standard deviation? </i></p>
<p style="margin-left: 10px;"><i> Everyone answers: 'Less than 68%! Fat tails mean more deviation.' They're wrong: stock prices spend between 78% and 98% of their time within one standard deviation of the mean. </i></p>
<h3>Illustration</h3>
<p>Both distributions below have standard deviations of 1, but the left is fat-tailed and the right is normal. The slider changes the fat-tailedness of the left (measured here as 'kurtosis') while keeping its standard deviation at 1. As you fatten the tails, the middle bunches up to balance things out.</p>
<p>As each datum is drawn, its corresponding bar flickers and it gets plotted below. The cumulative plots are called 'walks'. Look how the fat-tailed deviations stay near the average, but sometimes go above 5 or below -5. The normal is the opposite.</p>
</div>
</div>
</div>
<div class="frame" id="frame"></div>
<script src="http://d3js.org/d3.v3.min.js"></script>
<script type="text/javascript">
var xdomain = [-6,6]
, p = .8
, a = .4
, binCount = 50
, rec = null
, colors = ['coral','blue']
, interp = d3.interpolateHsl
, dur = 150
, n = 50000
// A formatter for counts.
, formatCount = d3.format(",.0f")
, m = {
top: 50
, right: 30
, bottom: 30
, left: 75
}
, width = 1000 // total width
, height = 400
, hWidth = width / 2 - m.left - m.right // histogram width
, hHeight = 400 - m.top - m.bottom // histogram height
, x = d3.scale.linear()
.domain(xdomain)
.range([0, hWidth])
// Generate a histogram using twenty uniformly-spaced bins.
function ft(a, n){
var b = Math.sqrt((1 - p * Math.pow(a, 2))/(1-p));
var sample = [];
d3.range(n).map(function(d){
if (Math.random() <= p){
sample.push(a * d3.random.normal(0,1)());
} else {
sample.push(b * d3.random.normal(0,1)());
}
})
return sample;
}
function kurtosis(a, p){
var b = Math.sqrt((1 - p * Math.pow(a, 2))/(1-p));
return 3*( p * Math.pow(a,4) + (1-p) * Math.pow(b,4));
}
// find the historgram bin that corisponds to a given data value
function binIndexFromDatum(bins, datum){
var bin;
for(var i = 0; i < bins.length; i++){
bin = bins[i];
if(bin.x < datum && datum < bin.x + bin.dx) return i;
}
return -1;
}
var normData = d3.range(n).map(d3.random.normal(0,1))
, ftData = ft(a, n)
, binize = d3.layout.histogram()
.bins(x.ticks(binCount))
.frequency(false)
, data = binize(ftData)
, normBinned = binize(normData)
, y = d3.scale.linear()
.domain([0, d3.max(data, function(d) { return d.y; })])
.range([hHeight, 0]);
function color(d){
var c = d3.scale.linear()
.domain([0 , xdomain[1]])
.range(colors)
.interpolate(interp)
return c(Math.abs(d))
}
var yAxis = d3.svg.axis()
.scale(y)
.orient('left');
var hist2YAxis = d3.svg.axis()
.scale(y)
.orient('right')
var xAxis = d3.svg.axis()
.scale(x)
.orient("bottom");
var svg = d3.select("#frame").append("svg").classed('root-svg', true)
.attr("width", width)
.attr("height", height)
var hist1 = svg.append("g")
.attr("transform", "translate(" + m.left + "," + m.top + ")")
.attr('class', 'histogram1')
var hist2 = svg.append("g")
.attr("transform", "translate(" + (hWidth + m.left * 2) + "," + m.top + ")")
.attr('class', 'histogram2')
var b = Math.sqrt((1 - p * Math.pow(a, 2))/(1-p));
var k = 3*( p * Math.pow(a,4) + (1-p) * Math.pow(b,4));
var bar1 = hist1.selectAll(".bar")
.data(data)
.enter()
.append("g")
.attr("class", "bar")
.attr("transform", function(d) {
return "translate(" + x(d.x) + "," + y(d.y) + ")";
})
.append('g')
// a container element so we can seperately animate the opacity
.attr('class','opacity-container')
bar1.on("mouseover", function(d) {
tooltip.transition().duration(200).style("opacity", .9)
tooltip.html(d.x + "<br/>" ).style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
}); //end of mousover
bar1.on("mouseout", function(d) {
tooltip.transition()
.duration(100)
.style("opacity", 0);
}); //end of the mouseout
bar1.append("rect")
.attr("x", 1)
.attr("width", x(data[0].dx + x.domain()[0]) - 2 )
.attr("height", function(d) { return hHeight - y(d.y); })
.attr("stroke", "black")
.attr("stroke-width", "1px")
.style("fill", function(d){return color(d.x); });
var bar2 = hist2.selectAll(".bar")
.data(normBinned)
.enter()
.append("g")
.attr("class", "bar")
.attr("transform", function(d) {
return "translate(" + x(d.x) + "," + y(d.y) + ")";
})
.append('g')
// a container element so we can seperately animate the opacity
.attr('class','opacity-container')
bar2.on("mouseover", function(d) {
tooltip.transition().duration(200).style("opacity", .9)
tooltip.html(d.x + "<br/>" ).style("left", (d3.event.pageX) + "px")
.style("top", (d3.event.pageY - 28) + "px");
}); //end of mousover
bar2.on("mouseout", function(d) {
tooltip.transition()
.duration(100)
.style("opacity", 0);
}); //end of the mouseout
bar2.append("rect")
.attr("x", 1)
.attr("width", x(data[0].dx + x.domain()[0]) - 2 )
.attr("height", function(d) { return hHeight - y(d.y); })
.attr("stroke", "black")
.attr("stroke-width", "1px")
.style("fill", function(d){return color(d.x); });
hist1.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + hHeight + ")")
.call(xAxis);
hist1.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + 0 + ",0)")
.call(yAxis)
.append("svg:text")
.text("probability")
.attr("transform", "translate(" + -45 + "," + 80 + ") rotate(-90)")
.attr("class", "sliderLabel");
hist1.append("g")
.attr("class", "bigLabel")
.attr("transform", "translate(" + (hWidth/2) + "," + (-20) + ")")
.append("svg:text")
.attr('text-anchor','middle')
.text('Fat-tailed')
hist2.append("g")
.attr("class", "bigLabel")
.attr("transform", "translate(" + (hWidth/2) + "," + (-20) + ")")
.append("svg:text")
.attr('text-anchor','middle')
.text('Normal')
hist2.append("g")
.attr("class", "x axis")
.attr("transform", "translate(0," + hHeight + ")")
.call(xAxis);
hist2.append("g")
.attr("class", "y axis")
.attr("transform", "translate(" + (hWidth) + ",0)")
.call(hist2YAxis);
function redraw(a) {
ftData = ft(a, n);
data = binize(ftData);
y.domain([0, d3.max(data, function(d) { return d.y; })]);
hist1.select(".y.axis")
.transition()
.duration(200)
.call(yAxis).ease('quad');
hist1.selectAll('.bar').data(data)
.transition().duration(300).ease('cube')
.attr("transform", function(d) {
return "translate(" + x(d.x) + "," + y(d.y) + ")";
});
hist1.selectAll('rect').data(data)
.transition().duration(300).ease('cube')
.attr("height", function(d) { return hHeight - y(d.y); });
hist2.select(".y.axis")
.transition()
.duration(200)
.call(hist2YAxis).ease('quad');
hist2.selectAll('.bar').data(normBinned)
.transition().duration(300).ease('cube')
.attr("transform", function(d) {
return "translate(" + x(d.x) + "," + y(d.y) + ")";
});
hist2.selectAll('rect').data(normBinned)
.transition().duration(300).ease('cube')
.attr("height", function(d) { return hHeight - y(d.y); });
};
var h2 = hHeight - 200
var market1 = d3.select("#frame").append("svg")
.classed('market market1', true)
.attr("width", hWidth + m.left + m.right)
.attr("height", h2 + 50)
.append("g")
.attr("transform", "translate(" + m.left + "," + 30 + ")");
d3.select('.market1').append('text')
.attr('text-anchor', 'middle')
.attr("class", "plotLabel")
.attr('transform','translate(' + (m.left + hWidth/2) + ',20)')
.text('Fat-tailed Deviations');
var market2 = d3.select("#frame").append("svg")
.classed('market market2', true)
.attr("width", hWidth + m.left + m.right)
.attr("height", h2 + 50)
.append("g")
.attr("transform", "translate(" + 45 + "," + 30 + ")");
d3.select('.market2').append('text')
.attr('text-anchor', 'middle')
.attr("class", "plotLabel")
.attr('transform','translate(' + (m.left + hWidth/2 -30) + ',20)')
.text('Normal Deviations');
var brown1 = d3.select("#frame").append("svg")
.classed('brown1', true)
.attr("width", hWidth + m.left + m.right)
.attr("height", h2 + 50)
.append("g")
.attr("transform", "translate(" + m.left + "," + 30 + ")");
d3.select('.brown1').append('text')
.attr('text-anchor', 'middle')
.attr("class", "plotLabel")
.attr('transform','translate(' + (m.left + hWidth/2) + ',20)')
.text('Fat-tailed Walk')
var brown2 = d3.select("#frame").append("svg")
.classed('brown2', true)
.attr("width", hWidth + m.left + m.right)
.attr("height", h2 + 50)
.append("g")
.attr("transform", "translate(" + 45 + "," + 30 + ")");
d3.select('.brown2').append('text')
.attr('text-anchor', 'middle')
.attr("class", "plotLabel")
.attr('transform','translate(' + (m.left + hWidth/2 -25) + ',20)')
.text('Normal Walk')
var y2 = d3.scale.linear()
.domain(xdomain)
.range([h2, 0]);
var by1 = d3.scale.linear()
.domain(xdomain)
.range([h2, 0]);
var by2 = d3.scale.linear()
.domain(xdomain)
.range([h2, 0]);
var x2 = d3.scale.linear()
.domain([0, 50])
.range([0,hWidth])
var plotData1 = d3.range(50).map(function(){return newFTData();})
var plotData2 = d3.range(50).map(function(){return newNormalData();})
var brownData1 = d3.range(50).map(function(){return 0;})
var brownData2 = d3.range(50).map(function(){return 0;})
for( var i = 1; i < brownData1.length; i++){
brownData1[i] += plotData1[i] + brownData1[i-1]
};
for( var i = 1; i < brownData2.length; i++){
brownData2[i] += plotData2[i] + brownData2[i-1]
};
var yAxis2 = d3.svg.axis()
.scale(y2)
.tickSize(-hWidth)
.orient('left')
var byAxis1 = d3.svg.axis()
.scale(by1)
.tickSize(-hWidth)
.orient('left')
var byAxis2 = d3.svg.axis()
.scale(by2)
.tickSize(-hWidth)
.orient('left')
var xAxis2 = d3.svg.axis()
.scale(x2)
.orient("bottom");
market1.append("g")
.attr("class", "y axis")
.attr("transform", "translate(0,0)")
.call(yAxis2);
brown1.append("g")
.attr("class", "y axis")
.attr("transform", "translate(0,0)")
.call(byAxis1);
brown2.append("g")
.attr("class", "y axis")
.attr("transform", "translate(0,0)")
.call(byAxis2);
market2.append("g")
.attr("class", "y axis")
.attr("transform", "translate(0,0)")
.call(yAxis2);
var zeroLine1 = market1.append("line")
.attr({
x1: 0,
x2: hWidth,
y1: 0,
y2: 0,
class: "zero",
transform: "translate(0," + h2/2 + ")"
});
var bzeroLine1 = brown1.append("line")
.attr({
x1: 0,
x2: hWidth,
y1: 0,
y2: 0,
class: "zero"
});
var bzeroLine2 = brown2.append("line")
.attr({
x1: 0,
x2: hWidth,
y1: 0,
y2: 0,
class: "zero"
});
var zeroLine2 = market2.append("line")
.attr({
x1: 0,
x2: hWidth,
y1: 0,
y2: 0,
class: "zero",
transform: "translate(0," + h2/2 + ")"
});
var sdBox1 = market1.append("rect")
.attr({
width : hWidth,
height : y2(-1) - y2(1),
class : "sdBox",
x: 0,
y: y2(1)
})
var sdBox2 = market2.append("rect")
.attr({
width : hWidth,
height : y2(-1) - y2(1),
class : "sdBox",
x: 0,
y: y2(1)
});
var tooltip = d3.select("#frame").append("div") // the div used for the tooltips
.attr("class", "tooltip") // apply the 'tooltip' class
.style("opacity", 0);
var line1 = d3.svg.line()
.x(function(d,i) { return x2(i); })
.y(function(d) { return y2(d); });
var bline1 = d3.svg.line()
.x(function(d,i) { return x2(i); })
.y(function(d) { return y2(d); });
var bline2 = d3.svg.line()
.x(function(d,i) { return x2(i); })
.y(function(d) { return y2(d); });
var line2 = d3.svg.line()
.x(function(d,i) { return x2(i); })
.y(function(d) { return y2(d); });
function newFTData(){
var rand = Math.round( Math.random() * ftData.length)
var t = ftData[ rand ];
return t;
};
function newNormalData(){
var rand = Math.round( Math.random() * normData.length)
var t = normData[ rand ];
return t;
};
market1.append("defs").append("clipPath")
.attr("id", "clip1")
.append("rect")
.attr("width", hWidth)
.attr("height", h2);
brown1.append("defs").append("clipPath")
.attr("id", "bclip1")
.append("rect")
.attr("width", hWidth)
.attr("height", h2);
market2.append("defs").append("clipPath")
.attr("id", "clip2")
.append("rect")
.attr("width", hWidth)
.attr("height", h2);
brown2.append("defs").append("clipPath")
.attr("id", "bclip2")
.append("rect")
.attr("width", hWidth)
.attr("height", h2);
var clip1 = market1.append('g')
.attr('clip-path','url(#clip1)');
var bclip1 = brown1.append('g')
.attr('clip-path','url(#bclip1)');
var clip2 = market2.append('g')
.attr('clip-path','url(#clip2)');
var bclip2 = brown2.append('g')
.attr('clip-path','url(#bclip2)');
var path1 = clip1
.append('path')
.data([plotData1])
.attr({
class: 'line',
fill: 'none',
stroke: 'black'
})
.attr("d", line1)
.classed('plotline',true);
var bpath1 = bclip1
.append('path')
.data([brownData1])
.attr({
class: 'brown line',
fill: 'none',
stroke: 'black'
})
.attr("d", bline1)
.classed('plotline',true);
var bpath2 = bclip2
.append('path')
.data([brownData2])
.attr({
class: 'brown line',
fill: 'none',
stroke: 'black'
})
.attr("d", bline2)
.classed('plotline',true);
var path2 = clip2
.append('path')
.data([plotData2])
.attr({
class: 'line',
fill: 'none',
stroke: 'black'
})
.attr("d", line2)
.classed('plotline',true);
function stdDev(data){
var ex = 0, e_x2 = 0
for(var i in data){
var l = data[i];
ex += l / data.length;
e_x2 += Math.pow(l, 2)/data.length
};
var ex_2 = Math.pow(ex,2);
return Math.pow(e_x2 - ex_2, 0.5);
}
function plot1Anim(){
var t = newFTData();
// nth child starts at 1
var binIndex = binIndexFromDatum(data, t) + 1;
hist1.selectAll('.bar:nth-child(' + binIndex + ') .opacity-container')
.transition()
.duration(200)
.ease('out')
.attr("opacity", "0.5")
.transition()
.ease('sin')
.duration(200)
.attr("opacity", "1")
plotData1.push(t);
var circle = clip1.selectAll("circle")
.data(plotData1, function(d){return d; });
circle.enter()
.append('circle')
.attr({
r: 10,
fill: function(d){return color(d);},
cx: function(d,i){return x2(i);},
cy: function(d){return y2(d);},
stroke: "black"
});
var v = stdDev(plotData1);
circle.transition().duration(dur).ease('linear')
.attr("cx", function(d,i){return x2(i -1);})
.attr("r", "3px");
circle.exit().remove();
path1
.attr("d", line1)
.attr("transform", null)
.transition()
.duration(dur)
.ease("linear")
.attr("transform", "translate(" + x2(-1) + ",0)")
// brownian plot
brownData1.push(brownData1[brownData1.length - 1] + t);
by1.domain([
d3.min([d3.min(brownData1) - 2, xdomain[0]])
, d3.max([d3.max(brownData1) + 2, xdomain[1]])
]);
byAxis1.scale(by1);
brown1.select('.y.axis').call(byAxis1);
bzeroLine1
.transition().duration()
.attr("y1", by1(0)).attr("y2", by1(0))
var bcircle = bclip1.selectAll("circle")
.data(brownData1, function(d){return d; });
bcircle.enter()
.append('circle')
.attr({
r: 10,
fill: '#999',
cx: function(d,i){return x2(i);},
cy: by1,
stroke: "black"
});
bcircle.transition().duration(dur).ease('linear')
.attr("cx", function(d,i){return x2(i -1);})
.attr('cy', function(d){ return by1(d); })
.attr("r", "3px");
bcircle.exit().remove();
bline1.y(by1)
bpath1
.attr("d", bline1)
.attr("transform", null)
.transition()
.duration(dur)
.ease("linear")
.attr("transform", "translate(" + x2(-1) + ",0)")
.each('end', plot1Anim);
plotData1.shift();
brownData1.shift();
};
plot1Anim();
function plot2Anim(){
var t = newNormalData();
// nth css selector starts at 1
var binIndex = binIndexFromDatum(normBinned, t) + 1;
hist2.selectAll('.bar:nth-child(' + binIndex + ') .opacity-container')
.transition()
.duration(200)
.ease('out')
.attr("opacity", "0.5")
.transition()
.ease('sin')
.duration(200)
.attr("opacity", "1");
plotData2.push(t);
var circle = clip2.selectAll("circle")
.data(plotData2, function(d){return d; });
circle.enter()
.append('circle')
.attr({
r: 10,
fill: function(d){return color(d);},
cx: function(d,i){return x2(i);},
cy: function(d){return y2(d);},
stroke: "black"
});
circle.transition().duration(dur).ease('linear')
.attr("cx", function(d,i){return x2(i -1);})
.attr("r", "3px");
circle.exit().remove();
path2
.attr("d", line2)
.attr("transform", null)
.transition()
.duration(dur)
.ease("linear")
.attr("transform", "translate(" + x2(-1) + ",0)")
// brownian plot
brownData2.push(brownData2[brownData2.length - 1] + t);
by2.domain([
d3.min([d3.min(brownData2) - 2, xdomain[0]])
, d3.max([d3.max(brownData2) + 2, xdomain[1]])
]);
byAxis2.scale(by2);
brown2.select('.y.axis').call(byAxis2);
bzeroLine2
.transition().duration()
.attr("y1", by2(0))
.attr("y2", by2(0));
var bcircle = bclip2.selectAll("circle")
.data(brownData2, function(d){ return d; });
bcircle.enter()
.append('circle')
.attr({
r: 10,
fill: '#999',
cx: function(d,i){return x2(i);},
cy: by2,
stroke: "black"
});
bcircle.transition().duration(dur).ease('linear')
.attr("cx", function(d,i){ return x2(i - 1);})
.attr('cy', function(d){ return by2(d); })
.attr("r", "3px");
bcircle.exit().remove()
bline2.y(by2)
bpath2
.attr("d", bline2)
.attr("transform", null)
.transition()
.duration(dur)
.ease("linear")
.attr("transform", "translate(" + x2(-1) + ",0)")
.each('end', plot2Anim);
plotData2.shift();
brownData2.shift();
}
plot2Anim()
;(function setupSlider(){
var sliderY = d3.scale.linear().domain([0.1, 1]).range([30,300]);
var sliderAxis = d3.svg.axis()
.scale(sliderY)
.orient("left")
.ticks(10)
.tickFormat(function(d){
return d3.round(kurtosis(d, p),1);
});
var slider = svg.append('g')
.attr('class', 'p-value-slider')
.attr('transform', 'translate(' + (width / 2 - 30) + ',50)')
.call(sliderAxis);
var drag = d3.behavior.drag()
.on('drag', function(d){
var circle = d3.select(this);
var d = Number(circle.attr('d')) + sliderY.invert(d3.event.dy);
if(d < sliderY.domain()[0] ) d = sliderY.domain()[0];
if(d > sliderY.domain()[1]) d = sliderY.domain()[1];
circle.attr('d', d);
circle.attr('cy', function(){
return sliderY(d);
})
redraw(Number(d3.select(this).attr('d')));
})
.on('dragend', function(){
redraw(Number(d3.select(this).attr('d')));
brownData1 = d3.range(50).map(function(){return 0;})
brownData2 = d3.range(50).map(function(){return 0;})
bpath1.data([brownData1])
bpath2.data([brownData2])
});
var sliderLabel = slider.append("text")
.text("Kurtosis (normality)")
.attr({
transform: "translate(-65," + 9 + ") rotate(0)",
class: "sliderLabel"
})
.style("font" ,"15px")
var dragger = slider.append('circle')
.attr('class', 'handle')
.attr('r', 7)
.attr('d', (sliderY.domain()[0] + sliderY.domain()[1]) / 2)
.attr('cy', function(){
return sliderY(Number(d3.select(this).attr('d')))
}).call(drag);
})();
</script>
<div class = "columns">
<div class = "left column">
<h3> Why This Matters</h3>
<p>Let's say you're a bank. People deposit their money, and you use it to place bets. Now, let's say you think the outcomes of the bets are normal, but they're actually fat-tailed. In this case, 90% of the time your bet works, but sometimes it doesn't, and when you're wrong you'll be very, very wrong. If you lose too much money at once, depositors will want their money back right away (like at the end of 'It's A Wonderful Life'). Then the government will have to bail you out.</p>
<p>It isn't just banks that should take notice, though. We also see fat tails in hurricane damage, crop losses, death from deadly conflicts, and other measures that public policy addresses.</p>
</div>
<div class = "right column">
<h3>More Information</h3>
<ul>
<li><a href="http://en.wikipedia.org/wiki/Fat-tailed_distribution">Wikipedia</a> </li>
<li><a href="http://www.fooledbyrandomness.com/FatTails.html">Nicholas Nassim Taleb's textbook (in progress)</a></li>
<li><a href="http://www.rff.org/News/Features/Pages/Understanding-Fat-Tailed-Distributions-and-What-They-Mean-for-Policy.aspx">Resources for the Future</a></li>
</ul>
<h3>Makers</h3>
<p>Made in d3.js by <a href="http://heylewis.com">Lewis Lehe</a> with help from <a href="http://vctr.me/">Victor Powell.</a></p>
</div>
</div>
</div>
</body>