View source: R/gen-random-binomial-walk.R
random_binomial_walk | R Documentation |
The random_binomial_walk
function generates multiple random walks using the binomial distribution via rbinom()
.
The user can specify the number of walks, the number of steps in each walk, the number of trials, and the probability of success.
The function also allows for sampling a proportion of the steps and optionally sampling with replacement.
random_binomial_walk(
.num_walks = 25,
.n = 100,
.size = 10,
.prob = 0.5,
.initial_value = 0,
.samp = TRUE,
.replace = TRUE,
.sample_size = 0.8,
.dimensions = 1
)
.num_walks |
An integer specifying the number of random walks to generate. Default is 25. |
.n |
An integer specifying the number of observations per walk. Must be greater than 0. Default is 100. |
.size |
An integer specifying the number of trials (zero or more). Default is 10. |
.prob |
A numeric value specifying the probability of success on each trial. Must be 0 <= .prob <= 1. Default is 0.5. |
.initial_value |
A numeric value indicating the initial value of the walks. Default is 0. |
.samp |
A logical value indicating whether to sample the binomial 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 |
.dimensions |
An integer specifying the number of dimensions (1, 2, or 3). Default is 1. |
This function generates random walks where each step is drawn from the binomial distribution using rbinom()
.
The user can control the number of walks, steps per walk, the number of trials (size
), and the probability of success (prob
).
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.
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:
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)
.
The tibble includes attributes for the function parameters.
Steven P. Sanderson II, MPH
Other Generator Functions:
brownian_motion()
,
discrete_walk()
,
geometric_brownian_motion()
,
random_beta_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_multinomial_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_displacement_walk()
,
random_geometric_walk()
,
random_hypergeometric_walk()
,
random_multinomial_walk()
,
random_negbinomial_walk()
,
random_poisson_walk()
,
random_smirnov_walk()
,
random_wilcox_walk()
,
random_wilcoxon_sr_walk()
set.seed(123)
random_binomial_walk()
set.seed(123)
random_binomial_walk(.dimensions = 2) |>
head() |>
t()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.