abscondment (owner)

Revisions

gist: 128830 Download_button fork
public
Public Clone URL: git://gist.github.com/128830.git
Embed All Files: show embed
Text only #
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
Combining Tony Wright's post on startup acquisition rate (http://is.gd/101m1)
and Evan Miller's post on statistical significance in percentage ratings
(http://bit.ly/19CJAd).
 
Results:
 
{"CA"=>[2739, 188, "5.98%"],
 "NY"=>[692, 34, "3.54%"],
 "MA"=>[386, 20, "3.38%"],
 "TX"=>[323, 19, "3.80%"],
 "WA"=>[317, 26, "5.66%"],
 "FL"=>[254, 3, "0.40%"],
 "NJ"=>[227, 8, "1.80%"],
 "IL"=>[180, 9, "2.65%"],
 "VA"=>[164, 7, "2.08%"],
 "CO"=>[133, 7, "2.57%"],
 "PA"=>[131, 2, "0.42%"],
 "GA"=>[117, 2, "0.47%"],
 "MD"=>[94, 4, "1.67%"],
 "NC"=>[80, 1, "0.22%"],
 "AZ"=>[77, 1, "0.23%"]}
 
 
Script to calculate these results:
 
NB: script requires statistics2 gem, which can be found at
    http://github.com/abscondment/statistics2 and installed like so:
 
    $ gem sources -a http://gems.github.com (you only have to do this once)
    $ sudo gem install abscondment-statistics2
 
 
#!/usr/bin/ruby
require 'pp'
require 'statistics2'
 
def ci_lower_bound(pos, n, power=0.05)
    if n == 0
        return 0
    end
    z = Statistics2.pnormaldist(1-power/2)
    phat = 1.0*pos/n
    (phat + z*z/(2*n) - z * Math.sqrt((phat*(1-phat)+z*z/(4*n))/n))/(1+z*z/n)
end
 
results = %{
CA 2739 41.2% 188 53.3% 6.9%
NY 692 10.4% 34 9.6% 4.9%
MA 386 5.8% 20 5.7% 5.2%
TX 323 4.9% 19 5.4% 5.9%
WA 317 4.8% 26 7.4% 8.2%
FL 254 3.8% 3 0.8% 1.2%
NJ 227 1.8% 8 2.3% 6.6%
IL 180 2.7% 9 2.5% 5.0%
VA 164 2.5% 7 2.0% 4.3%
CO 133 2.0% 7 2.0% 5.3%
PA 131 2.0% 2 0.6% 1.5%
GA 117 1.8% 2 0.6% 1.7%
MD 94 1.4% 4 1.1% 4.3%
NC 80 1.2% 1 0.3% 1.2%
AZ 77 1.2% 1 .3% 1.3%
}.split(/\n/).reject!{|l| l.gsub(/[\s]+/,'').empty?}
results = results.inject({}) {
  |h,l|
  l = l.split
  h[l[0]] = [l[1].to_i, l[3].to_i, sprintf("%.2f%%", 100.0 * ci_lower_bound(l[3].to_f, l[1].to_f))]
  h
}
pp results