The custom_walk function generates multiple random walks in 1, 2, or 3 dimensions
using a user-provided custom function. Each walk is a sequence of steps where each
step is generated by calling the provided custom function. This allows users to
create random walks with any type of step distribution.
custom_walk(
.n = 100,
.num_walks = 25,
.initial_value = 0,
.dimensions = 1,
.custom_fns
)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.
An integer specifying the number of steps in each walk. Default is 100.
An integer specifying the number of random walks to generate. Default is 25.
A numeric value indicating the initial value of the walks. Default is 0.
An integer specifying the number of dimensions (1, 2, or 3). Default is 1.
A function that generates a single random step. The function should take no parameters and return a single numeric value. This function will be called repeatedly to generate steps for the random walks.
Steven P. Sanderson II, MPH
This function provides a flexible way to generate random walks using any custom random number generation function. The custom function should take no parameters and return a single numeric value representing the step displacement. The function will be called repeatedly to generate the required number of steps for each walk and dimension.
The resulting data structure follows the same pattern as other walk generation functions in this package, including cumulative statistics and proper attribute setting for further analysis and visualization.
Other Generator Functions:
brownian_motion(),
discrete_walk(),
double_pendulum_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_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()
# Biased random walk with upward trend
biased_displacement <- function() {
return(rnorm(1, mean = 0.1, sd = 1.0))
}
set.seed(123)
custom_walk(.n = 100, .num_walks = 5, .custom_fns = biased_displacement)
# Multi-dimensional custom walk
set.seed(123)
custom_walk(.n = 50, .num_walks = 3, .dimensions = 2, .custom_fns = biased_displacement)
Run the code above in your browser using DataLab