Skip to contents

Out of a given number of trials flipping a fair coin (p = 0.5) n times, count the number of times a run (streak) of length k occurs

Usage

count_runs(
  trials,
  sample_space,
  sample_probs = NULL,
  sample_size,
  run_value,
  run_length
)

Arguments

trials

number, number of times flipping a coin n times.

sample_space

vector, vector of unique values from which to sample.

sample_probs

vector, vector of probabilities equal in length to sample_space.

sample_size

number, size of sample to generate from sample_space; e.g. n coin flips.

run_value

number or character, the value on which to count sequential occurrences.

run_length

number, length of streak of interest value.

Value

number, the total number of applicable runs; i.e. the number of runs where the length of the run is greater than or equal to the specified run_length.

Examples

count_runs(
 trials = 8,
 sample_space = c(0, 1),
 sample_size = 5,
 run_value = 1,
 run_length = 3
)
#> [1] 3