//img.uscri.be/pth/7e3c989a6fedb81a8dcad96ff98bb24ae0c768d7
La lecture en ligne est gratuite
Le téléchargement nécessite un accès à la bibliothèque YouScribe
Tout savoir sur nos offres
Télécharger Lire

Arts du spectacle

De
134 pages
  • cours magistral
Arts du spectacle Pour l'égal accès des femmes et des hommes aux postes de responsabilité, aux lieux de décision, aux moyens de production, aux réseaux de diffusion, à la visibilité médiatique. 2 De l'interdit à l'empêchement mai 2009 Reine Prat agrégée de lettres chargée de mission pour l'égalité h/f dans les arts du spectacle Mcc – Dmdts 3, rue de Valois 75033 Paris cedex 01 01 40 15 38 13 reine.
  • valider de nouvelles conventions
  • charte-egalite
  • egalite-entre-hommes-femmes
  • quant aux représentations mentales
  • femmes
  • jeunes femmes manifestement supérieures
  • aux
Voir plus Voir moins

l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
l
Introduction to the R Project for Statistical Computing
for use at ITC
D G Rossiter
International Institute for Geo information Science & Earth Observation
Enschede (NL)
http://www.itc.nl/personal/rossiter
November 20, 2010
Actual vs. modelled straw yields
4 5 6 7 8 9 1 3 5 7 9 11 13 15 17 19 21 23 25
Modelled Column number
Frequency histogram, Meuse lead concentration
53
GLS 2nd−order trend surface, subsoil clay %
26
17 17 17
12
4 3 3
1 1 10 0
0 100 200 300 400 500 600 700
660000 670000 680000 690000 700000
lead concentration, mg kg−1
ECounts shown above bar, actual values shown with rug plot
Frequency Actual
0 10 20 30 40 50 60 4 5 6 7 8 9
N
Grain yield, lbs per plot
315000 320000 325000 330000 335000 340000
3.0 3.5 4.0 4.5 5.0Contents
1 What is R? 1
2 Why R for ITC? 2
2.1 Advantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.2 Disadvantages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.3 Alternatives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3.1 S PLUS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3.2 Statistical packages . . . . . . . . . . . . . . . . . . . . . . 5
2.3.3 Special purpose statistical programs . . . . . . . . . . . 5
2.3.4 Spreadsheets . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.3.5 Applied mathematics programs . . . . . . . . . . . . . . 6
3 Using R for Windows 6
3.1 R on the ITC network . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Starting R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.3 Stopping R . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.4 Setting up a workspace . . . . . . . . . . . . . . . . . . . . . . . . 7
3.5 The command prompt . . . . . . . . . . . . . . . . . . . . . . . . 8
3.6 On line help in R . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.7 Internet help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.8 Saving your analysis steps . . . . . . . . . . . . . . . . . . . . . . 10
3.9 your graphs . . . . . . . . . . . . . . . . . . . . . . . . . . 10
3.10Writing and running scripts . . . . . . . . . . . . . . . . . . . . . 11
3.11The Tinn R code editor . . . . . . . . . . . . . . . . . . . . . . . 12
3.12Using the Rcmdr GUI . . . . . . . . . . . . . . . . . . . . . . . . . 12
3.13Loading optional packages . . . . . . . . . . . . . . . . . . . . . . 13
3.14Sample datasets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4 The S language 16
4.1 Command line calculator and mathematical operators . . . . 16
4.2 Creating new objects: the assignment operator . . . . . . . . . 17
4.3 Methods and their arguments . . . . . . . . . . . . . . . . . . . . 18
4.4 Vectorized operations and re cycling . . . . . . . . . . . . . . . 19
4.5 Vector and list data structures . . . . . . . . . . . . . . . . . . . 21
4.6 Arrays and matrices . . . . . . . . . . . . . . . . . . . . . . . . . . 22
4.7 Data frames . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
4.8 Factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.9 Selecting subsets . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.9.1 Simultaneous operations on subsets . . . . . . . . . . . 35
4.10Rearranging data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.11Random numbers and simulation . . . . . . . . . . . . . . . . . 37
4.12Character strings . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Revision 3.8 Copyright © D G Rossiter 2003 – 2010. All rights reserved.
Non commercial reproduction and dissemination of the work as a whole
freely permitted if this original copyright notice is included. To adapt or
translate please contact the author.
ii4.13Objects and classes . . . . . . . . . . . . . . . . . . . . . . . . . . 39
4.13.1The S3 and S4 class systems . . . . . . . . . . . . . . . . 41
4.14Descriptive statistics . . . . . . . . . . . . . . . . . . . . . . . . . 44
4.15Classification tables . . . . . . . . . . . . . . . . . . . . . . . . . . 45
4.16Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
4.17Statistical models in S . . . . . . . . . . . . . . . . . . . . . . . . . 47
4.17.1Models with categorical predictors . . . . . . . . . . . . 51
4.17.2Analysis of Variance (ANOVA) . . . . . . . . . . . . . . . 52
4.18Model output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
4.18.1Model diagnostics . . . . . . . . . . . . . . . . . . . . . . . 54
4.18.2Model based prediction . . . . . . . . . . . . . . . . . . . 56
4.19Advanced statistical modelling . . . . . . . . . . . . . . . . . . . 57
4.20Missing values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
4.21Control structures and looping . . . . . . . . . . . . . . . . . . . 59
4.22User defined functions . . . . . . . . . . . . . . . . . . . . . . . . 60
4.23Computing on the language . . . . . . . . . . . . . . . . . . . . . 62
5 R graphics 64
5.1 Base graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
5.1.1 Mathematical notation in base graphics . . . . . . . . . 68
5.1.2 Returning results from graphics methods . . . . . . . . 70
5.1.3 Types of base graphics plots . . . . . . . . . . . . . . . . 70
5.1.4 Interacting with base graphics plots . . . . . . . . . . . . 72
5.2 Trellis graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
5.2.1 Univariate plots . . . . . . . . . . . . . . . . . . . . . . . . 72
5.2.2 Bivariate plots . . . . . . . . . . . . . . . . . . . . . . . . . 73
5.2.3 Triivariate plots . . . . . . . . . . . . . . . . . . . . . . . . 74
5.2.4 Panel functions. . . . . . . . . . . . . . . . . . . . . . . . . 76
5.2.5 Types of Trellis graphics plots . . . . . . . . . . . . . . . 77
5.2.6 Adjusting graphics parameters . . . . . . . . . . 77
5.3 Multiple graphics windows. . . . . . . . . . . . . . . . . . . . . . 79
5.3.1 Switching between windows . . . . . . . . . . . . . . . . . 80
5.4 Multiple graphs in the same window . . . . . . . . . . . . . . . 80
5.4.1 Base graphics . . . . . . . . . . . . . . . . . . . . . . . . . . 80
5.4.2 Trellis. . . . . . . . . . . . . . . . . . . . . . . . . 81
5.5 Colours . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6 Preparing your own data for R 85
6.1 Preparing data directly in R . . . . . . . . . . . . . . . . . . . . . 85
6.2 A GUI data editor . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
6.3 Importing data from a CSV file . . . . . . . . . . . . . . . . . . . 87
6.4 images . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7 Exporting from R 92
8 Reproducible data analysis 94
8.1 The NoWeb document . . . . . . . . . . . . . . . . . . . . . . . . 94
A8.2 The LTX . . . . . . . . . . . . . . . . . . . . . . . . . . 95E
8.3 The PDF document . . . . . . . . . . . . . . . . . . . . . . . . . . 96
iii8.4 Graphics in Sweave . . . . . . . . . . . . . . . . . . . . . . . . . . 96
9 Miscellaneous R tricks 97
9.1 Setting up a regular grid . . . . . . . . . . . . . . . . . . . . . . . 97
9.2 up a random sampling scheme . . . . . . . . . . . . . . 97
10Learning R 99
10.1R tutorials and introductions . . . . . . . . . . . . . . . . . . . . 99
10.2Textbooks using R . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
10.3Technical notes using R . . . . . . . . . . . . . . . . . . . . . . . 101
10.4Web Pages to learn R . . . . . . . . . . . . . . . . . . . . . . . . . 101
10.5Keeping up with developments in R . . . . . . . . . . . . . . . . 102
11Frequently asked questions 105
11.1Help! I got an error, what did I do wrong? . . . . . . . . . . . . 105
11.2Why didn’t my command(s) do what I expected? . . . . . . . . 107
11.3How do I find the method to do what I want? . . . . . . . . . . 108
11.4Memory problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
11.5What version of R am I running? . . . . . . . . . . . . . . . . . . 111
11.6What statistical procedure should I use? . . . . . . . . . . . . . 112
A Obtaining your own copy of R 113
A.1 Installing new packages . . . . . . . . . . . . . . . . . . . . . . . 115
A.2 Customizing your installation . . . . . . . . . . . . . . . . . . . . 115
A.3 R in different human languages . . . . . . . . . . . . . . . . . . . 116
B An example script 117
C An example function 120
References 122
Index of R concepts 126
List of Figures
1 The Tinn R screen . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2 The R Commander screen . . . . . . . . . . . . . . . . . . . . . . 14
3 Regression diagnostic plots . . . . . . . . . . . . . . . . . . . . . 55
4 Finding the closest point . . . . . . . . . . . . . . . . . . . . . . . 61
5 Default scatterplot . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
6 Plotting symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
7 Custom scatterplot . . . . . . . . . . . . . . . . . . . . . . . . . . 68
8 Scatterplot with math symbols, legend and model lines . . . . 69
9 Some interesting base graphics plots . . . . . . . . . . . . . . . 71
10 Trellis density plots . . . . . . . . . . . . . . . . . . . . . . . . . . 73
11 scatter plots . . . . . . . . . . . . . . . . . . . . . . . . . . 74
12 Trellis trivariate plots . . . . . . . . . . . . . . . . . . . . . . . . . 75
13 scatter plot with some added elements . . . . . . . . . 77
14 Example of a colour ramp . . . . . . . . . . . . . . . . . . . . . . 84
15 R graphical data editor . . . . . . . . . . . . . . . . . . . . . . . . 87
ivA16 Example PDF produced by Sweave and LTX . . . . . . . . . . . 96E
17 Two sampling schemes . . . . . . . . . . . . . . . . . . . . . . . . 98
18 Results of an RSeek search . . . . . . . . . . . . . . . . . . . . . . 102
19 of an R site search . . . . . . . . . . . . . . . . . . . . . . 104
20 Visualising the variability of small random samples . . . . . . 119
v1 What is R?
R is an open source environment for statistical computing and visualisa
tion. It is based on the S language developed at Bell Laboratories in the
1980’s [20], and is the product of an active movement among statisti
cians for a powerful, programmable, portable, and open computing en
vironment, applicable to the most complex and sophsticated problems, as
well as “routine” analysis, without any restrictions on access or use. Here
1is a description from the R Project home page:
“R is an integrated suite of software facilities for data manip
ulation, calculation and graphical display. It includes:
• an effective data handling and storage facility,
• a suite of operators for calculations on arrays, in partic
ular matrices,
• alarge,coherent,integratedcollectionofintermediatetools
for data analysis,
• graphicalfacilitiesfordataanalysisanddisplayeitheron
screen or on hardcopy, and
• a well developed, simple and effective programming lan
guage which includes conditionals, loops, user defined re
cursive functions and input and output facilities.”
The last point has resulted in another major feature:
• Practisingstatisticianshaveimplementedhundredsofspe
cialised statistical produres for a wide variety of appli
cations as contributed packages, which are also freely
available and which integrate directly into R.
A few examples especially relevant to ITC are:
• the gstat, geoR and spatial packages for geostatistical analysis,
contributed by Pebesma [32], Ribeiro, Jr. & Diggle [38] and Ripley
[39], respectively;
• the spatstat package for spatial point pattern analysis and simula
tion;
• the vegan package of ordination methods for ecology;
• the circular package for directional statistics;
1http://www.r project.org/
1• the sp package for a programming interface to spatial data;
• thergdalpackageforGDAL standarddataaccesstogeographicdata
sources;
There are also packages for the most modern statistical techniques such
as:
• sophisticated modelling methods, including generalized linear mod
els,principalcomponents,factoranalysis,bootstrapping,androbust
regression; these are listed in §4.19;
• wavelets (wavelet);
• neural networks (nnet);
• non linear mixed effects models ( nlme);
• recursive partitioning (rpart);
• splines (splines)
2 Why R for ITC?
ITC is an international institution of post graduate education located in
Enschede, the Netherlands, with a thematic focus on geo information sci
2ence and earth observation in support of development. Its mission is
described as follows:
“ITCaimsatcapacitybuildingandinstitutionaldevelopmentof
professionalandacademicorganizationsandindividualsspecif
ically in countries that are economically and/or technologically
less developed.”
ThusthetwopillarsonwhichITCstandsaredevelopment related andgeo
information. R supports both of these.
2.1 Advantages
R has several major advantages for a typical ITC student or collaborator:
1. It is completely free and will always be so, since it is issued under
3the GNU Public License;
2. It isfreely available over the internet , via a large network of mirror
servers; see Appendix A for how to obtain R;
2http://www.itc.nl/about_itc/mission_statement.asp
3http://www.gnu.org/copyleft/gpl.html
2©3. It runs on almost all operating systems: Unix and derivatives in
cluding Darwin, Mac OS X, Linux, FreeBSD, and Solaris; most flavours
of Microsoft Windows; Apple Macintosh OS; and even some main
frame OS.
4. It is the product of international collaboration between top compu
tational statisticians and computer language designers;
5. Itallowsstatisticalanalysisandvisualisationofunlimitedsophisti
cation; youarenotrestrictedtoasmallsetofproceduresoroptions,
and because of the contributed packages, you are not limited to one
method of accomplishing a given computation or graphical presen
tation;
6. It can work onobjectsofunlimitedsizeandcomplexity with a con
sistent, logical expression language;
7. Itissupportedbycomprehensivetechnicaldocumentationanduser
contributed tutorials (§10). There are also several good textbooks on
statistical methods that use R (or S) for illustration.
8. Every computational step is recorded, and this history can be saved
for later use or documentation.
9. It stimulates critical thinking about problem solving rather than a
“push the button” mentality.
10. It is fully programmable, with its own sophisticated computer lan
guage (§4). Repetitive procedures can easily be automated by user
written scripts (§3.10). It is easy to write your own functions (§B),
and not too difficult to write wholepackages if you invent some new
analysis;
11. Allsourcecodeispublished, soyoucanseetheexactalgorithmsbe
ing used; also, expert statisticians can make sure the code is correct;
12. It can exchange data in MS Excel, text, fixed and delineated formats
(e.g. CSV), so that existing datasets are easily imported (§6), and re
sults computed in R are easily exported (§7).
13. Most programs written for the commercial S PLUS program will run
unchanged, or with minor changes, in R (§2.3.1).
2.2 Disadvantages
Rhasitsdisadvantages(although“everydisadvantagehasitsadvantage”):
1. The default Windows and Mac OS X graphical user interface (GUI) is
limited to simple system interaction and does not include statistical
3procedures. The user must type commands to enter data, do analy
ses, and plot graphs. This has the advantage that you have complete
control over the system. TheRcmdr add on package (§ 3.12) provides
a reasonable GUI for common tasks.
2. The user must decide on the analysis sequence and execute it step
by step . However, it is easy to create scripts with all the steps in an
analysis,andrunthescriptfromthecommandlineormenus(§3.10);
scripts can be preared in code editors built into GUI versions of R or
separate front ends such as Tinn R (§ 3.10). A major advantage of
this approach is that intermediate results can be reviewed.
3. The user must learn a new way of thinking about data, as data
frames(§4.7)andobjectseachwithitsclass, whichinturnsupports
a set of methods (§4.13). This has the advantage common to object
oriented languages that you can only operate on an object according
4to methods that make sense and methods can adapt to the type of
5object.
4. The user must learn the S language (§4), both for commands and
the notation used to specify statistical models (§4.17). The S statis
tical modelling language is a lingua franca among statisticians, and
provides a compact way to express models.
2.3 Alternatives
Therearemanywaystodocomputationalstatistics;thissectiondiscusses
them in relation to R. None of these programs are open source, meaning
that you must trust the company to do the computations correctly.
2.3.1 S PLUS
6S PLUSisacommercialprogramdistributedbytheInsightfulcorporation,
and is a popular choice for large scale commerical statistical computing.
Like R, it is a dialect of the original S language developed at Bell Laborato
7ries. S PLUS has a full graphical user interface (GUI); it may be also used
like R, by typing commands at the console or by running scripts. It has
a rich interactive graphics environment called Trellis, which has been em
ulated with the lattice package in R (§5.2). S PLUS is licensed by local
distributors in each country at prices ranging from moderate to high, de
pending factors such as type of licensee and application, and how many
4For example, the t (transpose) method only can be applied to matrices
5For the summary and plot methods give different results depending on the
class of object.
6http://www.insightful.com/
7TherearedifferencesinthelanguagedefinitionsofS,R,andS PLUSthatareimportant
to programmers, but rarely to end users. There are also differences in how some
algorithms are implemented, so the numerical results of an identical method may be
somewhat different.
4computers it will run on. The important point for ITC R users is that their
expertise will be immediately applicable if they later use S PLUS in a com
mercial setting.
2.3.2 Statistical packages
There are many statistical packages, including MINITAB, SPSS, Statistica,
8Systat,GenStat,andBMDP, whichareattractiveifyouarealreadyfamiliar
with them or if you are required to use them at your workplace. Although
theseareprogrammabletovaryingdegrees,itisnotintendedthatspecial
ists develop completely new algorithms. These must be purchased from
local distributors in each country, and the purchaser must agree to the li
cense terms. These often have common analyses built in as menu choices;
these can be convenient but it is tempting to use them without fully un
derstanding what choices they are making for you.
SAS is a commercial competitor to S PLUS, and is used widely in industry.
It is fully programmable with a language descended from PL/I (used on
IBM mainframe computers).
2.3.3 Special purpose statistical programs
Someprogramsadressspecificstatisticalissues,e.g.geostatisticalanalysis
and interpolation (SURFER, gslib, GEO EAS), ecological analysis (FRAG
STATS),andordination(CONOCO).Thealgorithmsintheseprogramshave
or can be programmed as an R package; examples are the gstat program
9for geostatistical analysis [34], which is now available within R [32], and
the vegan package for ecological statistics.
2.3.4 Spreadsheets
Microsoft Excel is useful for data manipulation. It can also calculate some
statistics (means, variances, ...) directly in the spreadsheet. This is also
anadd onmodule(menuitemT ools|DataAnalysis...) forsomecommon
statisticalproceduresincludingrandomnumbergeneration. Beawarethat
Excel was not designed by statisticians. There are also some commer
cial add on packages for Excel that provide more sophisticated statistical
analyses. Excel’s default graphics are easy to produce, and they may be
customized via dialog boxes, but their design has been widely criticized.
Least squares fits on scatterplots give no regression diagnostics, so this is
not a serious linear modelling tool.
10OpenOffice includes an open source and free spreadsheet (Open Office
Calc) which can replace Excel.
8See the list at http://www.stata.com/links/stat_software.html
9http://www.gstat.org/
10http://www.openoffice.org/
5