Age.case <- 40 + 5 * rnorm(50)
Age.cont <- 45 + 10 * rnorm(150)
Age <- c(Age.case, Age.cont)
Sex.case <- sample(c("M", "F"), 50, prob = c(.4, .6), replace = TRUE)
Sex.cont <- sample(c("M", "F"), 150, prob = c(.6, .4), replace = TRUE)
Sex <- as.factor(c(Sex.case, Sex.cont))
casecont <- as.factor(c(rep("case", 50), rep("cont", 150)))
## now look at the group properties:
boxplot(Age ~ casecont)
barplot(table(Sex, casecont), beside = TRUE)
m <- matchControls(casecont ~ Sex + Age)
## properties of the new groups:
boxplot(Age ~ m$factor)
barplot(table(Sex, m$factor))
Run the code above in your browser using DataLab