Skip to content

Instantly share code, notes, and snippets.

@alexhallam
Created June 28, 2021 11:20
Show Gist options
  • Save alexhallam/ff07fe276728151d17f4df2e0658d067 to your computer and use it in GitHub Desktop.
Save alexhallam/ff07fe276728151d17f4df2e0658d067 to your computer and use it in GitHub Desktop.
Monte Carlo Addition of Random Variables
# calculate the sum of a, b, b2
n <- 1000
m <- 10
a <- rnorm(n, 10)
b <- rnorm(n, 20)
b2 <- .1*a + .1*b
c <- sample(a, size = m*n, replace=T) + sample(b, size = m*n, replace=T) + sample(b2, size = m*n, replace=T)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment