SHARE
TWEET

Index selection on 2 variables, 1 good & bad

a guest Jul 18th, 2019 79 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top