library(dplyr)
<- read.csv("../data/mice_pheno.csv")
data <- filter(data, Sex == "F" & Diet == "chow") %>%
controlPopulation select(Bodyweight) %>% unlist
Monte Carlo methods
Monte Carlo simulation
<- function(n) {
ttestgenerator <- sample(controlPopulation, n)
cases <- sample(controlPopulation, n)
controls <- (mean(cases) - mean(controls)) / sqrt(var(cases)/n + var(controls)/n)
tstat return(tstat)
}
<- replicate(1000, ttestgenerator(10))
ttests hist(ttests)
qqnorm(ttests)
abline(0, 1)
<- (seq(0, 999) + 0.5)/1000
ps qqplot(qt(ps, df = 2*3-2), ttests, xlim=c(-6, 6), ylim=c(-6, 6))
abline(0, 1)
qqnorm(controlPopulation)
qqline(controlPopulation)
Parametric Simulations for the Observations
<- rnorm(5000, mean=24, sd=3.5)
controls
<- function(n, mean=24, sd=3.5) {
ttestgenerator <- rnorm(n, mean, sd)
cases <- rnorm(n, mean, sd)
controls <- (mean(cases)-mean(controls)) /
tstat sqrt(var(cases)/n + var(controls)/n)
return(tstat)
}