Created
February 5, 2020 15:38
-
-
Save krishnanraman/2e082433c7823be867c16e99b9b845a8 to your computer and use it in GitHub Desktop.
bivar1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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