random_normal_walk: Generate Multiple Random Normal Walks in Multiple Dimensions

View source: R/gen-random-normal-walk.R

random_normal_walkR Documentation

Generate Multiple Random Normal Walks in Multiple Dimensions

Description

The random_normal_walk function generates multiple random walks in 1, 2, or 3 dimensions. Each walk is a sequence of steps where each step is a random draw from a normal distribution. The user can specify the number of walks, the number of steps in each walk, and the parameters of the normal distribution (mean and standard deviation). The function also allows for sampling a proportion of the steps and optionally sampling with replacement.

Usage

random_normal_walk(
  .num_walks = 25,
  .n = 100,
  .mu = 0,
  .sd = 0.1,
  .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.

.mu

A numeric value indicating the mean of the normal distribution. Default is 0.

.sd

A numeric value indicating the standard deviation of the normal distribution. Default is 0.1.

.initial_value

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

.samp

A logical value indicating whether to sample the normal distribution 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: Normal 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.

Author(s)

Steven P. Sanderson II, MPH

See Also

Other Generator Functions: brownian_motion(), discrete_walk(), geometric_brownian_motion(), random_normal_drift_walk()

Examples

set.seed(123)
random_normal_walk()

set.seed(123)
random_normal_walk(.dimensions = 3) |>
  head() |>
  t()


RandomWalker documentation built on June 8, 2025, 12:15 p.m.