data(HumanGeneLengths)
str(HumanGeneLengths)
histogram(~gene.length, HumanGeneLengths, subset=gene.length<15000)
if (require(manipulate)){
## Resampled mean, sd, SE
genes <- function(n){
nreps = 1000
sample.mean <- numeric(nreps) # vector for sample means
sample.se <- numeric(nreps) # vector for sample standard errors
sample.sd <- numeric(nreps) # vector for sample standard deviations
for (i in 1:nreps){
random.sample <- sample(HumanGeneLengths$gene.length, size = n)
sample.mean[i] <- mean(random.sample)
sample.sd[i] <- sd(random.sample)
sample.se[i] <- se(random.sample)
}
hist.bins <- hist(sample.mean, breaks = 30, plot = FALSE)
hist(sample.mean,
breaks = 30, xlim = c(1000, 4000),
xlab = "Sample mean length (nucleotides)",
col = "red", main = "")
abline(v = mean(sample.mean), col = "blue", lwd = 2)
text(x = 3200, y = 0.6 * max(hist.bins$counts),
pos = 4, cex = 1.25,
paste("n = ", n,
"mean = ", round(mean(sample.mean), digits = 1),
"sd = ", round(mean(sample.sd), digits = 1),
"se = ", round(mean(sample.se), digits = 1), sep = ""))
}
manipulate(genes(nreps), nreps = slider(1, 500))
}
Run the code above in your browser using DataLab