Data

Search for Best Configuration

M1 <- 5000001
M2 <- 6000000
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.25   16.36   20.37   21.04   24.98   73.53
Xsum %>%
  sd %>%
  round(2)
## [1] 6.51
Xsum %>%
  `<=`(5) %>%
  which %>%
  `[`(Xsum, .) %>%
  round(2)
## 5005986 5015646 5018256 5027165 5027493 5032040 5037010 5039118 5041481 5043701 
##    4.79    4.37    4.85    4.88    3.62    4.93    4.76    3.79    4.32    3.55 
## 5047653 5063439 5068830 5072285 5072939 5075190 5090652 5094507 5095157 5099156 
##    4.18    4.93    4.36    4.52    4.33    4.51    4.60    3.65    4.05    4.87 
## 5117935 5119380 5121691 5121814 5122731 5135559 5152468 5167220 5173241 5184867 
##    4.51    4.31    4.92    3.79    4.76    4.93    4.96    4.78    4.95    4.87 
## 5184974 5192717 5198463 5208036 5208517 5215077 5216871 5220184 5232942 5233468 
##    4.07    4.83    4.13    4.52    3.81    4.91    4.79    4.78    4.68    3.87 
## 5236841 5239901 5243263 5262530 5270648 5279369 5284233 5293711 5293718 5294220 
##    4.92    4.20    4.86    4.60    4.20    4.80    3.73    4.85    4.52    4.76 
## 5302335 5308033 5310315 5321619 5323548 5327151 5327695 5330491 5331389 5332751 
##    4.67    4.48    4.79    4.95    4.79    4.33    2.25    4.32    2.61    4.07 
## 5345977 5350775 5351937 5353729 5362536 5375279 5400099 5406532 5427147 5432095 
##    3.53    4.80    4.62    4.85    4.60    3.78    4.14    4.94    3.67    2.78 
## 5445374 5454273 5459888 5478968 5514217 5525870 5527252 5534082 5538753 5540111 
##    4.38    4.67    3.21    4.70    4.70    4.22    4.61    3.67    4.78    4.12 
## 5552168 5570346 5580500 5592694 5604206 5605117 5607453 5641210 5641291 5641402 
##    4.53    4.65    4.63    4.76    3.82    4.35    4.99    3.74    4.40    4.14 
## 5643538 5643798 5653031 5670321 5676982 5688499 5688772 5697810 5703744 5709071 
##    4.82    3.97    4.70    4.34    4.95    4.88    4.92    3.93    4.96    4.66 
## 5710962 5739725 5741663 5749246 5749416 5749553 5754055 5762105 5772039 5777114 
##    3.86    4.17    3.47    4.08    4.45    4.93    4.77    3.73    4.68    4.76 
## 5782816 5783134 5783571 5790848 5791883 5792491 5796531 5799212 5812145 5819936 
##    4.43    4.74    4.80    4.65    4.63    4.27    3.88    4.83    4.95    4.03 
## 5823898 5830713 5833858 5843517 5848004 5851741 5858625 5862069 5862415 5863435 
##    4.99    4.70    4.12    4.54    3.95    4.86    4.80    4.72    3.46    4.99 
## 5865249 5872140 5889253 5915682 5919367 5931564 5939434 5942458 5968561 5976278 
##    4.49    4.52    4.38    4.57    4.81    4.08    4.10    4.70    4.61    4.86 
## 5978086 5983400 5994863 5995175 
##    4.79    4.95    4.29    4.97
Xmin <- names(Xsum[which(Xsum == min(Xsum))])
Xmin
## [1] "5327695"

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.254616

학번

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 78 51 133 25
Black 21 35 61 76 50 136 25
X1min <- tbl1 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X1min
## X-squared 
## 0.1148325

학번 홀짝

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

학적 상태

tbl3 <- class_roll$status %>%
  table(class_roll$group, .) 
tbl3 %>%
  pander
  학생 휴학
Red 326 77
Black 333 71
X3min <- tbl3 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X3min
## X-squared 
## 0.3163597

e-mail 서비스업체

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

전화번호의 분포

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 39 34 31 43 32 50 41 40 42 51
Black 42 31 37 42 32 48 43 37 40 51
X5min <- tbl5 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X5min
## X-squared 
##  1.044848

성씨 분포

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 71 60 31 241
Black 77 61 29 237
X6min <- tbl6 %>%
  chisq.test(simulate.p.value = TRUE) %>%
  `[[`(1)
X6min
## X-squared 
## 0.3504086

Sum of Chi_Squares

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