The results of two coins which are tossed 200 times respectively are:
(A)
11110000000000100000101100000100000101001111001100
01111110010110110101101001111001100011011101100000
10001001111110100100001011001011101101110001010010
01100111111100011100101000101001110011100010100111
(B)
01110010010010100010011110010100010011010111001110
01111011010111101101001000111001101011010101101001
00101001110110100100001110101101101001110101100110
01110011110110001110011010111001110011110010100111
Which is the unfair one (or a false record)? In the animation below, x1 denotes the first coin, while x2 is the record of the second coin. The plot in the middle is 1000 simulations from the Binomial distribution with p = 0.5 and size = 1. An equivalent question to the hypothesis test is, which plot looks like the simulation more? Of course we should give a visual definition to “similarity” before comparison. Imagine if you are going to perform a test numerically, which statistic will you choose? For me, at least three options are available:
- Number of heads (or tails): if too many/few heads (or tails) show up, the coin might be unfair
- Maximum run length, i.e. maximum number of successive 0’s or 1’s (e.g. for coin A, there are ten 0’s); don’t take it for granted that ten successive 0’s is a rare event in 200 tosses – the probability is not
0.5^10; if the run length is too long or too short, we may consider the coin as unfair - Number of changes from 0 to 1 or 1 to 0: if the coin changes too frequently from one side to the other side, it can be regarded as unusual too
Accordingly, we can present these statistics in a visual way. Plot the observed sequences and a simulated sequence as a reference, and compare observed graphs with the reference to see which one is unusual:
- How many points are in the top (equivalently, bottom)
- Length of the longest horizontal segment
- Density of vertical lines
Now watch the Flash animation below (Fullscreen Flash animation):
Donate
As a freelancer (currently working as a contractor) and a dad of three kids, I truly appreciate your donation to support my writing and open-source software development! Your contribution helps me cope with financial uncertainty better, so I can spend more time on producing high-quality content and software. You can make a donation through methods below.
-
Venmo:
@yihui_xie, or Zelle:[email protected] -
Paypal
-
If you have a Paypal account, you can follow the link https://paypal.me/YihuiXie or find me on Paypal via my email
[email protected]. Please choose the payment type as “Family and Friends” (instead of “Goods and Services”) to avoid extra fees. -
If you don’t have Paypal, you may donate through this link via your debit or credit card. Paypal will charge a fee on my side.
-
-
Other ways:
WeChat Pay (微信支付:谢益辉) Alipay (支付宝:谢益辉) 

When sending money, please be sure to add a note “gift” or “donation” if possible, so it won’t be treated as my taxable income but a genuine gift. Needless to say, donation is completely voluntary and I appreciate any amount you can give.
Please feel free to email me if you prefer a different way to give. Thank you very much!
I’ll give back a significant portion of the donations to the open-source community and charities. For the record, I received about $30,000 in total (before tax) in 2024-25, and gave back about $15,000 (after tax).