<TeXmacs|1.0.3>

<style|generic>

<\body>
  <\make-title>
    <title|Excercise 2>
  </make-title>

  Help: you can write a series of R commands into a file, and then execute
  them all in a row by doing

  <with|prog-language|r|prog-session|default|<\session>
    <\input|<with|color|red|\<gtr\> <with|color|black|>>>
      source("filename")
    </input>
  </session>>

  \;

  1a. By simulating 10000 times flipping a coin 10 times, make a table of the
  probability to have heads show up 0 times, 1 time, twice, and so on.

  \;

  1b. If someone flipped a coin, and got 1 head, and 9 tails, we would like
  to test the hypothesis that the coin is unbiased. We will do this by
  calculating the probability that an unbiased coin flipped 10 times gives 0
  or 1 heads, or 0 or 1 tails. Calculate this probability.

  \;

  1c. How many heads/tails out of 10 would cause one to reject the hypothesis
  that the coin is unbiased at the 5% level? That means, how many heads/tails
  give a probability that is lower than 5% as calculated above.

  \;

  1d. With the command <verbatim|sample(0:1, 10, prob=c(0.3,0.7))> \ you can
  simulate a coin flip of a biased coin. Out of 1000 coin flips of length 10
  that are biased as above, how many come up significant at the 5% level?
  I.e. how often do you get as low a number as you calculated in 1c or worse?
  How many come up significant for an unbiased coin? How about
  <verbatim|c(0.1,0.9)> ?

  \;

  2. If the sex ratio at birth is 50%, but people adopt the following
  strategy: have children until you have one son, and then stop, unless you
  have 12 daughters (in which case you stop, too). What would be the average
  sex ratio in the population? (Calculate by simulation!)

  \;

  3a. As we did in Wednesday's exercise, start with a population of 100
  individuals. We will assume that they all have different alleles, so that
  their alleles are 1:100. Resample from the population 300 times - how many
  alleles are still present from the original population?

  3b. Now represent the population as a matrix, so that the rows are
  individuals, and the columns are loci \ (i.e. individuals are haploids).
  create a new population by chosing a mother and a father for each
  individual, and then chosing the alleles randomly from the father and the
  mother for each locus. Start with a population of 20 individuals with a
  genome length of 100. Alleles from how many individuals are present after
  300 generations?

  \;

  4. Read the data from the file <verbatim|speeding.csv>. Calculate the mean
  speed. How many individuals where caught speeding before? Calculate the
  mean speed for those that were caught, and for those that were not.

  \;
</body>

<\initial>
  <\collection>
    <associate|page-even|1in>
    <associate|page-reduce-bot|0.3in>
    <associate|page-reduce-right|0.7in>
    <associate|page-reduce-left|0.7in>
    <associate|page-type|letter>
    <associate|page-top|1in>
    <associate|page-right|1in>
    <associate|par-width|6.5in>
    <associate|page-odd|1in>
    <associate|page-bot|1in>
    <associate|language|english>
    <associate|page-reduce-top|0.3in>
  </collection>
</initial>
