Skip to content

Instantly share code, notes, and snippets.

@krishnanraman
Created February 5, 2020 15:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krishnanraman/2e082433c7823be867c16e99b9b845a8 to your computer and use it in GitHub Desktop.
Save krishnanraman/2e082433c7823be867c16e99b9b845a8 to your computer and use it in GitHub Desktop.
bivar1
rm(list=ls())
library(MASS)
mu <- c(1,0)
Sigma <- matrix(c(1,0.5,0.5,1),2,2)
n<- 1000
sumc <- c()
for(times in 1:1000) {
x<- mvrnorm(n=n,mu,Sigma)
sum<-0
for(i in 1:(n-1)) {
j = 0
if (x[i,1] > x[i,2]) { j=1 } else { j=2}
sum <- sum + x[(i+1),j]
}
mysum <- sum/(n-1)
sumc<- c(sumc, mysum)
}
hist(sumc)
summary(sumc)
sqrt(var(sumc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment