Lk.waterman_function(a , k) { #this program compute the probability of k-zero-run, P(Lk>=d), # in a iid Bernoulli seq with P(1)=ps, # where n is the length of seq., # d is the length of Lk, and k is the num. of mismached. # output 3 values: est. of the prob, and its lower, upper bounds n <- length(a) d <- Lk.length(a, k) ps <- sum(a)/n s <- d - k EEW <- (n * (s/d - ps) * dbinom(s, d, ps)) * (-1) EEW <- exp(EEW) erro <- 7 * d * dbinom(s, d, ps) + (1 - pbinom(s, d, ps)) upb <- EEW + erro lob <- EEW - erro bd <- c(EEW, upb, lob) bd <- 1 - bd if(bd[2] > 1) bd[2] <- 1 if(bd[3] < 0) bd[3] <- 0 bd[1] }