getWaitingTime: Waiting Time Calculation

Description Usage Arguments Value Examples

Description

Calculates the mean waiting time for a special absorbing markov chain (directed acyclic graph) that is based on an n-point-distribution. The value of this function answers the question:

"How long do I have to wait (on average) until every value of a discrete distribution (with a finite set of values) appears at least once?"

Uses Rcpp with memoization for faster calculations, but the problem is still O(2^n): 0.2s for length(x) = 15, and 11s for length(x) = 20. An approximation approach is given, see argument "max.len".

Usage

1
getWaitingTime(x, max.len = 10)

Arguments

x

[numeric]
Probabilities for which to calculate the mean waiting time.

max.len

[numeric(1)]
Controls calculation time. If x is longer than max.len, the waiting time will be approximated: x then just contains the max.len-1 smallest values and the sum of all others. Default is 10.

Value

[numeric(1)] Mean waiting time.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# How long until every side of a dice appears at least once (on average)?
getWaitingTime(rep(1/6, 6))

# Approximation:
## Not run: 
set.seed(1909)
tmp <- probnorm(runif(18))
system.time(print(getWaitingTime(tmp, max.len = 18)))
system.time(print(getWaitingTime(tmp, max.len = 10)))
system.time(print(getWaitingTime(tmp, max.len = 5)))

## End(Not run)

aschersleben/NBCD documentation built on May 12, 2019, 4:32 a.m.