Statistical Analysis of the number of coin tosses until you have n dollars if at each toss the probability of winning a dollar is p and of losing k dollars is , 1 - p By Shalosh B. Ekhad Suppose that at each round, you win a dollar with probability p and lose, k, dollars with probability 1-p and you quit as soon as you reach 1 dollar. If p>k/(k+1), then, of course, sooner or lat\ er you will reach your goal. How long should it take? Let g(t), be the formal power series, in t, satisfying the algebraic equatio\ n k (k + 1) (k + 1) g(t) - 1 - p (1 - p) t g(t) = 0 and in Maple format g(t)-1-p^k*(1-p)*t^(k+1)*g(t)^(k+1) = 0 The probability generating function for the number of rounds until reaching \ n n n dollars is, (p t) g(t) By implicit differentiation, we can compute any desired derivative, and henc\ e the expectation, variance, and higher moments. The expected duration (for arbitrary p,k,n), provided p>k/(k+1), is n ------------- (p - 1) k + p and in Maple format n/((p-1)*k+p) The variance is 2 n p (k + 1) (p - 1) - -------------------- 3 ((p - 1) k + p) and in Maple format -n*p*(k+1)^2*(p-1)/((p-1)*k+p)^3 The scaled , 3, -th moment about the mean is 2 2 (k + 1) (k p + p - k - 2 p) - ------------------------------------------ / 2 \1/2 2 | n p (k + 1) (p - 1)| (k p - k + p) |- --------------------| | 3 | \ ((p - 1) k + p) / and in Maple format -(k+1)*(k*p^2+p^2-k-2*p)/(k*p-k+p)^2/(-n*p*(k+1)^2*(p-1)/((p-1)*k+p)^3)^(1/2) The scaled , 4, -th moment about the mean is / 2 4 / 3 n \ 3 2 2 |-(k + 1) p - 2 (k + 1) |k - --- - 3| p + (6 k + (-6 n + 6) k - 3 n - 6) p \ \ 2 / / 3 n \ 2\ - 2 k |k - --- + 4| p - k |/(p n (p - 1) (p (k + 1) - k)) \ 2 / / and in Maple format (-(k+1)^2*p^4-2*(k+1)*(k-3/2*n-3)*p^3+(6*k^2+(-6*n+6)*k-3*n-6)*p^2-2*k*(k-3/2*n +4)*p-k^2)/p/n/(p-1)/(p*(k+1)-k) The scaled , 5, -th moment about the mean is / 3 6 2 / 5 n \ 5 (k + 1) |(k + 1) p + 8 (k + 1) |k - --- - 7/4| p \ \ 4 / 3 2 4 + (-19 k + (20 n - 60) k + (50 n - 5) k + 30 n + 36) p 2 3 + (80 k + (-40 n + 80) k - 20 n - 24) p 3 2 2 2 / 5 n \ + (19 k + (-20 n - 3) k + (10 n - 58) k) p - 8 k |k - --- + 11/4| p \ 4 / // 2 \1/2 \ 3\ / || n p (k + 1) (p - 1)| 3| - k | / ||- --------------------| p n (p - 1) (p (k + 1) - k) | / / || 3 | | \\ ((p - 1) k + p) / / and in Maple format (k+1)*((k+1)^3*p^6+8*(k+1)^2*(k-5/4*n-7/4)*p^5+(-19*k^3+(20*n-60)*k^2+(50*n-5)* k+30*n+36)*p^4+(80*k^2+(-40*n+80)*k-20*n-24)*p^3+(19*k^3+(-20*n-3)*k^2+(10*n-58 )*k)*p^2-8*k^2*(k-5/4*n+11/4)*p-k^3)/(-n*p*(k+1)^2*(p-1)/((p-1)*k+p)^3)^(1/2)/p /n/(p-1)/(p*(k+1)-k)^3 The scaled , 6, -th moment about the mean is / | 4 8 3 / 25 n 15\ 7 |(k + 1) p + 22 (k + 1) |k - ---- - --| p \ \ 22 11/ / 2 \ 2 | 2 / 5 n 105\ 15 n 155 n 75| 6 4 - 32 (k + 1) |k + |- --- + ---| k - ----- - ----- - --| p + (-86 k \ \ 8 16 / 32 32 16/ 3 2 2 2 2 + (145 n + 264) k + (-60 n + 990) k + (-90 n - 405 n + 400) k - 30 n 5 4 3 2 2 - 260 n - 240) p + (190 k + (-280 n + 380) k + (90 n - 420 n - 680) k 2 2 4 4 + (90 n + 120 n - 870) k + 15 n + 130 n + 120) p + (-86 k 3 2 2 2 + (145 n - 608) k + (-60 n + 435 n - 318) k + (-30 n + 30 n + 444) k) 3 4 3 2 2 2 p + (-32 k + (20 n + 146) k + (15 n - 135 n + 328) k ) p \ 4 3 3 4| / 2 2 2 2 + (22 k - 25 k n + 52 k ) p + k | / (p n (p - 1) (p (k + 1) - k) ) / / and in Maple format ((k+1)^4*p^8+22*(k+1)^3*(k-25/22*n-15/11)*p^7-32*(k+1)^2*(k^2+(-5/8*n+105/16)*k -15/32*n^2-155/32*n-75/16)*p^6+(-86*k^4+(145*n+264)*k^3+(-60*n^2+990)*k^2+(-90* n^2-405*n+400)*k-30*n^2-260*n-240)*p^5+(190*k^4+(-280*n+380)*k^3+(90*n^2-420*n-\ 680)*k^2+(90*n^2+120*n-870)*k+15*n^2+130*n+120)*p^4+(-86*k^4+(145*n-608)*k^3+(-\ 60*n^2+435*n-318)*k^2+(-30*n^2+30*n+444)*k)*p^3+(-32*k^4+(20*n+146)*k^3+(15*n^2 -135*n+328)*k^2)*p^2+(22*k^4-25*k^3*n+52*k^3)*p+k^4)/p^2/n^2/(p-1)^2/(p*(k+1)-k )^2 Let's check it against numerical computations and computer simulations for p=, 3/4, and k=, 2, and n= , 1 The exact value for these quantities are [4., 108., 8.371578907, 119.0833333, 2335.502121, 58602.92361] Let's see what happened after, 400, rounds The probability of ending in <=, 400, rounds is , 0.9999981914 The approximate values for the average, variance, and higher scaled-moments \ about the mean are [3.999192487, 107.6351977, 8.264516340, 113.1515727, 2045.683001, 44616.66939] compared to the exact values [4., 108., 8.371578907, 119.0833333, 2335.502121, 58602.92361] Now let's run a simulation with, 1000, times (where you quit after, 400, rounds) The fraction of games that ended in <=, 400, rounds is 1. the statistical data for the simulation turned out to be [3.613000000, 95.22323100, 7.996569840, 88.07012213, 1098.480726, 14719.08950] Of course, this changes each time, but it is not too far off. recall that the exact value is [4., 108., 8.371578907, 119.0833333, 2335.502121, 58602.92361] This ends this article that took, 0.541, seconds to generate.