Introduction to Scientific Programming and Simulation Using R 1st Edition Owen Jones pdf download
Introduction to Scientific Programming and Simulation Using R 1st Edition Owen Jones pdf download
https://ebookultra.com/download/introduction-to-scientific-
programming-and-simulation-using-r-1st-edition-owen-jones/
https://ebookultra.com/download/an-introduction-to-programming-using-
alice-2-2-2nd-edition-charles-w-herbert/
https://ebookultra.com/download/an-introduction-to-programming-using-
visual-basic-2008-with-visual-studio-expression-edition-dvd-schneider/
https://ebookultra.com/download/dean-dyer-introduction-to-
intellectual-property-law-1st-edition-owen-dean/
https://ebookultra.com/download/introduction-to-scientific-
reasoning-1st-edition-angela-m-potochnik/
Statistics 2nd Edition An Introduction Using R Michael J.
Crawley
https://ebookultra.com/download/statistics-2nd-edition-an-
introduction-using-r-michael-j-crawley/
https://ebookultra.com/download/an-introduction-to-sports-coaching-
robyn-l-jones/
https://ebookultra.com/download/introduction-to-linear-programming-
applications-and-extensions-first-edition-darst/
https://ebookultra.com/download/introduction-to-counselling-
skills-4th-edition-richard-nelson-jones/
Introduction to Scientific Programming and Simulation
Using R 1st Edition Owen Jones Digital Instant Download
Author(s): Owen Jones, Robert Maillardet, Andrew Robinson
ISBN(s): 9781420068726, 1420068725
Edition: 1
File Details: PDF, 7.64 MB
Year: 2009
Language: english
IntroductIon to
Scientific Programming
and Simulation using r
Scientific Programming
and Simulation using r
This book contains information obtained from authentic and highly regarded sources. Reasonable
efforts have been made to publish reliable data and information, but the author and publisher can-
not assume responsibility for the validity of all materials or the consequences of their use. The
authors and publishers have attempted to trace the copyright holders of all material reproduced
in this publication and apologize to copyright holders if permission to publish in this form has not
been obtained. If any copyright material has not been acknowledged please write and let us know so
we may rectify in any future reprint.
Except as permitted under U.S. Copyright Law, no part of this book may be reprinted, reproduced,
transmitted, or utilized in any form by any electronic, mechanical, or other means, now known or
hereafter invented, including photocopying, microfilming, and recording, or in any information
storage or retrieval system, without written permission from the publishers.
For permission to photocopy or use material electronically from this work, please access www.copy-
right.com (http://www.copyright.com/) or contact the Copyright Clearance Center, Inc. (CCC), 222
Rosewood Drive, Danvers, MA 01923, 978-750-8400. CCC is a not-for-profit organization that pro-
vides licenses and registration for a variety of users. For organizations that have been granted a
photocopy license by the CCC, a separate system of payment has been arranged.
Trademark Notice: Product or corporate names may be trademarks or registered trademarks, and
are used only for identification and explanation without intent to infringe.
Visit the Taylor & Francis Web site at
http://www.taylorandfrancis.com
and the CRC Press Web site at
http://www.crcpress.com
This book has two principal aims: to teach scientific programming and to
introduce stochastic modelling. Stochastic modelling in particular, and math-
ematical modelling in general, are intimately linked to scientific programming
because the numerical techniques of scientific programming enable the practi-
cal application of mathematical models to real-world problems. In the context
of stochastic modelling, simulation is the numerical technique that enables us
to analyse otherwise intractable models.
Simulation is also the best way we know of developing statistical intuition.
This book assumes that users have completed or are currently undertaking
a first year university level calculus course. The material is suitable for first
and second year science/engineering/commerce students and masters level stu-
dents in applied disciplines. No prior knowledge of programming or probability
is assumed.
It is possible to use the book for a first course on probability, with an empha-
sis on applications facilitated by simulation. Modern applied probability and
statistics are numerically intensive, and we give an approach that integrates
programming and probability right from the start.
We chose the programming language R because of its programming features.
We do not describe statistical techniques as implemented in R (though many
of them are admittedly quite remarkable), but rather show how to turn algo-
rithms into code. Our intended audience is those who want to make tools, not
just use them.
Complementing the book is a package, spuRs, containing most of the code
and data we use. Instructions for installing it are given in the first chapter. In
the back of the book we also provide an index of the programs developed in
the text and a glossary of R commands.
This book has grown out of the notes prepared for a first year course consist-
ing of 36 lectures, 12 one-hour tutorials, and 12 two-hour lab classes. However
it now contains more material than would fit in such a course, which permits
Core content The following chapters contain our core material for a course
on scientific programming and simulation.
Part II: Thinking about mathematics from a numerical point of view: applying
Part I concepts to root finding and numerical integration. Chapters 9–11.
Additional stochastic material The core outlined above only uses discrete
random variables, and for estimation only uses the concept of a sample average
converging to a mean. Chapters 16 and 17 add continuous random variables,
the Central Limit Theorem and confidence intervals. Chapters 18.3–18.5 and
20 then look at simulating continuous random variables and variance reduc-
tion. With some familiarity of continuous random variables the remaining case
studies, Chapter 21.3–21.4, become accessible.
Note that some of the projects in Chapter 22 use continuous random variables,
but can be easily modified to use discrete random variables instead.
Additional programming and numerical material For the core material ba-
sic plotting of output is sufficient, but for those wanting to produce more
professional graphics we provide Chapter 7. Chapter 8, on further program-
ming, acts as a bridge to more specialised texts, for those who wish to pursue
programming more deeply.
1: Setting up. Here we describe how to obtain and install R, and the package
spuRs which complements the book.
2: R as a calculating environment. This chapter shows you how to use R to
do arithmetic calculations; create and manipulate variables, vectors, and ma-
trices; work with logical expressions; call and get help on built-in R functions;
and to understand the workspace.
3: Basic programming. This chapter introduces a set of basic programming
structures that are the building blocks of many programs. Some structures are
common to numerous programming languages, for example if, for and while
statements. Others, such as vector-based programming, are more specialised,
but are arguably just as important for efficient R coding.
4: Input and output. This chapter describes some of the infrastructure that R
provides for importing data for subsequent analysis, and for displaying and
saving results of that analysis. More details on the construction of graphics
are available in Chapter 7, and we provide more information about importing
data in Chapter 6.
5: Programming with functions. This chapter extends Chapter 3 to include
user-defined functions. We cover the creation of functions, the rules that they
must follow, and how they relate to the environments from which they are
called. We also present some tips on the construction of efficient functions,
with especial reference to how they are treated in R.
6: Sophisticated data structures. In this chapter we study R’s more sophisti-
cated data structures—lists and dataframes—which simplify data representa-
tion, manipulation, and analysis. The dataframe is like a matrix but extended
to allow for different data modes in different columns, and the list is a general
data storage object that can house pretty much any other kind of R object.
We also introduce the factor, which is used to represent categorical objects.
7: Better graphics. This chapter provides a deeper exposition of the graphical
capabilities of R, building on Chapter 4. We explain the individual pieces that
make up the default plot. We discuss the graphics parameters that are used
to fine-tune individual graphs and multiple graphics on a page. We show how
to save graphical objects in various formats. Finally, we demonstrate some
graphical tools for the presentation of multivariate data (lattice graphs), and
3D-graphics.
8: Further programming. This chapter briefly mentions some more advanced
aspects of programming in R. We introduce the management of and interac-
tion with packages. We present details about how R arranges the objects that
we create within the workspace, and within functions that we are running.
We provide further suggestions for debugging your own functions. Finally, we
Bibliography/further reading
For those wishing to further their study of scientific programming and simu-
lation, here are some texts that the authors have found useful.
The R language
W.N. Venables and B.D. Ripley, S Programming. Springer, 2000.
W.N. Venables and B.D. Ripley, Modern Applied Statistics with S, Fourth
Edition. Springer, 2002.
J.M. Chambers and T.J. Hastie (Editors), Statistical Models in S.
Brooks/Cole, 1992.
J. Maindonald and J. Braun, Data Analysis and Graphics Using R: An
Example-Based Approach, Second Edition. Cambridge University Press, 2006.
Scientific programming/numerical techniques
W. Cheney and D. Kincaid, Numerical Mathematics And Computing, Sixth
Caveat computator
Thanks
Much of this book is based on a course given by the first two authors at the
University of Melbourne. The course was developed over many years, and we
owe much to previous lecturers for its fundamental structure, in particular
Steve Carnie and Chuck Miller. We are also indebted to our proof readers and
reviewers: Gad Abraham, Paul Blackwell, Steve Carnie, Alan Jones, David
Rolls, and especially Phil Spector. Olga Borovkova helped with some of the
coding, and we thank John Maindonald for drawing our attention to playwith.
We would like to acknowledge the dedication and the phenomenal achievement
Preface v
I Programming 1
1 Setting up 3
1.1 Installing R 3
1.2 Starting R 3
1.3 Working directory 4
1.4 Writing scripts 5
1.5 Help 5
1.6 Supporting material 5
2 R as a calculating environment 11
2.1 Arithmetic 11
2.2 Variables 12
2.3 Functions 13
2.4 Vectors 15
2.5 Missing data 18
2.6 Expressions and assignments 19
2.7 Logical expressions 20
2.8 Matrices 23
2.9 The workspace 25
2.10 Exercises 25
xiii
12 Optimisation 201
12.1 Newton’s method for optimisation 202
12.2 The golden-section method 204
12.3 Multivariate optimisation 207
12.4 Steepest ascent 209
12.5 Newton’s method in higher dimensions 213
12.6 Optimisation in R and the wider world 218
12.7 A curve fitting example 219
12.8 Exercises 220
13 Probability 227
13.1 The probability axioms 227
13.2 Conditional probability 230
13.3 Independence 232
13.4 The Law of Total Probability 233
13.5 Bayes’ theorem 234
13.6 Exercises 235
[23] Remarquons que Victor Hugo n’a pas dit autre chose dans sa
Réponse à un acte d’accusation, déjà citée par nous tout à l’heure, à
propos de «l’animal qui s’engraisse de glands»:
un mot
Était un duc et pair, ou n’était qu’un grimaud.
Mais la conclusion diffère: Delille s’incline et se soumet, Hugo
s’insurge:
Je mis un bonnet rouge au vieux dictionnaire.
Plus de mot sénateur! plus de mot roturier!
[25] «La gloire veut qu’on l’aide auprès des hommes; elle n’aime pas
les modestes.» (Edgar Quinet, La Révolution, t. II, p. 343, Librairie
internationale, 1869; in-18.)
[27] Voir, par exemple, ce que dit Cicéron dans Le Songe de Scipion,
livre VI, chap. XIV, XV et XVIII, sur la gloire humaine: «... Quelle gloire
digne de tes vœux peux-tu acquérir parmi les hommes? Tu vois quelles
rares et étroites contrées ils occupent sur le globe terrestre... Retranche
toutes les contrées où ta gloire ne pénétrera pas, et vois dans quelles
étroites limites», etc.
Et Salluste (Catilina, VIII): «De faire que les actions (et les œuvres)
soient connues, c’est le pur ouvrage du hasard (fortuna); c’est lui, c’est
son caprice qui nous dispense ou la gloire, ou l’oubli...»
Et Montesquieu (Pensées diverses: Œuvres complètes, t. II, p. 433;
Hachette, 1866): «A quoi bon faire des livres pour cette petite terre, qui
n’est guère plus grande qu’un point?»
Et Benjamin Constant (dans Sainte-Beuve, Portraits littéraires, t. III, p.
263, note 2): «... Le sentiment profond et constant de la brièveté de la
vie me fait tomber le livre ou la plume des mains, toutes les fois que
j’étudie. Nous n’avons pas plus de motifs pour acquérir de la gloire, pour
conquérir un empire ou pour faire un bon livre, que nous n’en avons
pour faire une promenade ou une partie de whist.»
Alfred de Vigny (Journal d’un poète, p. 183; Charpentier, 1882) a très
justement comparé le sort d’un livre à celui d’une bouteille jetée à la mer
avec cette inscription: «Attrape qui peut!»
«Ah! que le sage Huet (l’évêque d’Avranches) avait raison quand il
démontrait presque géométriquement quelle vanité et quelle
extravagance c’est de croire qu’il y a une réputation qui nous
appartienne après notre mort!» (Sainte-Beuve, Causeries du lundi, t. II, p.
164). «... Nous ressemblons tous à une suite de naufragés qui essaient
de se sauver les uns les autres, pour périr eux-mêmes l’instant d’après.»
(Id., Portraits littéraires, t. III, p. 128.) «... Un peu plus tôt, un peu plus
tard, nous y passerons tous. Chacun a la mesure de sa pleine eau. L’un
va jusqu’à Saint-Cloud, l’autre va jusqu’à Passy.» (Id., Nouvelle
Correspondance, p. 157.)
Sur l’aléa et l’inanité de la gloire littéraire, voir, dans le Mercure de
France de novembre 1900, un article abondamment documenté et des
plus judicieux de Remy de Gourmont.
[35] Aussi des poètes, voire de plus illustres, n’ont-ils pas hésité à faire
ange du féminin:
C’est une femme aussi, c’est une ange charmante.
(Alfred de Vigny, Éloa, Poésies complètes, p. 14; Charpentier,
1882.)
[44] Cette phrase comique a été souvent citée, mais parfois altérée et
amplifiée. Poitevin (La Grammaire, les Écrivains et les Typographes, p.
225) la donne ainsi: «Le pépin du mécontentement n’allait pas tarder à
pousser dans son cœur.» Hippolyte Babou (La Vérité sur le cas de M.
Champfleury, p. 31) ajoute tout un membre de phrase qui rend la
métaphore plus grotesque: «Le pépin du mécontentement devait
produire un arbre touffu sous lequel s’abriteraient les mauvaises
langues.»
[47] Berquin (1749-1791) commet, lui, une autre erreur, à propos des
rossignols: il en fait chanter deux ensemble et tout près l’un de l’autre,
ce qui n’a jamais lieu. «Deux rossignols allèrent se percher près de là,
sur le sommet d’un berceau de verdure, pour la réjouir (une jeune fille)
de leurs chansons de l’aurore.» (L’Ami des enfants, Clémentine et
Madelon, p. 28; Lehuby, s. d.)
1.D. The copyright laws of the place where you are located also
govern what you can do with this work. Copyright laws in most
countries are in a constant state of change. If you are outside
the United States, check the laws of your country in addition to
the terms of this agreement before downloading, copying,
displaying, performing, distributing or creating derivative works
based on this work or any other Project Gutenberg™ work. The
Foundation makes no representations concerning the copyright
status of any work in any country other than the United States.
1.E.6. You may convert to and distribute this work in any binary,
compressed, marked up, nonproprietary or proprietary form,
including any word processing or hypertext form. However, if
you provide access to or distribute copies of a Project
Gutenberg™ work in a format other than “Plain Vanilla ASCII” or
other format used in the official version posted on the official
Project Gutenberg™ website (www.gutenberg.org), you must,
at no additional cost, fee or expense to the user, provide a copy,
a means of exporting a copy, or a means of obtaining a copy
upon request, of the work in its original “Plain Vanilla ASCII” or
other form. Any alternate format must include the full Project
Gutenberg™ License as specified in paragraph 1.E.1.
• You pay a royalty fee of 20% of the gross profits you derive
from the use of Project Gutenberg™ works calculated using the
method you already use to calculate your applicable taxes. The
fee is owed to the owner of the Project Gutenberg™ trademark,
but he has agreed to donate royalties under this paragraph to
the Project Gutenberg Literary Archive Foundation. Royalty
payments must be paid within 60 days following each date on
which you prepare (or are legally required to prepare) your
periodic tax returns. Royalty payments should be clearly marked
as such and sent to the Project Gutenberg Literary Archive
Foundation at the address specified in Section 4, “Information
about donations to the Project Gutenberg Literary Archive
Foundation.”
• You comply with all other terms of this agreement for free
distribution of Project Gutenberg™ works.
1.F.
Most people start at our website which has the main PG search
facility: www.gutenberg.org.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookultra.com