From mboxrd@z Thu Jan 1 00:00:00 1970 From: Stephen Eglen Subject: updating drift.org on Worg Date: Thu, 28 Jul 2011 12:28:40 +0100 Message-ID: <29449.1311852520@maps> Return-path: Received: from eggs.gnu.org ([140.186.70.92]:36288) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmOlg-0005dm-0h for emacs-orgmode@gnu.org; Thu, 28 Jul 2011 07:28:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1QmOle-0002Z5-B9 for emacs-orgmode@gnu.org; Thu, 28 Jul 2011 07:28:43 -0400 Received: from ppsw-41.csi.cam.ac.uk ([131.111.8.141]:54191) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1QmOle-0002Yz-2Q for emacs-orgmode@gnu.org; Thu, 28 Jul 2011 07:28:42 -0400 List-Id: "General discussions about Org-mode." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org Sender: emacs-orgmode-bounces+geo-emacs-orgmode=m.gmane.org@gnu.org To: emacs-orgmode@gnu.org Cc: Stephen Eglen , dandavison7@gmail.com I've had an attempt at updating drift.org on Worg (currently in Worg/FIXME) so that it compiles in today's org mode. Can some kind soul check if this patch works? I've put brief comments at the end as to what I've changed, and note also for some reason the strange rendering of p[1] <- X1/N in the .tex file as: p\footnotemark[1] <- X1/N Is that a bug? (I've also just emailed Matt for write access to Worg.) Thanks, Stephen diff --git a/FIXME/drift.org b/FIXME/drift.org index 7d4b921..88fbf3e 100644 --- a/FIXME/drift.org +++ b/FIXME/drift.org @@ -1,4 +1,5 @@ #+title: Genetic drift +#+author: Dan Davison #+seq_todo: TODO | DONE #+property: cache no @@ -9,15 +10,13 @@ are two genetic types: red and blue[fn:1]. Here is the initial generation of the population (N=10). -#+begin_src ditaa :file drift-1-gen.png :cmdline -r :exports both +#+begin_src ditaa :file drift-1-gen.png :cmdline -r :exports results /----+ /----+ /----+ /----+ /----+ /----+ /----+ /----+ /----+ /----+ Generation 1 |cRED| |cBLU| |cBLU| |cBLU| |cRED| |cRED| |cBLU| |cRED| |cRED| |cRED| | | | | | | | | | | | | | | | | | | | | +----/ +----/ +----/ +----/ +----/ +----/ +----/ +----/ +----/ +----/ #+end_src -#+results: -[[file:../../../images/babel/drift-1-gen.png]] There is no mutation, no selection and no sex; the next generation is made up by randomly choosing 10 individuals from the previous generation[fn:2]. A single individual can be chosen more than once, @@ -29,7 +28,7 @@ So the first two generations might look like this. -#+begin_src ditaa :file drift-2-gen.png :cmdline -r :exports both +#+begin_src ditaa :file drift-2-gen.png :cmdline -r :exports results /----+ /----+ /----+ /----+ /----+ /----+ /----+ /----+ /----+ /----+ Generation 1 |cRED| |cBLU| |cBLU| |cBLU| |cRED| |cRED| |cBLU| |cRED| |cRED| |cRED| | | | | | | | | | | | | | | | | | | | | @@ -40,10 +39,6 @@ +----/ +----/ +----/ +----/ +----/ +----/ +----/ +----/ +----/ +----/ #+end_src -#+results: -[[file:../../../images/babel/drift-2-gen.png]] - - This is a form of evolution called "genetic drift". It is inevitable, although if the population is very large it will have less effect. @@ -55,22 +50,19 @@ success probability 0.6. In general, the random process is described by the following transition probabilities. -#+begin_src latex :file transprob.png +#+begin_src latex :file transprob.png :exports results \begin{equation} \Pr(X_t=j|X_{t-1}=i) = \frac{j(j-1)}{2}\Big(\frac{i}{N}\Big)^j\Big(\frac{N-i}{N}\Big)^{n-j} \end{equation} #+end_src -#+results: -[[file:../../../images/babel/transprob.png]] - We can simulate the evolution over many generations in R. This code simulates the change in frequency in a single population over 100 generations. We'll make the population larger (N=1000) but still start off with 60% red individuals. #+source: simpledrift(N=1000, X1=600, ngens=100) -#+begin_src R :file simpledrift.png :exports code +#+begin_src R :file simpledrift.png :exports both :results graphics p <- numeric(ngens) p[1] <- X1/N for(g in 2:ngens) @@ -78,9 +70,6 @@ plot(p, type="l", ylim=c(0,1), xlab="Generation", ylab="Proportion red") #+end_src -#+results[03beb832ebe2136388baae04b9f9e699af5d0426]: simpledrift -[[file:../../../images/babel/simpledrift.png]] - But how variable is this process? To answer this we need to repeat the simulation many times (i.e. simulate many identical but independent populations). We could do that as follows @@ -115,40 +104,32 @@ To run the simulation: #+source: drift(N=1000, X1=600, nreps=10, ngens=100) -#+begin_src R :session t :file repdrift.png :exports code +#+begin_src R :session t :file repdrift.png :exports both :results graphics p <- drift.faster(N, X1, ngens, nreps) matplot(p, type="l", ylim=c(0,1), lty=1) #+end_src -#+results[685ae7b4150a9413db180d2917384052ec288ab5]: drift -[[file:../../../images/babel/repdrift.png]] And let's quickly see how much of a speed difference the vectorisation makes. #+source: compare-times(N=1000, X1=600, nreps=1000, ngens=100) -#+begin_src R :session t :colnames t :results output +#+begin_src R :session t :colnames t :results output :exports both functions <- c(drift.slow=drift.slow, drift.faster=drift.faster) times <- sapply(functions, function(f) as.numeric(system.time(f(N, X1, ngens, nreps))[1])) print(times) cat(sprintf("\nFactor speed-up = %.1f\n", times[1] / times[2])) #+end_src -#+results[ba4b29e0bf6cc6da506361b76253285f7eab31a9]: compare-times - : drift.slow drift.faster - : 6.064 0.204 - : - : Factor speed-up = 29.7 - * Footnotes - [fn:1] Every individual is chacterised by a single type; no sex, - recombination, mutation, selection, etc. +[fn:1] Every individual is chacterised by a single type; no sex, +recombination, mutation, selection, etc. - [fn:2] All members of the previous generation die as the next - generation is formed. +[fn:2] All members of the previous generation die as the next +generation is formed. - [fn:3] Note that we can't vectorise the entire simulation because - drift is a Markov process. +[fn:3] Note that we can't vectorise the entire simulation because +drift is a Markov process. * Config :noexport: #+options: author:nil date:nil num:nil toc:nil @@ -164,3 +145,11 @@ *** TODO How do we put titles on figures? *** TODO Connect daughters to parents with lines +*** Stephen's changes 2011-07-28 + +- :results graphics needed in places. +- footnotes were causing problems, seemingly because they were + indented; deleting the indentation solved the problem. + +- note the problem when showing following line of code in the pdf: + p[1] <- X1/N (at bottom of page 1); there is a \footnotemark added.