Generate Multiple Random Walks with Drift
Source:R/gen-random-normal-walk-drift.R
random_normal_drift_walk.Rd
This function generates a specified number of random walks, each consisting of a specified number of steps. The steps are generated from a normal distribution with a given mean and standard deviation. An additional drift term is added to each step to introduce a consistent directional component to the walks.
Usage
random_normal_drift_walk(
.num_walks = 25,
.n = 100,
.mu = 0,
.sd = 1,
.drift = 0.1,
.initial_value = 0
)
Arguments
- .num_walks
Integer. The number of random walks to generate. Default is 25.
- .n
Integer. The number of steps in each random walk. Default is 100.
- .mu
Numeric. The mean of the normal distribution used for generating steps. Default is 0.
- .sd
Numeric. The standard deviation of the normal distribution used for generating steps. Default is 1.
- .drift
Numeric. The drift term to be added to each step. Default is 0.1.
- .initial_value
A numeric value indicating the initial value of the walks. Default is 0.
Value
A tibble in long format with columns walk_number
, x
(step index),
and y
(walk value). The tibble has attributes for the number of walks,
number of steps, mean, standard deviation, and drift.
Details
This function generates multiple random walks with a specified drift. Each walk is generated using a normal distribution for the steps, with an additional drift term added to each step.
See also
Other Generator Functions:
brownian_motion()
,
discrete_walk()
,
geometric_brownian_motion()
,
random_normal_walk()
Examples
library(ggplot2)
set.seed(123)
walks <- random_normal_drift_walk(.num_walks = 10, .n = 50, .mu = 0, .sd = 1.2,
.drift = 0.05)
ggplot(walks, aes(x = x, y = y, group = walk_number, color = walk_number)) +
geom_line() +
labs(title = "Random Walks with Drift", x = "Time", y = "Value") +
theme_minimal() +
theme(legend.position = "none")