Using the built-in `iris`

dataset:

- write a for() loop to test whether each numeric column in the
`iris`

dataset is normally distributed using the`shapiro.test()`

function, and print out the p-value from this test*you must write a for loop to get credit for this question* - make a histogram of each
`iris`

numeric variable - calculate the mean and median of the squared value of
`iris$Sepal.Length`

(calculated like this:`iris$Sepal.Length^2`

). - explain in words why these mean and median values are different.

One very common problem in bio-statistics is that many characters are not quite normally distributed. To understand how that arises, try the following steps:

Generate a vector called

`body.sizes`

for 1000 individuals sampled from a normal distribution with mean = 10 grams and sd = 3 grams. Save a copy of this in a variable called`body.sizes.original`

so we can always go back and look at the original.Simulate body growth assuming that each individual grows by some percentage each year (\(t\)) so that \(size(t+1) = g*size(t)\). A reasonable value of \(g\) might be 1.15 (15% growth per year). Write a loop representing 10 years of growth, in which you update the vector

`body.sizes`

by multiplying it by the annual growth rate each year for 10 years. Save the result to a new variable called`body.sizes.growth`

.Next, model inter-individual variation in growth rates. Create a vector of growth rates for the 1000 individuals, with mean 1.15 and standard deviation of 0.2. Reset

`body.sizes`

to its original values. Again simulate 10 years of growth this time applying each individual’s specific growth rate.an individual’s growth rate stays the same from year to year, but each individual should have a different growth rate. Save the results to a new variable called*Note:*`body.sizes.vargrowth`

.Finally, see what happens when environmental stochasticity is added in. Reset

`body.sizes`

to its original values. Repeat the variable growth scenario, this time adding in yearly fluctuations to the scenario. For each year multiply ALL individuals by single scaling factor representing the productivity that particular year. Have that scaling factor be drawn from a normal distribution with mean 1 and standard deviation of 0.2. Save the results to`body.sizes.environmentalgrowth`

.Do a Shapiro-Wilk test for normality on all four distributions. Which ones are normal, which aren’t? Produce Q-Q plots of all four. Verbally describe the deviations from normality.

To conclude, answer the following questions:

- Does growth of a normally-distributed population lead to non-normal distributions?
- Does variation in growth cause non-normality?
- Does environmental stochasticity reduce or amplify body size variation?