Data

Search for Best Configuration

M1 <- 4000001
M2 <- 5000000
Xsum <- sapply(M1:M2, red_and_black)
names(Xsum) <- M1:M2
Xsum %>%
  summary %>%
  round(2) 
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max. 
##    2.97   16.36   20.36   21.02   24.95   67.28
Xsum %>%
  sd %>%
  round(2)
## [1] 6.5
Xsum %>%
  `<=`(5) %>%
  which %>%
  `[`(Xsum, .) %>%
  round(2)
## 4004877 4018491 4023275 4027159 4040521 4058390 4058396 4065647 4084134 4084627 
##    3.29    4.20    4.97    4.58    4.51    4.78    4.84    4.91    3.90    4.78 
## 4092374 4107382 4107951 4126911 4133966 4135043 4144343 4169092 4169286 4184810 
##    4.90    4.25    4.21    3.44    3.09    4.35    4.55    4.41    4.58    4.75 
## 4188171 4195555 4200546 4208482 4231325 4236657 4239493 4245495 4251195 4251368 
##    4.83    2.97    4.06    4.66    4.79    4.73    4.90    4.86    4.22    4.70 
## 4258817 4267177 4276517 4284672 4309360 4315364 4317539 4328171 4329316 4330931 
##    4.81    4.99    4.42    4.86    4.79    4.87    4.90    4.92    3.96    4.61 
## 4336858 4364450 4372179 4382787 4386986 4398324 4401147 4419716 4428469 4438827 
##    3.52    3.54    4.57    4.98    4.73    4.96    3.79    4.78    4.22    4.82 
## 4441110 4444460 4444617 4445342 4458597 4470145 4488665 4519806 4541221 4558858 
##    3.93    4.16    4.72    4.75    4.73    4.98    4.68    4.88    4.34    4.76 
## 4570772 4576927 4579205 4607198 4625536 4631582 4644482 4649764 4651712 4677569 
##    4.11    4.47    4.91    4.62    4.96    4.96    4.76    3.75    3.42    4.91 
## 4678611 4700599 4705171 4710318 4710889 4718523 4720848 4721740 4727034 4730532 
##    4.16    3.94    4.53    4.45    4.33    4.10    4.68    4.49    4.24    3.88 
## 4737841 4753517 4754464 4755323 4761267 4768698 4774808 4781081 4788783 4807666 
##    4.70    4.15    4.58    3.53    4.04    4.65    4.28    3.83    4.25    4.61 
## 4812205 4817971 4833698 4839610 4844918 4845155 4889184 4913262 4914959 4916936 
##    4.64    4.77    4.96    4.95    4.66    4.98    4.69    4.95    3.88    3.58 
## 4916962 4922817 4929978 4930149 4938123 4940398 4944902 4968994 4981963 4982391 
##    3.56    4.92    4.61    4.85    4.82    3.81    4.96    4.93    5.00    4.55 
## 4986325 
##    4.89
Xmin <- names(Xsum[which(Xsum == min(Xsum))])
Xmin
## [1] "4195555"

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), ylim = c(0, 0.065), 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.974019

학번

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 15 30 54 66 42 69 230
Black 15 28 58 65 42 67 232
X1min <- tbl1 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X1min
## X-squared 
## 0.2565391

학번 홀짝

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

학적 상태

tbl3 <- class_roll$status %>%
  table(class_roll$group, .) 
tbl3 %>%
  pander
  학생 휴학
Red 465 41
Black 464 43
X3min <- tbl3 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X3min
##  X-squared 
## 0.04770835

e-mail 서비스업체

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

전화번호의 분포

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 47 42 50 47 61 52 58 57 41 51
Black 46 50 42 53 56 53 58 57 44 48
X5min <- tbl5 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X5min
## X-squared 
##  2.181062

성씨 분포

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 116 70 37 283
Black 118 72 41 276
X6min <- tbl6 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X6min
## X-squared 
## 0.3370609

Sum of Chi_Squares

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