Data

Search for Best Configuration

M1 <- 9000001
M2 <- 10000000
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. 
##    2.92   16.35   20.36   21.03   24.99   74.30
Xsum %>%
  sd %>%
  round(2)
## [1] 6.52
Xsum %>%
  `<=`(5) %>%
  which %>%
  `[`(Xsum, .) %>%
  round(2)
## 9000655 9005380 9006413 9007008 9023236 9024813 9025651 9046884 9048751 9052478 
##    4.67    4.76    4.89    4.96    4.76    4.52    4.79    4.09    4.86    4.58 
## 9067268 9077125 9082545 9096724 9106351 9109197 9113897 9133211 9138200 9139402 
##    4.75    3.89    3.29    4.63    4.91    3.61    4.65    4.57    4.67    4.97 
## 9145526 9145537 9153519 9159713 9163338 9168587 9172581 9174766 9175126 9175588 
##    3.81    4.86    4.53    4.74    4.85    4.00    4.70    4.75    4.33    3.67 
## 9180926 9186095 9187195 9203805 9215502 9232488 9233750 9234351 9235645 9258036 
##    4.55    4.63    4.81    4.88    4.57    4.80    4.35    4.53    4.08    3.89 
## 9267524 9279015 9280891 9282712 9283725 9298195 9298373 9315322 9320980 9322053 
##    3.88    4.97    4.10    4.46    4.98    4.92    4.91    4.67    4.61    4.16 
## 9323244 9328104 9331840 9339784 9348595 9349540 9360103 9367870 9372794 9375028 
##    4.67    4.91    4.57    4.94    4.27    4.92    4.87    4.35    4.64    4.26 
## 9381348 9398121 9405478 9412591 9414824 9420116 9437659 9445399 9449916 9465124 
##    3.11    4.39    3.35    4.61    4.59    3.85    4.94    4.71    4.61    4.63 
## 9467957 9476685 9482404 9485857 9489796 9496736 9502425 9503383 9509233 9512323 
##    4.80    4.37    4.46    3.68    4.64    4.15    4.97    4.61    4.08    4.79 
## 9537232 9542364 9571285 9575128 9578095 9579341 9580247 9585287 9595148 9598678 
##    4.92    4.58    4.89    4.37    4.25    4.92    4.88    4.06    4.86    4.54 
## 9599074 9602323 9615798 9621742 9657837 9661777 9672570 9680927 9681176 9686378 
##    4.83    4.92    4.52    4.58    3.75    4.30    4.71    4.86    4.46    4.79 
## 9688393 9690718 9695177 9696799 9712179 9712463 9716727 9736209 9742490 9746067 
##    4.68    4.33    4.86    4.82    4.77    4.75    4.98    4.39    3.47    4.62 
## 9759831 9760421 9767509 9778853 9781587 9796550 9799215 9815588 9819029 9842822 
##    3.99    4.04    4.17    4.42    3.34    4.79    4.15    4.18    4.62    4.87 
## 9844354 9847974 9852998 9856124 9863356 9864680 9905419 9908488 9917862 9923718 
##    2.92    4.96    3.60    3.50    4.47    4.50    4.04    4.48    4.77    4.19 
## 9925975 9926941 9932192 9935357 9936429 9944531 9945596 9948431 9961689 9965940 
##    4.91    4.33    4.34    4.84    4.66    4.85    4.97    4.30    4.66    4.43 
## 9967120 9970155 9973061 9976894 9990275 9999361 9999527 
##    4.61    3.84    3.63    4.19    4.31    4.29    4.85
Xmin <- names(Xsum[which(Xsum == min(Xsum))])
Xmin
## [1] "9844354"

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] 2.915651

학번

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 60 75 50 137 25
Black 21 35 61 79 51 132 25
X1min <- tbl1 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X1min
## X-squared 
## 0.2522343

학번 홀짝

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

학적 상태

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

e-mail 서비스업체

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

전화번호의 분포

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 41 30 34 45 31 49 40 38 39 55
Black 40 35 34 40 33 49 44 39 43 47
X5min <- tbl5 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X5min
## X-squared 
##  1.774663

성씨 분포

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 73 57 29 244
Black 75 64 31 234
X6min <- tbl6 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X6min
## X-squared 
## 0.7066193

Sum of Chi_Squares

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