Skip to contents

Create a Brownian Motion Tibble

Usage

brownian_motion(
  .num_walks = 25,
  .n = 100,
  .delta_time = 1,
  .initial_value = 0,
  .return_tibble = TRUE
)

Arguments

.num_walks

Total number of simulations.

.n

Total time of the simulation.

.delta_time

Time step size.

.initial_value

Integer representing the initial value.

.return_tibble

The default is TRUE. If set to FALSE then an object of class matrix will be returned.

Value

A tibble/matrix

Details

Brownian Motion, also known as the Wiener process, is a continuous-time random process that describes the random movement of particles suspended in a fluid. It is named after the physicist Robert Brown, who first described the phenomenon in 1827.

The equation for Brownian Motion can be represented as:

W(t) = W(0) + sqrt(t) * Z

Where W(t) is the Brownian motion at time t, W(0) is the initial value of the Brownian motion, sqrt(t) is the square root of time, and Z is a standard normal random variable.

Brownian Motion has numerous applications, including modeling stock prices in financial markets, modeling particle movement in fluids, and modeling random walk processes in general. It is a useful tool in probability theory and statistical analysis.

Author

Steven P. Sanderson II, MPH

Examples

library(ggplot2)

set.seed(123)
brownian_motion()
#> # A tibble: 2,525 × 6
#>    walk_number     x      y cum_min cum_max cum_mean
#>    <fct>       <int>  <dbl>   <dbl>   <dbl>    <dbl>
#>  1 1               1  0       0       0       0     
#>  2 1               2 -0.560  -0.560   0      -0.280 
#>  3 1               3 -0.791  -0.791   0      -0.450 
#>  4 1               4  0.768  -0.791   0.768  -0.146 
#>  5 1               5  0.839  -0.791   0.839   0.0511
#>  6 1               6  0.968  -0.791   0.968   0.204 
#>  7 1               7  2.68   -0.791   2.68    0.558 
#>  8 1               8  3.14   -0.791   3.14    0.881 
#>  9 1               9  1.88   -0.791   3.14    0.992 
#> 10 1              10  1.19   -0.791   3.14    1.01  
#> # ℹ 2,515 more rows

set.seed(123)
brownian_motion() |>
  ggplot(aes(x = x, y = y, group = walk_number, color = walk_number)) +
  geom_line() +
  labs(title = "Brownian Motion", x = "Time", y = "Value") +
  theme_minimal() +
  theme(legend.position = "none")