Data

Search for Best Configuration

M1 <- 6000001
M2 <- 7000000
Xsum <- numeric(0)
Xsum <- sapply(M1:M2, red_and_black)
# Values_mat <- numeric(0)
# for(k in M1:M2){
#   set.seed(k)
#   N <- nrow(class_roll) 
#   class_roll$group <- 
#     sample(1:N) %%
#     2 %>%
#     factor(levels = c(0, 1), labels = c("Red", "Black"))
#   Xsum <- c(Xsum, red_and_black(class_roll)$Xsum)
#   Values_mat <- rbind(Values_mat, red_and_black(class_roll)$Values)
# }
# colnames(Values_mat) <- paste0("X", 1:6)
# Values_mat
# pairs(Values_mat)
# cor(Values_mat) %>%
#   round(4)
names(Xsum) <- M1:M2
Xsum %>%
  summary %>%
  round(2) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    1.34   16.34   20.36   21.03   24.98   69.46
Xsum %>%
  sd %>%
  round(2)
## [1] 6.51
Xsum %>%
  `<=`(5) %>%
  which %>%
  `[`(Xsum, .) %>%
  round(2)
## 6010157 6010902 6011230 6011816 6014232 6045352 6049783 6049790 6052375 6068418 
##    4.20    3.93    4.04    4.61    4.80    4.40    4.76    4.90    4.57    4.88 
## 6077393 6078525 6080173 6083943 6086686 6088513 6098195 6100474 6119334 6122011 
##    4.29    3.79    4.13    3.48    4.37    4.75    4.14    4.80    4.25    4.95 
## 6128254 6139575 6142373 6156793 6171237 6173858 6178972 6180492 6184915 6191014 
##    4.40    4.83    4.29    4.61    4.82    4.89    4.39    4.38    3.33    3.98 
## 6193463 6207071 6215773 6217629 6221350 6228273 6230068 6230858 6233518 6240109 
##    4.27    4.59    4.81    4.65    4.94    4.75    4.11    4.98    4.54    4.81 
## 6241742 6251009 6270089 6276063 6308831 6310393 6314069 6319079 6339915 6342218 
##    4.99    4.87    4.89    4.98    4.00    4.52    3.88    4.60    4.42    4.62 
## 6342821 6353503 6354129 6361433 6368549 6368982 6391668 6398282 6399121 6402698 
##    4.63    4.09    3.64    4.52    4.38    4.93    4.75    4.95    4.98    4.86 
## 6409153 6412764 6423961 6425815 6436041 6439884 6441556 6445187 6448819 6454572 
##    4.68    4.83    4.83    4.10    4.93    4.78    3.68    4.67    4.47    4.06 
## 6465530 6469594 6481550 6482032 6488391 6500605 6518258 6518857 6530522 6535225 
##    4.52    4.97    4.66    4.64    2.63    4.71    4.17    4.42    4.78    4.95 
## 6539949 6543521 6544138 6549472 6556272 6557323 6561448 6570032 6571529 6591637 
##    4.83    4.57    4.38    4.86    4.96    3.68    4.14    4.52    4.62    3.56 
## 6592308 6594404 6600405 6625183 6639424 6644244 6652389 6653764 6661934 6663484 
##    4.74    4.69    4.97    4.63    4.69    4.66    4.55    4.91    4.83    4.56 
## 6674806 6685441 6686399 6714483 6719130 6728598 6740359 6744769 6761968 6766341 
##    1.34    4.99    4.50    4.08    4.88    4.74    3.90    4.95    4.87    4.39 
## 6773692 6777487 6782042 6784012 6785166 6787267 6788397 6805121 6808121 6808139 
##    4.89    4.79    4.55    4.39    4.58    4.33    4.90    4.11    4.67    4.43 
## 6817884 6842248 6845438 6852165 6853253 6859806 6869836 6872215 6874103 6876353 
##    4.54    3.31    4.24    4.76    4.61    4.57    4.89    4.93    4.94    4.48 
## 6899413 6903022 6927207 6936873 6941242 6942117 6947068 6950382 6950469 6953671 
##    4.22    4.87    3.82    4.80    4.62    4.77    4.68    4.88    4.58    4.60 
## 6955541 6957304 6961667 6970532 6973360 6975349 6985564 6987132 6988081 6988716 
##    3.66    4.91    4.65    4.51    4.83    4.42    4.99    3.88    4.66    3.41
Xmin <- names(Xsum[which(Xsum == min(Xsum))])
Xmin
## [1] "6674806"

Plot

hist(Xsum, prob = TRUE, nclass = 30, xlim = c(0, 50), ylim = c(0, 0.065))
x <- seq(0, 50, by = 0.1)
lines(x, dchisq(x, df = 21), col = "red")
legend("topright", inset = 0.05, legend = c("Xsum", "Chi-square(21)"), col = c("black", "red"), lty = 1)

plot(density(Xsum), xlim = c(0, 50), main = "Density Estimation of Xsum")
lines(x, dchisq(x, df = 21), col = "red")
legend("topright", inset = 0.05, legend = c("Xsum", "Chi-square(21)"), col = c("black", "red"), lty = 1)

Randomization

set.seed(Xmin)
N <- nrow(class_roll) 
class_roll$group <- 
  sample(1:N) %%
  2 %>%
  factor(levels = c(0, 1), labels = c("Red", "Black"))
red_and_black(Xmin)
## [1] 1.336604

학번

class_roll$id_2 <-
  class_roll$id %>%
  ifelse(. <= 2016, "2016", .)
tbl1 <- class_roll %$%
  table(.$group, .$id_2 %>% substr(1, 4)) %>%
  `colnames<-`(c("2016 이전", 2017:2022)) 
tbl1 %>%
  pander
  2016 이전 2017 2018 2019 2020 2021 2022
Red 20 36 61 77 49 135 25
Black 21 35 60 77 52 134 25
X1min <- tbl1 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X1min
## X-squared 
## 0.1383267

학번 홀짝

tbl2 <- class_roll$id %>%
  as.numeric %>%
  `%%`(2) %>%
  factor(levels = c(1, 0), labels = c("홀", "짝")) %>%
  table(class_roll$group, .) 
tbl2 %>%
  pander
 
Red 209 194
Black 211 193
X2min <- tbl2 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X2min
##  X-squared 
## 0.01086865

학적 상태

tbl3 <- class_roll$status %>%
  table(class_roll$group, .) 
tbl3 %>%
  pander
  학생 휴학
Red 329 74
Black 330 74
X3min <- tbl3 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X3min
##    X-squared 
## 0.0002782937

e-mail 서비스업체

tbl4 <- class_roll$email %>%
  strsplit("@", fixed = TRUE) %>%
  sapply("[", 2) %>%
  `==`("naver.com") %>%
  ifelse("네이버", "기타서비스") %>%
  factor(levels = c("네이버", "기타서비스")) %>%
  table(class_roll$group, .) 
tbl4 %>%
  pander
  네이버 기타서비스
Red 331 72
Black 333 71
X4min <- tbl4 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X4min
##  X-squared 
## 0.01177796

전화번호의 분포

cut_label <- paste(paste0(0:9, "000"), paste0(0:9, "999"), 
                   sep = "~")
tbl5 <- class_roll$cell_no %>%
  substr(start = 8, stop = 11) %>%
  sapply(as.numeric) %>%
  cut(labels = cut_label, 
      breaks = seq(0, 10000, by = 1000)) %>%
  table(class_roll$group, .) 
tbl5 %>%
  pander
  0000~0999 1000~1999 2000~2999 3000~3999 4000~4999 5000~5999 6000~6999 7000~7999 8000~8999 9000~9999
Red 42 33 36 43 31 47 42 37 39 53
Black 39 32 32 42 33 51 42 40 43 49
X5min <- tbl5 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X5min
## X-squared 
##  1.068188

성씨 분포

f_name <- class_roll$name %>%
  substring(first = 1, last = 1) 
tbl6 <- f_name %>%
  `%in%`(c("김", "이", "박")) %>%
  ifelse(f_name, "기타") %>%
  factor(levels = c("김", "이", "박", "기타")) %>%
  table(class_roll$group, .) 
tbl6 %>%
  pander
  기타
Red 74 61 31 237
Black 74 60 29 241
X6min <- tbl6 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X6min
## X-squared 
## 0.1071649

Sum of Chi_Squares

Xsum_min <- X1min + X2min + X3min + X4min + X5min + X6min
Xsum_min
## X-squared 
##  1.336604