Disclaimer
This notebook gives a graphical explanation of the central limit theorem and shows its consequences for quantitative genetics.
Sampling
Take a number of random numbers from the uniform distribution and sum them up. Repeat that for a given number of times and look at the distribution of the sums.
Example
n_nr_random_numbers <- 100
n_nr_repeat <- 1000
# draw 100 random numbers from uniform distributio
vec_random_numbers <- runif(n_nr_random_numbers)
# sum of random numbers
sum_random_numbers <- sum(vec_random_numbers) / n_nr_random_numbers
# repeat above
rep_sum <- NULL
for (i in 1:n_nr_repeat){
vec_random_numbers <- runif(n_nr_random_numbers)
sum_random_numbers <- sum(vec_random_numbers) / n_nr_random_numbers
rep_sum <- c(rep_sum, sum_random_numbers)
}
#rep_sum
hist(rep_sum)
Loops
# Output number 1 to 5
cat("1\n")
1
cat("2\n")
2
cat("3\n")
3
cat("4\n")
4
cat("5\n")
5
for (i in 1:5){
cat(i, "\n")
}
1
2
3
4
5
LS0tCnRpdGxlOiAiRXhwbGFpbiBDZW50cmFsIExpbWl0IFRoZW9yZW0iCm91dHB1dDogaHRtbF9ub3RlYm9vawotLS0KCiMgRGlzY2xhaW1lcgpUaGlzIG5vdGVib29rIGdpdmVzIGEgZ3JhcGhpY2FsIGV4cGxhbmF0aW9uIG9mIHRoZSBjZW50cmFsIGxpbWl0IHRoZW9yZW0gYW5kIHNob3dzIGl0cyBjb25zZXF1ZW5jZXMgZm9yIHF1YW50aXRhdGl2ZSBnZW5ldGljcy4KCgojIFNhbXBsaW5nClRha2UgYSBudW1iZXIgb2YgcmFuZG9tIG51bWJlcnMgZnJvbSB0aGUgdW5pZm9ybSBkaXN0cmlidXRpb24gYW5kIHN1bSB0aGVtIHVwLiBSZXBlYXQgdGhhdCBmb3IgYSBnaXZlbiBudW1iZXIgb2YgdGltZXMgYW5kIGxvb2sgYXQgdGhlIGRpc3RyaWJ1dGlvbiBvZiB0aGUgc3Vtcy4KCgojIEV4YW1wbGUKCmBgYHtyfQpuX25yX3JhbmRvbV9udW1iZXJzIDwtIDEwMApuX25yX3JlcGVhdCA8LSAxM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