DynamicModelsLabsInR

DynamicModelsLabsInR - CONTENTS 1 An introduction to R for...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
CONTENTS 1 An introduction to R for dynamic models in biology Last compile: February 8, 2008 Stephen P. Ellner 1 and John Guckenheimer 2 1 Department of Ecology and Evolutionary Biology, and 2 Department of Mathematics Cornell University, Ithaca NY 14853 Contents 1 Interactive calculations 4 2 An interactive session: fitting a linear regression model 6 3 Script files and data files 8 4 Vectors 11 5 Matrices 14 5.1 cbind and rbind . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15 5.2 Matrix addressing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16 5.3 Matrix operations and matrix-vector multiplication . . . . . . . . . . . . . . . . . . . . . . 16 6 Iteration (“Looping”) 17 6.1 For-loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17 6.2 While-loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 7 Branching 21 8 Numerical Matrix Algebra 22 8.1 Eigenvalues and eigenvectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23 8.2 Eigenvalue sensitivities and elasticities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24 8.3 Finding the eigenvalue with largest real part . . . . . . . . . . . . . . . . . . . . . . . . . . 25 9 Creating new functions 26 10 A simulation project 27 11 Coin tossing and Markov Chains 28 11.1 Markov chains and residence times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
CONTENTS 2 12 The Hodgkin-Huxley model 32 12.1 Getting started . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34 13 Solving systems of differential equations 36 13.1 Always use lsoda! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 13.2 The logs trick . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39 14 Equilibrium points and linearization 40 15 Phase-plane analysis and the Morris-Lecar model 42 16 Simulating Discrete-Event Models 45 17 Simulating dynamics in systems with spatial patterns 47 17.1 General method of lines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49 18 References 49 Preface These notes for computer labs accompany our textbook Dynamic Models in Biology (Princeton Univer- sity Press 2006), but they can also be used as a “standalone” introduction to R as a scripting language for simulating dynamic models of biological systems. They are based in part on course materials by former TAs Colleen Webb, Jonathan Rowell and Daniel Fink at Cornell University, Lou Gross (University of Tennessee) and Paul Fackler (NC State University), and on the book Getting Started with Matlab by Rudra Pratap (Oxford University Press). We also have drawn on the documentation supplied with R (R Development Core Team 2005). The current home for these notes is www.cam.cornell.edu/ dmb/DMBsupplements.html , a web page for the textbook that we maintain ourselves. If that fails, an up-to-date link should be in the book’s listing at the publisher ( www.pupress.princeton.edu ). Parallel notes and script files for Matlab are also available at those sites. Sections 1-7 are a general introduction to some basics of R programming. We generally cover those in two or three 2-hour lab sessions, depending on how much previous experience students have had. Rather than lecturing, we have students work through them individually, asking for help as needed and having us or a TA check their exercise solutions. Those sections contain many sample calculations. It is important to do them yourselves – type them in at your keyboard and see what happens on your screen to get the feel of working in R . All exercises in the middle of a section should be done immediately when you get to them, and make sure that you have them right before moving on. Exercises at the ends of sections may be more appropriate as homework exercises. However the exercises are all straightforward applications of the programming techniques being taught.
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern