View source: R/gen-random-multinom-walk.R
random_multinomial_walk | R Documentation |
A multinomial random walk is a stochastic process in which each step is drawn from the multinomial distribution. This function allows for the simulation of multiple independent random walks in one, two, or three dimensions, with user control over the number of walks, steps, trials, probabilities, and dimensions. Sampling options allow for further customization, including the ability to sample a proportion of steps and to sample with or without replacement. The resulting data frame includes cumulative statistics for each walk.
random_multinomial_walk(
.num_walks = 25,
.n = 100,
.size = 3,
.prob = rep(1/3, .n),
.initial_value = 0,
.samp = TRUE,
.replace = TRUE,
.sample_size = 0.8,
.dimensions = 1
)
.num_walks |
Integer. Number of random walks to generate. Default is 25. |
.n |
Integer. Length of each walk (number of steps). Default is 100. |
.size |
Integer. Number of trials for each multinomial draw. Default is 3. |
.prob |
Numeric vector. Probabilities for each outcome. Default is rep(1/3, .n). |
.initial_value |
Numeric. Starting value of the walk. Default is 0. |
.samp |
Logical. Whether to sample the steps. Default is TRUE. |
.replace |
Logical. Whether sampling is with replacement. Default is TRUE. |
.sample_size |
Numeric. Proportion of steps to sample (0-1). Default is 0.8. |
.dimensions |
Integer. Number of dimensions (1, 2, or 3). Default is 1. |
The random_multinomial_walk
function generates multiple random walks using
the multinomial distribution via stats::rmultinom()
. Each walk is a sequence
of steps where each step is a random draw from the multinomial distribution.
The user can specify the number of walks, steps, trials per step, and the
probability vector. Sampling options allow for further customization,
including the ability to sample a proportion of steps and to sample with or
without replacement. The resulting data frame includes cumulative statistics
for each walk, making it suitable for simulation studies and visualization.
A tibble containing the generated random walks with columns:
walk_number
: Factor representing the walk number.
step_number
: Step index.
value
: Value of the walk at each step.
Cumulative statistics: cum_sum, cum_prod, cum_min, cum_max, cum_mean.
The following are also returned based upon how many dimensions there are and could be any of x, y and or z:
cum_sum
: Cumulative sum of dplyr::all_of(.dimensions)
.
cum_prod
: Cumulative product of dplyr::all_of(.dimensions)
.
cum_min
: Cumulative minimum of dplyr::all_of(.dimensions)
.
cum_max
: Cumulative maximum of dplyr::all_of(.dimensions)
.
cum_mean
: Cumulative mean of dplyr::all_of(.dimensions)
.
Steven P. Sanderson II, MPH
Other Generator Functions:
brownian_motion()
,
discrete_walk()
,
geometric_brownian_motion()
,
random_beta_walk()
,
random_binomial_walk()
,
random_cauchy_walk()
,
random_chisquared_walk()
,
random_displacement_walk()
,
random_exponential_walk()
,
random_f_walk()
,
random_gamma_walk()
,
random_geometric_walk()
,
random_hypergeometric_walk()
,
random_logistic_walk()
,
random_lognormal_walk()
,
random_negbinomial_walk()
,
random_normal_drift_walk()
,
random_normal_walk()
,
random_poisson_walk()
,
random_smirnov_walk()
,
random_t_walk()
,
random_uniform_walk()
,
random_weibull_walk()
,
random_wilcox_walk()
,
random_wilcoxon_sr_walk()
Other Discrete Distribution:
discrete_walk()
,
random_binomial_walk()
,
random_displacement_walk()
,
random_geometric_walk()
,
random_hypergeometric_walk()
,
random_negbinomial_walk()
,
random_poisson_walk()
,
random_smirnov_walk()
,
random_wilcox_walk()
,
random_wilcoxon_sr_walk()
set.seed(123)
random_multinomial_walk()
set.seed(123)
random_multinomial_walk(.dimensions = 3) |>
head() |>
t()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.