-
Notifications
You must be signed in to change notification settings - Fork 12
/
RcourseBerry.Rnw
7383 lines (6427 loc) · 278 KB
/
RcourseBerry.Rnw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\documentclass[xcolor=table, handout , xcolor=dvipsnames]{beamer} % , handout, draft
\usetheme{Madrid} % Madrid, Warsaw, Berlin
\usecolortheme{beaver}
\usepackage[latin1]{inputenc} % windows
%\usepackage[utf8]{inputenc} %linux
\usepackage[T1]{fontenc} % for textbackslash
\usepackage[german, english]{babel}
\usepackage{float} % placing floats (table and figures) where they should be
\usepackage{lmodern} % make tiny font shape warnings within the beamer class diappear
\usepackage{tabu, multirow, url, hyperref, textcomp, amsmath, listings, datetime, graphicx, booktabs, xcolor, multicol, setspace}
\usepackage[absolute,overlay,showboxes]{textpos}
\hypersetup{pdfstartview={XYZ null null 1}}
\hypersetup{colorlinks=true, linkcolor=blue, urlcolor=blue}
\setbeamertemplate{footline}[text line]{%
\parbox{\linewidth}{\vspace*{-8pt}
\href{https://bookdown.org/brry/course}{bookdown.org/brry/course} \hfill
\hyperlink{toc}{TOC} ~~ \insertframenumber / \inserttotalframenumber~~~~~~~~~}}
\setbeamertemplate{navigation symbols}[only frame symbol]
\beamersetleftmargin{0.3cm}
\beamersetrightmargin{0.3cm}
% Reduce spacing in table of contents (toc) http://tex.stackexchange.com/questions/51452
\usepackage{etoolbox}
\makeatletter
\patchcmd{\beamer@sectionintoc}{\vskip1.5em}{\vskip0.1em}{}{} % vskip0.5em
\makeatother
% Remove Bullets and Numbers in TOC: http://tex.stackexchange.com/questions/54656
\setbeamertemplate{sections/subsections in toc}[default]
% white letters in enumerate bullet points
%\definecolor{stupidblue}{RGB}{51,51,178}
\setbeamercolor{item projected}{fg=white}%fg=blue,bg=red!75!black} % fg=white , bg=stupidblue
\setbeamercolor{frametitle}{fg=black}
% Block title color
\setbeamercolor{block title}{fg=white}%fg=blue,bg=red!75!black} % white
%\setbeamertemplate{item projected}[square]
% define an environment for the exercises
\newcounter{exercisecount}
\setcounter{exercisecount}{0}
\newenvironment{exercise}[1]
{% This is the begin code
\stepcounter{exercisecount}
\begin{block}{Exercise \arabic{exercisecount}: #1}
}
{% This is the end code
\end{block} }
\resetcounteronoverlays{exercisecount}
% format inline R command names in blue courier and lightgrey background:
\newcommand{\rcode}[1]{\texttt{\textcolor{Blue}{#1}}}
\newcommand{\key}[1]{\colorbox{gray!30}{\texttt{\textcolor{Blue}{#1}}}}
% links to files
\newcommand{\datalinkRaw}[1]{\href{https://raw.githubusercontent.com/brry/course/master/data/#1}{#1}}
\newcommand{\datalinkBlob}[1]{\href{https://github.com/brry/course/blob/master/data/#1}{#1}}
\newcommand{\datalinkText}[1]{\href{https://github.com/brry/course/blob/master/data/#1}{#1}
{\footnotesize \textit{(rightclick \textbf{Raw}, save as)}}}
% Format month with leading zero:
\newcommand{\leadingzero}[1]{\ifnum #1<10 0\the#1\else\the#1\fi}
% "#' " for doc files:
\newcommand{\doc}{\#\textquotesingle~}
% remove empty lines between code and output. apparently hard to get rid of without turning off syntax highlighting
%------------------------------------------------------------%
%------------------------------------------------------------%
\begin{document}
%------------------------------------------------------------%
%------------------------------------------------------------%
\AtBeginSubsection[]
{
\begin{frame}%[shrink]
{Outline}
\scriptsize
\tableofcontents[sectionstyle=show/shaded, subsectionstyle=show/shaded/hide]
\end{frame}
}
%\def\newblock{} % beamer---natbib bugfix
<<setup, include=FALSE>>=
library(knitr)
# install packages, if not available
packinst <- function(n) if(!requireNamespace(n, quietly=TRUE)) install.packages(n)
dummy <- sapply(c("berryFunctions", "numbers", "TeachingDemos", "devtools",
"microbenchmark", "zoo", "extremeStat", "nortest", "xts",
"maptools", "rgeos", "sp", "geoR"), packinst)
# set global chunk options maybe use out.width='.55\\linewidth'
opts_chunk$set(fig.path='./fig/', fig.align='center', fig.show='hold', out.width='\\textwidth', fig.height=3, fig.width=6, cache=TRUE)
options(replace.assign=FALSE, width=50) # width 40 or 60
# set locale to US, which makes sure that eg month names are in english
# Sys.setlocale("LC_ALL", "US") # Windows
Sys.setlocale("LC_ALL","English")
Sys.setenv(LANG = "en") # english errors and warnings
# set r course working directory
# if(.Platform$OS.type=="unix") if(Sys.getenv("username") == "hydro")
# try(setwd("S:/Dropbox/Public/R_course_Berry"))
# if(Sys.info()["nodename"]=="GK-PC-2") setwd("C:/Users/boessenkool/Dropbox/Public/R_course_Berry")
ThemeBerry <- list(highlight="
\\definecolor{fgcolor}{rgb}{0, 0, 0}
\\newcommand{\\hlnum}[1]{\\textcolor[rgb]{0,0,0}{#1}}
\\newcommand{\\hlstr}[1]{\\textcolor[rgb]{0.545,0.137,0.137}{#1}}
\\newcommand{\\hlcom}[1]{\\textcolor[rgb]{0,0.392,0}{\\textit{#1}}}
\\newcommand{\\hlopt}[1]{\\textcolor[rgb]{0,0,0}{#1}}
\\newcommand{\\hlstd}[1]{\\textcolor[rgb]{0,0,0}{#1}}
\\newcommand{\\hlkwa}[1]{\\textcolor[rgb]{1,0,0}{\\textbf{#1}}}
\\newcommand{\\hlkwb}[1]{\\textcolor[rgb]{0,0,0}{#1}}
\\newcommand{\\hlkwc}[1]{\\textcolor[rgb]{1,0,1}{#1}}
\\newcommand{\\hlkwd}[1]{\\textcolor[rgb]{0,0,1}{#1}}
", background="#F5F5F5", foreground="black")
knit_theme$set(ThemeBerry)
rm(ThemeBerry)
@
%------------------------------------------------------------%
%------------------------------------------------------------%
\section{R course info}
%------------------------------------------------------------%
%------------------------------------------------------------%
<<slidebg, echo=F, fig.show='hide', fig.height=4.5>>=
library("berryFunctions")
par(mar=c(0,0,0,0))
plot(1:10, axes=F, type="n", ann=FALSE, xaxs="i", yaxs="i")
set.seed(007)
for(i in 1:50)
{
x <- seq(1,10, length=sample(10:100,1))
y <- rescale(cumsum(rnorm(length(x)+30))[-(1:30)], -1, 13)
lines(x, y, col=addFade(sample(colors(),1), 0.1), lwd=2)
}
@
{\usebackgroundtemplate{\includegraphics[width=\paperwidth]{fig/slidebg-1.pdf}}
\begin{frame}
\begin{center}
\begin{columns}
\column{22.0em}
\begin{block}{}{\Large ~Introductionary + advanced~ \includegraphics[width=0.7cm]{externalfig/Rlogo.png}~course}
\end{block}
\end{columns}
\vspace{1em}
Berry Boessenkool, \texttt{[email protected]}\\
Hints and corrections are very welcome!\\[1em]
Download the current slides, source code and datasets at\\
\Large
\href{https://bookdown.org/brry/course}{bookdown.org/brry/course}\\[1em]
\normalsize
These slides are licenced under
\href{https://creativecommons.org/licenses/by/4.0}{\includegraphics[width=3em]{externalfig/ccby.png}},\\
so you can use the material freely as long as you cite me.\\[2em]
% \alert{guest account. example PC: ~ Einstein, 141.89.114.20\\user: gast\_20 ~ pw: 20-einstein. (mind the dot)}\\[1em]
\scriptsize
PDF created on \the\year-\leadingzero{\month}-\leadingzero{\day}, \currenttime\ \hyperlink{introBerry}{\textcolor{white}{.}}\\[1em]
\end{center}
\end{frame}
}
%------------------------------------------------------------%
\begin{frame}{Outline}
%%%\hspace{0.9em} \hyperlink{titlepage}{R course Info}\\[0.4em]
\tableofcontents[hideallsubsections]
\label{toc}
\end{frame}
%------------------------------------------------------------%
%------------------------------------------------------------%
\section{1. One-Session-Intro}
%------------------------------------------------------------%
%------------------------------------------------------------%
%------------------------------------------------------------%
%------------------------------------------------------------%
\subsection{1. Intro, objects, vectors}
%------------------------------------------------------------%
%------------------------------------------------------------%
\begin{frame}{\rcode{print("Hello world!")}}
\label{introBerry}
\begin{itemize}[<+->]
\item Berry Boessenkool $\rightarrow$ [email protected]
\item Geoecology @ Potsdam University
\item R Fan\onslide<+->atic \onslide<+-> since 2010
\begin{itemize}
\item Programming: \href{https://github.com/brry/rdwd\#rdwd}{\texttt{rdwd}},
\onslide<+->\href{https://github.com/brry/extremeStat}{\texttt{extremeStat}},
\onslide<+->\href{https://github.com/brry/OSMscale}{\texttt{OSMscale}}
\item Community: \href{https://www.meetup.com/de-DE/Berlin-R-Users-Group/}{\includegraphics[width=3em]{externalfig/BRUG_full.png}}
\item Training \& Consulting: \href{https://brry.github.io}{\includegraphics[width=0.5cm]{externalfig/Blogo.png}}
\end{itemize}
%\item \alert{Jump to beta distribution \hyperlink{beta}{example lecture}}
\item These slides were originally based on a one week course held in 2013 for \href{http://www.cawa-project.net/ru/news-detail/news/cawa-training-course-statistical-analysis-in-hydrology-introduction-into-r/}{CaWa} with Mathias Seibert (GFZ) in Bishkek, Kyrgyzstan
% \item R installation instructions: \href{https://bookdown.org/brry/course/install.html}{bookdown.org/brry/course/install}
\item \alert{If we're proceeding too fast, please interrupt!}
\end{itemize}
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Session 1: Why R, read file, select and plot data}
Aim: \pause get a general impression on how R works, without going too much into technical detail.\\
\pause Afterwards, you should be able to:
\pause
\begin{itemize}[<+->]
\item start a new script in Rstudio and execute lines of code
\item read a data file into R
\item select a column and rows that fullfill a certain criterion
\item generate basic graphics with annotation and added elements
\item open and read the documentation for R functions
\end{itemize}
\onslide<+->
\vspace{2em}
-> Brief inputs followed by short exercises (for max learning)
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Why R? (and not matlab, java, html, C++, fortran)}
\includegraphics[width=0.7cm]{externalfig/Rlogo.png} \pause is free \pause \& open source \pause and has a large user community \pause (hence many methods are implemented).\\
\pause It is the standard for data analysis \pause and visualisation \pause in many universities and industries.\\
\pause R is an interpreter language \pause $\rightarrow$ no compilation, human readable code\\
\pause The flexibility of programming \pause enables automatization \pause of complex statistical procedures.\\
\pause Using R will make your work efficient, \pause productive, \pause transparent \pause and reproducible, \pause thus giving you happiness \pause and a job chance advantage.\\[2em]
\pause R installation instructions: \href{https://bookdown.org/brry/course/install.html}{bookdown.org/brry/course/install.html}\\
\end{frame}
%------------------------------------------------------------%
% \begin{frame}{In the future, programming will save you time!}
% \includegraphics[width=0.99\textwidth]{externalfig/xkcd3.PNG}\\
% I find that when someone's taking time to do something right in the present, they're a perfectionist with no ability to prioritize, whereas when someone took time to do something right in the past, they're a master artisan of great foresight. (\href{https://xkcd.com/974/}{xkcd.com/974})\\
% \end{frame}
%------------------------------------------------------------%
\begin{frame}{Clone github repo from within Rstudio I}
\label{installGit}
Install git (program for version control) \href{https://bookdown.org/brry/course/git.html}{bookdown.org/brry/course/git.html}\\[1em]
Go to \href{https://github.com/brry/course}{github.com/brry/course} -> \colorbox{Green}{\textcolor{White}{Code}} -> Copy URL
\begin{figure}
\includegraphics[width=0.8\textwidth]{./externalfig/git_clone_1.PNG}
\end{figure}
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Clone github repo from within Rstudio II}
\footnotesize
Rstudio - File - New Project - Version Control - Git\\
paste the repository URL, set the subdirectory and create project.\\
\scriptsize
I recommend to keep the Project directory name so local and github folder names match exactly.
\footnotesize
\begin{figure}
\includegraphics[width=0.9\textwidth]{./externalfig/git_clone_Rstudio.png}
\end{figure}
From now on, get the latest version of my slides with a single click on \key{Pull}:
\begin{figure}
\includegraphics[width=0.4\textwidth]{./externalfig/git_clone_6.PNG}
\end{figure}
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Integrated Development Environment (IDE): RStudio}
\label{iderstudio}
\begin{figure}
\includegraphics[width=0.95\textwidth]{./externalfig/Rstudio2.png}
\end{figure}
\label{rstudio}
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Get started in R}
\pause
\begin{exercise}{R is an awesome calculator}
In the console, calculate ~ 21+21 ~,~ 7*6 ~ and ~ $\frac{0,3}{4}*\sqrt{313600}$\\
\textit{If you don't know how to compute a square root in R, you can google it!}
\end{exercise}
\vspace{-1em}
\pause
<<sol_Rcalc, eval=F>>=
21+21 ; 7*6 ; 0.3/4*sqrt(313600)
@
\vspace{-1em}
\pause
\begin{itemize}[<+->]
\item objects: assignment ~ \rcode{$<-$} ~ Rstudio Keyboard shortcut: \key{ALT} + \key{-} \\
\rcode{nstudents <- 15\\nstudents\\nstudents > 12}
\item What's a good object name? \onslide<+-> $\rightarrow$ short, but explanatory,
\onslide<+-> lowerCamelStandard\_or\_underscore are good naming conventions
\item comments: \texttt{\textcolor[rgb]{0,0.392,0}{\# everything after a hashtag is not executed.}}
\item Rstudio scripts: Send line/selection to R console: \key{CTRL} + \key{ENTER}
\end{itemize}
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Objects: vectors}
\begin{itemize}[<+->]
\item To create a vector with values, use the syntax\\
\rcode{values <- c(3, -11, 13, 5.94)} \texttt{\textcolor[rgb]{0,0.392,0}{\# \textbf{c}oncatenate, \textbf{c}ombine}}
\item To obtain a subset (=indexing), use square brackets: \rcode{values[2]}
\end{itemize}
\onslide<+->
\begin{exercise}{Vector indexing}
\begin{enumerate}
\item Create a vector with body sizes of people around you. You can also use the values 1.75, 1.76, 1.83, 1.84, 1.77, 1.76, 1.77, 1.66, 1.86, 1.76. Assign it to an object with a useful name (\rcode{YourObject} is not one!).
\item What does \rcode{3:6} create? What does \rcode{YourObject[3:6]} do?
\item What does \rcode{YourObject[-4]} do?
\item BONUS (for fast people): Analyze the descriptive statistics: \rcode{mean(YourObject), median, min, max, range, quantile}
\item BONUS 2: Help your peers - there's no reason to be bored ;-)
\end{enumerate}
\end{exercise}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Vector task solutions}
<<vectsol, eval=FALSE>>=
size <- c(1.75, 1.76, 1.83, 1.84, 1.77, 1.76,
1.77, 1.66, 1.86, 1.76)
3:6 # A vector with consecutive integers
size[3:6] # Select the corresponding elements of a vector
size[-4] # Select all but the fourth value
@
<<vectsol2, echo=-1, size="scriptsize">>=
size <- c(1.75, 1.76, 1.83, 1.84, 1.77, 1.76, 1.77, 1.66, 1.86, 1.76)
c(mean(size), median(size), min(size), max(size)); range(size); quantile(size)
@
\rcode{mean} and \rcode{median} are similar, hinting at a symmetric data distribution\\
\rcode{range} returns a composite of \rcode{min}imum and \rcode{max}imum\\
\rcode{quantile} returns \href{http://lmgtfy.com/?q=quantile}{quantiles} (now that is surprising...)
\end{frame}
%------------------------------------------------------------%
%------------------------------------------------------------%
\subsection{2. Files, data.frames}
%------------------------------------------------------------%
%------------------------------------------------------------%
\begin{frame}{Reading files}
<<datageneration, echo=F, eval=F>>=
set.seed(42)
age1 <- runif(50, 5, 25)
height1 <- 2.4e-05*age1^3 - 0.051*age1^2 + 3*age1 - 7.6 + rnorm(50, sd=3)
age2 <- runif(50, 5, 25)
height2 <- 2.4e-05*age2^3 - 0.051*age2^2 + 2.5*age2 - 7.6 + rnorm(50, sd=3)
treesize <- data.frame(age=round(c(age1,age2),1),
height=round(c(height1,height2),1),
measured=rep(c("A","B"), each=50))
treesize <- treesize[sample(1:100), ]
write.table(treesize, file="data/treesize.txt", quote=F, row.names=F)
plot(height~age, data=treesize, col=measured)
@
\onslide<+->
\begin{itemize}[<+->]
\item Read files into R with the command \rcode{read.table}
\item \rcode{?read.table}, or press F1 to read the documentation
\end{itemize}
\onslide<+->
In case you did not clone the course repo:
\begin{itemize}
\item Download \datalinkText{treesize.txt}
\item Tell R (in the script) where to look for files with:\\
\rcode{setwd("C:/path/to/input")} \texttt{\textcolor[rgb]{0,0.392,0}{ \# use forwardslashes}}
\end{itemize}
\onslide<+->
\begin{exercise}{Reading files}
\begin{itemize}[<+->]
\item Read the file into R with the command \rcode{read.table}, assigning it to an object with a good name.
\item If R tells you "no such file" exists, check the output of \rcode{dir()}.
\item Check the object with \rcode{head(YourObject)}.
\item \rcode{str(YourObject)} must yield the column data types: \texttt{num, num, factor}.
\item You need to set the argument \texttt{header}.
\end{itemize}
\end{exercise}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution to exercise \arabic{exercisecount}: Reading files}
<<solreadfile, eval=F>>=
treesize <- read.table(file="treesize.txt", header=TRUE)
str(treesize)
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Objects: data.frames}
\vspace{-0.5em}
\begin{itemize}[<+->]
\item For tables with different data types (numbers, characters, categories, integers), R has the object type data.frame: \\\rcode{data.frame(count=c(2,6,5), type=c("a","k","k"))}
\item \rcode{read.table} also returns a data.frame
\item If we have the object \rcode{DF}, we can subset with \rcode{DF[rows,columns]}
\item \rcode{DF[1,2:4]; \onslide<+-> DF[2, ]; \onslide<+-> ~ DF[ ,"name"]; \onslide<+-> DF\$name}
\item Logical values: \rcode{vect[c(TRUE,TRUE,FALSE,FALSE,TRUE,FALSE)]}
\end{itemize}
\onslide<+->
\begin{exercise}{Data.frame indexing}
From the dataset \rcode{treesize} from the previous exercise, obtain:
\begin{enumerate}
\item The first 5 values in column 2
\item The maximum "Height" (the maximum of the values in that column)
\item For each entry: is the measurement equal to (\rcode{==}) A?
\item BONUS 1: The height entries for trees older than 23.5 years
\item BONUS 2: All rows, excluding rows 3,7,8,9,...,90
\end{enumerate}
\end{exercise}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution to exercise \arabic{exercisecount}: subsetting data.frames I}
<<sol_treessubset, eval=T, echo=-(1:2), size="scriptsize">>=
options(width=80)
treesize <- read.table(file="data/treesize.txt", header=TRUE)
treesize[1:5, 2]
max(treesize$height) ; max(treesize[ ,"age"])
treesize$measurement=="A"
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution to exercise \arabic{exercisecount}: subsetting data.frames II}
<<sol_treessubset2, size="scriptsize">>=
treesize[ treesize$age >= 23.5 , "height"]
@
<<sol_treessubset3, eval=F, size="scriptsize">>=
treesize[ -c(3,7:90) , ]
#
@
\vspace{-3em}
<<sol_treessubset4, echo=F, size="scriptsize">>=
options(width=50)
head(treesize[ -c(3,7:90) , ],12); cat("...")
@
\end{frame}
%------------------------------------------------------------%
%------------------------------------------------------------%
\subsection{3. Plotting}
%------------------------------------------------------------%
%------------------------------------------------------------%
\begin{frame}[fragile]{Plotting I}
General code for scatterplots: \rcode{plot(x, y, ...)}
\pause
<<plot_indo1, echo=-1>>=
par(mar=c(2.8,2.8,1.5,0), mgp=c(1.8,0.7,0))
plot(x=Indometh$time, y=Indometh$conc,
col="orange", pch=16, main="Awesome Graph!")
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Plotting I}
General code for scatterplots: \rcode{plot(x, y, ...)}
<<plot_indo2, echo=-(1:2)>>=
par(mar=c(2.8,2.8,1.5,0), mgp=c(1.8,0.7,0))
plot(x=Indometh$time, y=Indometh$conc,
col="orange", pch=16, main="Awesome Graph!")
points(4, 1.5, pch=22, bg="yellow", cex=4, col="red")
# PointCHaracter, BackGround, Character EXpansion
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Plotting I}
General code for scatterplots: \rcode{plot(x, y, ...)}
<<plot_indo3, echo=-(1:3)>>=
par(mar=c(2.8,2.8,1.5,0), mgp=c(1.8,0.7,0))
plot(x=Indometh$time, y=Indometh$conc,
col="orange", pch=16, main="Awesome Graph!")
points(4, 1.5, pch=22, bg="yellow", cex=4, col="red")
lines(x=c(2,5,6,7), y=c(1,2.3,-3,1),
col="blue", type="b", lwd=5)
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Plotting II: Our treesize dataset}
\vspace{-1em}
%Code to read the file:
<<readtreesize, eval=F, size="small">>=
treesize <- read.table(file="data/treesize.txt", header=TRUE)
@
\pause
%General code for scatterplots:
<<generalplot, eval=FALSE>>=
plot(x=xvalues, y=y_values, xlab="nice axis label",
main="graph title", las=1)
@
\pause
\begin{exercise}{Scatterplots, sample distribution graphs}
\begin{enumerate}%[<+->]
\item Plot tree height over age.
\item Add labels to the plot.
\item Change the point character (\rcode{pch}) and color (\rcode{col}).
\item BONUS 1: Use a catogory vector for colors, e.g. as.factor(treesize\$measurement)
\item BONUS 2: Compare the histogram (\rcode{hist}) of the heights with the \rcode{boxplot} and \rcode{quantile(x, probs=c(0.1, 0.8))}.
\end{enumerate}
\end{exercise}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: Scatterplots}
<<solscatplot, fig.show="hide", size="footnotesize", fig.height=4>>=
treesize <- read.table(file="data/treesize.txt", header=TRUE)
plot(treesize$age, treesize$height)
plot(treesize$age, treesize$height, las=1, ylab="Tree height [m]",
xlab="Tree age [years]", col=as.factor(treesize$measurement),
main="Older trees are larger", pch=3)
quantile(treesize$height, probs=c(0.1, 0.8))
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: Scatterplot}
\includegraphics[width=\linewidth]{fig/solscatplot-2.pdf}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: Histogram}
<<solscathist>>=
hist(treesize$height, col="purple", breaks=20, las=1)
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: Boxplot}
<<solscatbox>>=
boxplot(treesize$height, col="cyan", horizontal=TRUE,
notch=TRUE)
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{commonly needed \rcode{plot} arguments}
<<plotoverview, eval=FALSE>>=
plot(x, y, # point coordinates
col="lightblue", # point color
pch=0, # point character (symbol)
xlab="My label [km]", ylab="", # axis labels
main="Graph title", # title
cex=1.8, # character expansion (symbol size)
type="l", # draw lines instead of points
lwd=3, # line width (thickness of lines)
las=1, # label axis style (axis numbers upright)
xaxt="n" # axis type (none to suppress axis)
)
@
\end{frame}
%------------------------------------------------------------%
%------------------------------------------------------------%
\subsection{4. Packages, regression}
%------------------------------------------------------------%
%------------------------------------------------------------%
\begin{frame}[fragile]{R Packages}
\begin{itemize}[<+->]
\item Many people write code for specific tasks and publish it on CRAN, the Comprehensive R Archive Network
\item Packages for a range of topics: \href{http://cran.r-project.org/web/views/}{cran.r-project.org/web/views}
\item All $>$16'000 available packages: \href{http://cran.r-project.org/web/packages/}{cran.r-project.org/web/packages}
\item \rcode{install.packages("ggplot2")} to download and install.\\
\footnotesize (only needs to be executed once, works on user level, no admin rights required)\\
You can do this in Rstudio \normalsize
\item \rcode{library("ggplot2")} to load it \\
\footnotesize (needed in every new R session) Put this in the script for reproducibility \normalsize
\item Better to use the \rcode{package::function} syntax
\item Regularly run \rcode{update.packages()} or use the Rstudio button
\item Rarely needed: \rcode{remove.packages("packagename")}
\end{itemize}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Packages and linear regression}
\begin{exercise}{Packages, linear regression}
\begin{enumerate}
\item Install and load the package \rcode{berryFunctions}
\item Pass the \datalinkText{treesize.txt} data to \rcode{linReg}.
Don't use (x,y) coordinates, but a (y\textasciitilde x) formula, read as "y dependent on x".
Use the \texttt{data} argument as described in the "Examples" section of the \rcode{linReg} manual.
Describe the resulting graph (height vs age).
\item Feed the data into \rcode{lm}, assign the output to an object (useful name!).
\item Briefly explain the \rcode{summary} of the linear model.
\item BONUS1: Look into the source code of \rcode{linReg}.
% \textit{If you don't know how to view the source code of a function in R, you can google it!}
You can print the function by calling it without brackets.
You can also open it on github with \rcode{berryFunctions::funSource}.
\item BONUS2: What is the backbone for the calculation in \rcode{linReg}?
\item BONUS3: install \href{https://github.com/brry/rskey\#rskey}{rskey},
set a keyboard shortcut for \rcode{funSource} and use it to get the source code of some function.
\end{enumerate}
\end{exercise}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: Linear regression}
\vspace{-1em}
<<sollinreg, eval=FALSE, size="footnotesize">>=
library("berryFunctions")
linReg(height~age, data=treesize)
linReg
funSource(linReg) # berryFunctions/R/linReg.R - working horse: lm
linear_model <- lm(height~age, data=treesize)
summary(linear_model)
@
\vspace{-1em}
\small
\href{http://blog.yhat.com/posts/r-lm-summary.html}{blog.yhat.com/posts/r-lm-summary.html}\\
\href{http://stats.stackexchange.com/questions/5135/interpretation-of-rs-lm-output}{stats.stackexchange.com/questions/5135/interpretation-of-rs-lm-output}
\normalsize
<<sollinreg2, echo=F, fig.height=2.1>>=
treesize <- read.table(file="data/treesize.txt", header=TRUE)
par(mar=c(2.5,3,2,1), mgp=c(2,0.7,0))
library("berryFunctions")
linReg(height~age, data=treesize, pos1="topleft", xlab="", inset=-0.03)
title(xlab="age", mgp=c(1.5,0,0))
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}{Session 1: Recap \footnotesize{(They tried to make me go to recap and I said, 'Yes, yes, yes.')}}
\pause
\begin{itemize}[<+->]
\item R is awesome. You're here, thus you will be R-some, too
\item Console for code execution (R), ready with \rcode{$>$}, waiting with \rcode{$+$}
\item Script for code writing (you) + exchange
\item Objects are created with the assignment operator \rcode{$<$-}%, see \rcode{ls()} % in the workspace
\item Get help with \rcode{help(median)}, \rcode{?matrix}, or pressing F1
\item Create vectors with \rcode{c(42,3,-4)}, \rcode{1:n}
\item \rcode{data.frame}s hold tables with one data type per column
\item \rcode{read.table}, with \texttt{header=TRUE} to read files into R
\item Index objects with \rcode{values[8:5]}, \rcode{tab[4,2:6]}
\item df columns with \rcode{tab[ ,3]}, \rcode{tab[ ,"precip"]}, \rcode{tab\$wind}
\item \rcode{hist(vals)}; \rcode{plot(x,y, las=1, pch=16, type="b")}
\end{itemize}
\pause
Homework: finish all covered exercises, work on exercise 7 (Reading files, subsetting, comparing)
% \onslide<+-> The homework is at \url{https://github.com/brry/course/blob/master/uni.md\#homework}
\end{frame}
%' %------------------------------------------------------------%
%' %------------------------------------------------------------%
%' \subsection{Packages, normality test}
%' %------------------------------------------------------------%
%' %------------------------------------------------------------%
%'
%' \begin{frame}[fragile]{Test for normality of a distribution}
%' \pause
%' \begin{itemize}[<+->]
%' \item If a population is normally distributed, it is described by only two parameters: the mean (position) and the sd (width, dispersion) of the bell shaped curve.
%' \item This is an important assumption for many classical statistical methods.
%' \item Whether a dataset is normally distributed can be checked with a histogram (visually effective, but the class limits are subjective), with qqplots (I don't find them very intuitive), or with statistical tests.
%' \item
%' <normaltest, eval=F>>=
%' data <- rnorm(1000, mean=97, sd=8.9)
%' shapiro.test(data)
%' ks.test(data, "pnorm", mean(data), sd(data))
%' # if p > 0.05: accept the Null-hypothesis
%' # that data are normally distributed.
%' @
%' \end{itemize}
%' \end{frame}
%'
%' %------------------------------------------------------------%
%'
%' \begin{frame}{Packages, normality test}
%' \begin{itemize}[<+->]
%' \item Many people write code for specific tasks and publish it on CRAN, the Comprehensive R Archive Network
%' \item \rcode{install.packages("ggplot2")} to download and install\\ (only needs to be executed once, requires internet connection)
%' \item \rcode{library("ggplot2")} to load it (in every new R session)
%' \end{itemize}
%' \onslide<+->
%' \begin{exercise}{Packages, normality test}
%' \begin{enumerate}
%' \item Install and load the package \rcode{nortest}
%' \item Open the package documentation (see \rcode{?help})
%' \item Run and compare several tests for normality: \rcode{shapiro.test}, \rcode{ks.test}\\
%' Lilliefors (Kolmogorov-Smirnov), Anderson-Darling, Cramer-von Mises, Pearson chi-square, Shapiro-Francia
%' \item BONUS: With random numbers generated from a normal distribution (\rcode{rnorm}),
%' study the sensitivity / stability of each of the tests (What do you obtain in repeated application?).
%' \end{enumerate}
%' \end{exercise}
%' \end{frame}
%'
%' %------------------------------------------------------------%
%'
%' \begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: normality test}
%' \vspace{-1em}
%' <<solnortest, eval=TRUE, size="footnotesize">>=
%' if(!requireNamespace("nortest")) install.packages("nortest")
%' library(nortest) # with Lilliefors-correction!
%' help(package="nortest")
%' d <- treesize$height[treesize$measurement=="A"]
%' lillie.test(d) # Lilliefors (Kolmogorov-Smirnov) test for normality
%' ad.test(d) # Anderson-Darling test for normality
%' @
%' \end{frame}
%'
%' %------------------------------------------------------------%
%'
%' \begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: normality test}
%' <<solnortest2, eval=TRUE, size="tiny">>=
%' cvm.test(d) # Cramer-von Mises test for normality
%' pearson.test(d) # Pearson chi-square test for normality
%' sf.test(d) # Shapiro-Francia test for normality
%' @
%' \end{frame}
%------------------------------------------------------------%
\begin{frame}{Time to put all of this into practice}
\begin{exercise}{Reading files, subsetting, comparing}%1
\begin{enumerate}
\item Start a new session of R. Read in the tree size data.
\item Check that everything is read correctly with \rcode{str}.
\item \rcode{which} rows of the data.frame have measurement equal to (\rcode{==}) B?
\item Plot the linear regression for measurement method B, then add the points and regression line for A in a different color and shape.
\item BONUS 1: use \rcode{boxplot} with a formula (\rcode{height\textasciitilde measurement})
for an automatic boxplot comparison with median difference notches.
\item BONUS 2: Visually compare the effect of Girth and Height on Volume in the dataset \rcode{trees}. Here's one idea (of many possible): Plot with two panels below each other (\rcode{par(mfrow=c(2,1)}), with the linear regression plots (\rcode{berryFunctions::linReg}) for each variable. Make it look nice with the graphical \rcode{par}ameters \texttt{mar} and \texttt{mgp}, as well as by specifying some of the linReg arguments.
\end{enumerate}
\end{exercise}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: Reading files, subsetting}
<<introsol1, eval=FALSE, size="footnotesize">>=
setwd("D:/my/path")
treesize <- read.table(file="data/treesize.txt", header=TRUE)
str(treesize)
@
\vspace{-1em}
<<introsol2, fig.show="hide", eval=T, size="footnotesize", fig.height=4>>=
which(treesize$measurement=="B")
treeA <- treesize[treesize$measurement=="A", ]
treeB <- treesize[treesize$measurement=="B", ]
library("berryFunctions")
linReg(height~age, data=treeA, pos1="topleft")
linReg(height~age, data=treeB, add=T, colline="blue",
pos1="bottomright", inset=0.05)
points(height~age, data=treeB, pch=3, col="blue")
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}: Plotting, linear Regression}
\includegraphics[width=.99\textwidth]{fig/introsol2-1.pdf}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}.BONUS 1}
<<introsol3, fig.height=3, echo=-1>>=
par(mar=c(3,3,0.5,0.5), las=1)
boxplot(height~measurement, data=treesize,
col=c("blue","orange"), notch=TRUE)
@
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Solution for exercise \arabic{exercisecount}.BONUS 2}
<<introsol4, size="scriptsize", fig.height=3.5, fig.width=6, out.width='.95\\textwidth'>>=
par(mfrow=c(2,1), mar=c(3,3,1.5,0.5), mgp=c(1.9,0.7,0), las=1)
linReg(Volume~Height, data=trees, col="blue", pos1="topleft")
linReg(Volume~Girth, data=trees, col="forestgreen", pos1="topleft")
@
\end{frame}
% %------------------------------------------------------------%
% %------------------------------------------------------------%
% \section{2. Getting started: Background, GUI and first steps}
% %------------------------------------------------------------%
% %------------------------------------------------------------%
%
% %------------------------------------------------------------%
% %------------------------------------------------------------%
% \subsection{Background information}
% %------------------------------------------------------------%
% %------------------------------------------------------------%
%
% \begin{frame}{R - What and Why?}
% \pause
% \vspace{-0.5em}
% \begin{itemize}%[<+->]
% \item R is a standard environment for statistical computing
% \item and an object-oriented programming language.
% \item It is developed and maintained by the R development core team
% \item and has thousands of add-on packages written by the community.
% \item There are mailing lists where users (\& developers) help users
% \item and blogs to communicate analysis and coding to the public.
% \item R allows complex data analysis of big data sets with current methods
% \item and the creation of advanced professional (even interactive) graphics.
% \item Coding and programming forces you to keep track of your work
% \item and allows you to efficiently customize and automatize your analysis.
% \item R is very versatile: you can write your own functions and packages,
% \item implement new methods and make them available to everyone.
% \item Being capable of programming helps finding a job
% \item and the best part: \textcolor{green}{R is open source and free!}
% \end{itemize}
% % \pause
% \small \href{http://fantasyfootballanalytics.net/2014/01/why-r-is-better-than-excel.html}{fantasyfootballanalytics.net/2014/01/why-r-is-better-than-excel.html}
% \href{http://thegrantlab.org/bio3d/tutorials/79-static-content/85-why-use-r}{thegrantlab.org/bio3d/tutorials/79-static-content/85-why-use-r}
% \end{frame}
%
% %------------------------------------------------------------%
%
% \begin{frame}{interpreter language - no compilation}
% \pause
% \centering
% \includegraphics[height=0.65\textheight]{externalfig/compiling.png}\\
% \href{https://xkcd.com/303/}{xkcd.com/303}
% \end{frame}
%
% %------------------------------------------------------------%
%
% % \begin{frame}{R is growing increasingly popular}
% % \begin{figure}[h]
% % \begin{center}
% % \includegraphics[width=.8\linewidth]{./externalfig/jobgraph.png}
% % \caption{\href{http://www.indeed.com/jobanalytics/}{www.indeed.com/jobanalytics}}
% % \label{fig:r-jobs}
% % \end{center}
% % \end{figure}
% % \end{frame}
%
% %------------------------------------------------------------%
%
% \begin{frame}{Where to get R}
% %\pause
% Instructions online: \href{https://bookdown.org/brry/course/install.html}{bookdown.org/brry/course/install.html}\\[1em]
% \begin{itemize}%[<+->]
% % \item base R itself: \href{https://cloud.r-project.org/}{r-project.org}.\\
% % \href{https://cran.r-project.org/bin/linux/ubuntu/README.html}{Official} and \href{https://www.r-bloggers.com/how-to-install-r-on-linux-ubuntu-16-04-xenial-xerus/}{helpful} hints for Linux Ubuntu users.
% % \item \href{https://www.rstudio.com/products/rstudio/\#Desktop}{R-Studio} (widely spread, easy to use)
% %
% \item Editor alternative to Rstudio: \href{http://sourceforge.net/projects/tinn-r/}{Tinn-R}
% \item Only for Windows OS, but flexible window arrangement
% \item Needs some initial tweaking, see \href{https://rclickhandbuch.wordpress.com/install-r/tinn-r_english}{Berry's TinnR Page} % pdf cannot be completed without this percent sign
% \item Since Rstudio has become so incredibly awesome, you should use it!
% \end{itemize}
% \label{installR}
% \end{frame}
%------------------------------------------------------------%
%------------------------------------------------------------%
\section{2. Objects}
%------------------------------------------------------------%
%------------------------------------------------------------%
%------------------------------------------------------------%
%------------------------------------------------------------%
\subsection{1. Rstudio + getting help}
%------------------------------------------------------------%
%------------------------------------------------------------%
% \begin{frame}{Working with R: Basic R GUI and Command line}
% \begin{figure}[h]
% \includegraphics[width=\textwidth]{./externalfig/rgui.png}
% \end{figure}
% \end{frame}
%------------------------------------------------------------%
\begin{frame}{RStudio overview}
\begin{figure}
\includegraphics[width=0.95\textwidth]{./externalfig/Rstudio.png}
\end{figure}
\end{frame}
%------------------------------------------------------------%
\begin{frame}{RStudio configuration}
Recommended settings for reproducible research under\\
\alert{Rstudio - Tools - Global Options - General}\\
\textbf{OFF}: Restore .Rdata into workspace at startup\\
Save workspace to .RData on exit: \textbf{NEVER}\\[0.5em]
\pause
\textit{Instead use \rcode{save(object, file="object.Rdata")} after long computations.
You can load them later with \rcode{load("object.Rdata")}.}\\[0.5em]
\pause
More at \href{https://bookdown.org/brry/course/settings.html}{bookdown.org/brry/course/settings.html}\\[0.5em]
\pause
\href{https://support.rstudio.com/hc/en-us/articles/200711853-Keyboard-Shortcuts}{keyboard shortcuts} (\key{ALT}+\key{SHIFT}+\key{K})
\pause
\begin{enumerate}[<+->]
\item \key{CTRL} + \key{ENTER} (in source script) send line/selection to console
\item \key{CTRL} + \key{UP} (in console) command history
\item \key{CTRL} + \key{SHIFT} + \key{N} new R script
\item \key{CTRL} + \key{O} open file
\item \key{CTRL} + \key{S} save script
\item \key{CTRL} + \key{TAB} next Tab
\item \key{CTRL} + \key{SHIFT} + \key{TAB} previous Tab
\end{enumerate}
\end{frame}
%------------------------------------------------------------%
\begin{frame}[fragile]{Rstudio Tips and Tricks}
\begin{enumerate}[<+->]
\item \href{https://rviews.rstudio.com/2016/11/11/easy-tricks-you-mightve-missed/}{RStudio IDE Easy Tricks You Might've Missed}
and \href{https://rviews.rstudio.com/categories/tips-and-tricks/}{rviews.rstudio.com/categories/tips-and-tricks}
\item Work with Rstudio projects!
\item \key{ALT} + mouse for multiline cursor. \textit{or}: \key{CTRL} + \key{ALT} + \key{UP}/\key{DOWN}
\item \key{CTRL} + \key{1} cursor to panel \scriptsize{(1:source, 2:console, 3:help, 4:history, 5:files, 6:plot...)}
\item \key{CTRL} + \key{SHIFT} + \key{1}/\key{2}/\key{3}/\key{...} panel full view
\item \key{ALT} + \key{UP}/\key{DOWN} move line of code
\item \key{CTRL} + \key{SHIFT} + \key{P} rerun previous code region
\item \key{CTRL} + \key{SHIFT} + \key{S}/\key{ENTER} source document
\item \key{CTRL} + \key{SHIFT} + \key{C} (un)comment lines
\item \key{CTRL} + \key{SHIFT} + \key{M} insert pipe operator
\item tearable panes
\item \key{CTRL} + \key{SHIFT} + \key{O} Document outline
\end{enumerate}
\end{frame}
%------------------------------------------------------------%
% \begin{frame}{Install git (program for version control)}
% \label{installGit}
% \begin{enumerate}
% \item Create a github account at \url{https://github.com/join}\\[1em]
% \item Download and install git, see \url{https://git-scm.com/downloads}\\[1em]
% \item Connect git to Rstudio: up to \rcode{git config user.name} at \url{https://www.r-bloggers.com/rstudio-and-github}\\[1em]
% \item Excellent tutorial on git in general (mostly without Rstudio): \url{http://kbroman.org/github\_tutorial}
% \end{enumerate}
% \end{frame}
%------------------------------------------------------------%
% \begin{frame}[fragile]{Tinn R}
% \begin{figure}[h]
% \begin{center}
% \includegraphics[width=.8\linewidth]{./externalfig/TinnR_gui.PNG}
% \caption{screenshot Tinn-R}
% \label{fig:how to start R from Tinn-R}
% \end{center}
% \end{figure}
% <<trpaths, eval=FALSE, size="scriptsize">>=
% # enable sending of blocks up to the next blank line:
% .trPaths <- paste(Sys.getenv('LOCALAPPDATA'),
% '\\Temp\\Tinn-R', c('', 'search.txt', 'objects.txt',
% 'file.r', 'selection.r', 'block.r','lines.r'),sep='\\')
% # write this in C:/Program Files/R/R-3.2.2/etc/Rprofile.site
% @
% \end{frame}
%------------------------------------------------------------%
%------------------------------------------------------------%
% \subsection{Getting help}
%------------------------------------------------------------%
%------------------------------------------------------------%
\begin{frame}[fragile]{Getting help}