Quote:
Originally Posted by whosnext
It is remarkably both simple and complex. There are multiple approaches to solving the problem, including Markov Chains.
simple in Excel, been done before
here is my Excel in Google
Streak column Excel
*****
here is R code for the matrix solution
Code:
#####################################################
# runs.m(m,N,p)
#
# Probability of at least 1 run of length m or more
# in N trials with probability p of success.
# Uses Markov chain.
#####################################################
require(expm)
runs.m = function(m,N,p) {
q = 1-p
A = matrix(rep(0,(m+1)^2),nrow=m+1)
A[1,1:m] = q
A[2:(m+1),1:m] = diag(p,m,m)
A[m+1,m+1] = 1
v = c(1,rep(0,m))
(A%^%N %*% v)[m+1]
}
#example
1/runs.m(25,10000000,0.5)
print(runs.m(25,10000000,0.5),9)
> 1/runs.m(25,10000000,0.5)
[1] 7.223312
> print(runs.m(25,10000000,0.5),9)
[1] 0.138440643
and an accurate online javascript streak calculator (thanks BruceZ)
I placed on Google (many others contain error in their code)
Streak Calculator
*****
of course, for simple and some exact answers
Wolfram Alpha (will time-out for large # of trials)
streak of 15 successes in 50 trials p=6/10
Wolfram Alpha
hope this helps out for future streak-type questions
the matrix result (in R) for the OP question
Code:
runs.m = function(m,N,p) {
+ q = 1-p
+ A = matrix(rep(0,(m+1)^2),nrow=m+1)
+ A[1,1:m] = q
+ A[2:(m+1),1:m] = diag(p,m,m)
+ A[m+1,m+1] = 1
+ v = c(1,rep(0,m))
+ (A%^%N %*% v)[m+1]
+ }
> print(runs.m(15,50,0.6),9)
[1] 0.00704428576
Last edited by kraps2312; 01-11-2018 at 06:58 PM.
Reason: added result from R