Advertisement
Guest User

Index selection on 2 variables, 1 good & bad

a guest
Jul 18th, 2019
251
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
R 0.48 KB | None | 0 0
  1. library(mvtnorm)
  2. library(MBESS)
  3. rgMatrix <- matrix(ncol=2, c(1,-0.3, -0.3, 1))
  4. covMatrix <- cor2cov(rgMatrix, sd=rep(1,2))
  5. generate <- function(mu=c(0,0), n=1000) { rmvnorm(n, mean=mu, sigma=covMatrix, method="svd") }
  6.  
  7. df <- as.data.frame(generate())
  8. colnames(df) <- c("Good", "Bad")
  9.  
  10. df$Index <- (df$Good * 1) - (df$Bad * 0.5)
  11. cutoff <- quantile(df$Index, probs=0.90)
  12. df$Selected <- df$Index > cutoff
  13. library(ggplot2)
  14. qplot(Good, Bad, color=Selected, data=df) + geom_point(size=5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement