We are going to be looking at data from the Spanish Flu. The Spanish Flu overlapped with the World War I, but caused more than twice as many deaths as the war itself. Below read in data from 1918 Switzerland deaths. After reading in the data, take a look at the dataframe to determine what data is present and how to call it.
flu <- read.csv(url("http://www.zoology.ubc.ca/~schluter/WhitlockSchluter/wp-content/data/chapter10/chap10e6AgesAtDeathSpanishFlu1918.csv"))
First, start by making a histogram of the age of death. from the data you just read in. What do you notice about this data? Does the histogram look normal? How would you describe the distribution (modality, skew). Plot a qqplot of the dats to confirm if you thought the data was normal or not.
Now with this data we are going to demonstrate the central limit theorem. Treat the age at death measurements from Switzerland in 1918 as the population. Using the code below, you will take a large number of random samples, each of size n, from the population of age at death measurements and plot the sample means.
n <- 4
results <- vector()
for(i in 1:10000){
AgeSample <- sample(flu$age, size = n, replace = FALSE)
results[i] <- mean(AgeSample)
}
Plot a histogram of the sample means (now as a variable called results). What do you notice about the distribution now? How would you describe it and do you think it is fairly normal or not? Change n to another number and rerun to see the effects of sample size on the shape of the distribution of sample means. What happens if you make n larger or smaller?
Compare the means between the population (the entire flu data) and the results from your simulation. Are they similar or different?
LS0tCnRpdGxlOiAiRGVtb25zdHJhdGlvbiBvZiB0aGUgQ2VudHJhbCBMaW1pdCBUaGVvcm9tIgpvdXRwdXQ6IGh0bWxfbm90ZWJvb2sKLS0tCgpXZSBhcmUgZ29pbmcgdG8gYmUgbG9va2luZyBhdCBkYXRhIGZyb20gdGhlIFNwYW5pc2ggRmx1LiBUaGUgU3BhbmlzaCBGbHUgb3ZlcmxhcHBlZCB3aXRoIHRoZSBXb3JsZCBXYXIgSSwgYnV0IGNhdXNlZCBtb3JlIHRoYW4gdHdpY2UgYXMgbWFueSBkZWF0aHMgYXMgdGhlIHdhciBpdHNlbGYuIEJlbG93IHJlYWQgaW4gZGF0YSBmcm9tIDE5MTggU3dpdHplcmxhbmQgZGVhdGhzLiBBZnRlciByZWFkaW5nIGluIHRoZSBkYXRhLCB0YWtlIGEgbG9vayBhdCB0aGUgZGF0YWZyYW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