Skip to contents

The random_smirnov_walk function generates multiple random walks using the Smirnov distribution via rsmirnov(). The user can specify the number of walks, the number of steps in each walk, the sizes parameter, and the alternative hypothesis. The function also allows for sampling a proportion of the steps and optionally sampling with replacement.

Usage

random_smirnov_walk(
  .num_walks = 25,
  .n = 100,
  .sizes = c(1, 1),
  .z = NULL,
  .alternative = "two.sided",
  .initial_value = 0,
  .samp = TRUE,
  .replace = TRUE,
  .sample_size = 0.8,
  .dimensions = 1
)

Arguments

.num_walks

An integer specifying the number of random walks to generate. Default is 25.

.n

An integer specifying the number of steps in each walk. Default is 100.

.sizes

A numeric vector of length 2 specifying the sizes parameter for rsmirnov. Default is c(1, 1).

.z

Optional numeric vector for the z parameter in rsmirnov. Default is NULL.

.alternative

One of "two.sided" (default), "less", or "greater". Indicates the type of test statistic.

.initial_value

A numeric value indicating the initial value of the walks. Default is 0.

.samp

A logical value indicating whether to sample the Smirnov values. Default is TRUE.

.replace

A logical value indicating whether sampling is with replacement. Default is TRUE.

.sample_size

A numeric value between 0 and 1 specifying the proportion of .n to sample. Default is 0.8.

.dimensions

An integer specifying the number of dimensions (1, 2, or 3). Default is 1.

Value

A tibble containing the generated random walks with columns depending on the number of dimensions:

  • walk_number: Factor representing the walk number.

  • step_number: Step index.

  • y: If .dimensions = 1, the value of the walk at each step.

  • x, y: If .dimensions = 2, the values of the walk in two dimensions.

  • x, y, z: If .dimensions = 3, the values of the walk in three dimensions.

The following are also returned based upon how many dimensions there are and could be any of x, y and or z:

  • walk_number: Factor representing the walk number.

  • x: Step index.

  • y: Smirnov distribution values.

  • cum_sum: Cumulative sum of y.

  • cum_prod: Cumulative product of y.

  • cum_min: Cumulative minimum of y.

  • cum_max: Cumulative maximum of y.

The tibble includes attributes for the function parameters.

Details

This function generates random walks where each step is drawn from the Smirnov distribution using rsmirnov(). The user can control the number of walks, steps per walk, the sizes parameter (default c(1, 1)), and the alternative hypothesis. The parameter z can be provided or left as NULL (default). The function supports 1, 2, or 3 dimensions, and augments the output with cumulative statistics for each walk. Sampling can be performed with or without replacement, and a proportion of steps can be sampled if desired.

Author

Steven P. Sanderson II, MPH

Examples

set.seed(123)
random_smirnov_walk()
#> # A tibble: 2,000 × 8
#>    walk_number step_number     y cum_sum_y cum_prod_y cum_min_y cum_max_y
#>    <fct>             <int> <dbl>     <dbl>      <dbl>     <dbl>     <dbl>
#>  1 1                     1     1         1          0         1         1
#>  2 1                     2     1         2          0         1         1
#>  3 1                     3     1         3          0         1         1
#>  4 1                     4     1         4          0         1         1
#>  5 1                     5     1         5          0         1         1
#>  6 1                     6     1         6          0         1         1
#>  7 1                     7     1         7          0         1         1
#>  8 1                     8     1         8          0         1         1
#>  9 1                     9     1         9          0         1         1
#> 10 1                    10     1        10          0         1         1
#> # ℹ 1,990 more rows
#> # ℹ 1 more variable: cum_mean_y <dbl>

set.seed(123)
random_smirnov_walk(.dimensions = 2) |>
  head() |>
  t()
#>             [,1] [,2] [,3] [,4] [,5] [,6]
#> walk_number "1"  "1"  "1"  "1"  "1"  "1" 
#> step_number "1"  "2"  "3"  "4"  "5"  "6" 
#> x           "1"  "1"  "1"  "1"  "1"  "1" 
#> y           "1"  "1"  "1"  "1"  "1"  "1" 
#> cum_sum_x   "1"  "2"  "3"  "4"  "5"  "6" 
#> cum_sum_y   "1"  "2"  "3"  "4"  "5"  "6" 
#> cum_prod_x  "0"  "0"  "0"  "0"  "0"  "0" 
#> cum_prod_y  "0"  "0"  "0"  "0"  "0"  "0" 
#> cum_min_x   "1"  "1"  "1"  "1"  "1"  "1" 
#> cum_min_y   "1"  "1"  "1"  "1"  "1"  "1" 
#> cum_max_x   "1"  "1"  "1"  "1"  "1"  "1" 
#> cum_max_y   "1"  "1"  "1"  "1"  "1"  "1" 
#> cum_mean_x  "1"  "1"  "1"  "1"  "1"  "1" 
#> cum_mean_y  "1"  "1"  "1"  "1"  "1"  "1"