/
Chapter1.tex
1391 lines (1124 loc) · 38.2 KB
/
Chapter1.tex
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[10pt]{beamer}
\setbeamersize{text margin left=0.5cm, text margin right=0.5cm}
\usepackage{alltt}%
%\usetheme{Boadilla}
\usetheme[progressbar = foot, background=light]{metropolis}
%\useoutertheme{split}
%\usecolortheme{beaver}
%\usepackage{listings}
\makeatletter
\def\maxwidth{ %
\ifdim\Gin@nat@width>\linewidth
\linewidth
\else
\Gin@nat@width
\fi
}
\makeatother
\definecolor{fgcolor}{rgb}{0.345, 0.345, 0.345}
\newcommand{\hlnum}[1]{\textcolor[rgb]{0.686,0.059,0.569}{#1}}%
\newcommand{\hlstr}[1]{\textcolor[rgb]{0.192,0.494,0.8}{#1}}%
\newcommand{\hlcom}[1]{\textcolor[rgb]{0.678,0.584,0.686}{\textit{#1}}}%
\newcommand{\hlopt}[1]{\textcolor[rgb]{0,0,0}{#1}}%
\newcommand{\hlstd}[1]{\textcolor[rgb]{0.345,0.345,0.345}{#1}}%
\newcommand{\hlkwa}[1]{\textcolor[rgb]{0.161,0.373,0.58}{\textbf{#1}}}%
\newcommand{\hlkwb}[1]{\textcolor[rgb]{0.69,0.353,0.396}{#1}}%
\newcommand{\hlkwc}[1]{\textcolor[rgb]{0.333,0.667,0.333}{#1}}%
\newcommand{\hlkwd}[1]{\textcolor[rgb]{0.737,0.353,0.396}{\textbf{#1}}}%
\let\hlipl\hlkwb
\usepackage{framed}
\makeatletter
\newenvironment{kframe}{%
\def\at@end@of@kframe{}%
\ifinner\ifhmode%
\def\at@end@of@kframe{\end{minipage}}%
\begin{minipage}{\columnwidth}%
\fi\fi%
\def\FrameCommand##1{\hskip\@totalleftmargin \hskip-\fboxsep
\colorbox{shadecolor}{##1}\hskip-\fboxsep
% There is no \\@totalrightmargin, so:
\hskip-\linewidth \hskip-\@totalleftmargin \hskip\columnwidth}%
\MakeFramed {\advance\hsize-\width
\@totalleftmargin\z@ \linewidth\hsize
\@setminipage}}%
{\par\unskip\endMakeFramed%
\at@end@of@kframe}
\makeatother
\definecolor{shadecolor}{rgb}{.97, .97, .97}
\definecolor{messagecolor}{rgb}{0, 0, 0}
\definecolor{warningcolor}{rgb}{1, 0, 1}
\definecolor{errorcolor}{rgb}{1, 0, 0}
\newenvironment{knitrout}{}{} % an empty environment to be redefined in TeX
\usepackage[utf8]{inputenc}
\usepackage{default}
\usepackage{xcolor}%for color mixing
\usepackage{amsmath}%
\usepackage{amsfonts}%
\usepackage{amssymb}%
\usepackage{graphicx}
\usepackage{tikz}
\setbeamertemplate{itemize/enumerate body begin}{\small}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\title{Statistical Thinking in Biology Research}
\subtitle{Chapter 1}
\author[T.Bonnet, T. Neeman]{Timoth\'ee Bonnet \& Terry Neeman}
\institute[RSB/BDSI]{Research School Biology and Biological Data Science Institute}
\date{\today}
\begin{document}
%\lstset{language=R}%code
\setbeamerfont{section in toc}{size*={14}{16}}
\AtBeginSection[]
{
\begin{frame}<beamer>
\frametitle{}
\tableofcontents[currentsection,sectionstyle=show/shaded,subsectionstyle=show/shaded/hide]% down vote\tableofcontents[currentsection,currentsubsection,hideothersubsections,sectionstyle=show/hide,subsectionstyle=show/shaded/hide]
\end{frame}
}
\begin{frame}{}
\maketitle
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{A bit of history of statistical methods}
R.A. Fisher: 1890-1962
\only<1>{\begin{center}
\includegraphics[width=0.5\textwidth]{Figures/fisher}
\end{center}}
\only<2>{\begin{center}
\includegraphics[width=0.9\textwidth]{Figures/fields}
\end{center}}
Statistical Principles for Research Workers (1925)
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{The big picture}
\begin{quote}
To call in the statistician after the experiment is done may be no more than asking him to perform a post-mortem examination: he may be able to say what the experiment died of.
\end{quote}
\textbf{Sir Ronald Fisher} \\ \footnotesize Presidential Address to the First Indian Statistical Congress, 1938. Sankhya 4, 14-17
\pause
\vfill
\textbf{You won't need to call in a statistician too often if you are (almost) one yourself}
\vfill
\pause
\begin{exampleblock}{Statistics is\dots}
\begin{enumerate}
\item interesting
\item a unifying language of sciences
\item empowering
\end{enumerate}
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Approximate plan}
\begin{columns}
\begin{column}{0.2\textwidth}
\end{column}
\begin{column}{0.8\textwidth}
\begin{exampleblock}{}
\begin{itemize}
\item[Monday morning] Cautionary tales, General approach to modelling
\item[Monday afternoon] Experimental design
\item[Tuesday morning] Mean structure, \textit{additive effects and interactions}
\item[Tuesday afternoon] Variance structure, \textit{mixed models}
\item[Wednesday] Data generating process, \textit{GLMs}; + practice with your data?
\end{itemize}
\end{exampleblock}
\end{column}
\end{columns}
If you want, send me:
\begin{itemize}
\item Your data / your planned experiment
\item Brief explanation of biological system and question
\end{itemize}
\hfill \dots we will look at it together
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Key ideas for today}
\begin{block}{}
\begin{itemize}[<+->]
\item Statistics in biology = study biological variation
\item Undestanding statistical ideas about biological variation:
\begin{itemize}
\item Informs the design of experiments
\item Informs the analysis of experiments
\end{itemize}
\item Statistical thinking is an essential component of scientific thinking
\end{itemize}
\end{block}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Cautionary tales from the front}
%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Message 1: A small p-value is not always evidence of a treatment effect}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/message1}
\end{center}
\end{column}
\begin{column}{0.5\textwidth}
\begin{block}{Vaccine challenge experiment:}
\begin{itemize}
\item 6 mice/group (saline/low dose/high dose)
\item All mice challenged with Shigella
\item Followed for 14 days
\item Outcome: Symptom score average Days 2 - 8
\end{itemize}
\end{block}
\begin{alertblock}{}
One-way ANOVA (post-hoc Bonferroni) p=0.04
\end{alertblock}
\end{column}
\end{columns}
\pause \vspace{0.3cm}
\emph{\large Do you think the vaccine works? What is strange?}
\end{frame}
%%%%%%%%%%%%%%%%%%%%%%%
\begin{frame}{Message 1: A small p-value is not always evidence of a treatment effect}
\pause
\vspace{-0.2cm}
\begin{center}
\includegraphics[width=\textwidth]{Figures/mice}
\end{center}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Message 2: p-values from simple comparisons cannot tell us when differences are “different”}
\pause
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/drought}
\end{center}
\end{column}
\begin{column}{0.5\textwidth}
\begin{block}{Are temperature mechanisms modified in a genetically modified tomato plant?}
\begin{itemize}
\item Genotypes: WT/mutant
\item Water condition: Normal/Drought
\item Leaf temperature measured
\end{itemize}
\end{block}
\end{column}
\end{columns}
\begin{alertblock}{T-tests between water conditions:}
GM: p=0.46 ; Wt: p=0.02
\pause
\begin{center}
Evidence of difference + No evidence of difference \\ $\neq$ \\ Evidence that differences are different.
\end{center}
\end{alertblock}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Message 3: Interpreting experimental results needs more than t-tests}
\pause
Research question: Are mice susceptible to obesity when exposed to a high fat diet?
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/message3}
\end{center}
\end{column}
\begin{column}{0.5\textwidth}
\begin{block}{Experimental set-up:}
\begin{itemize}
\item 37 mice: 16 NODk /21 WT
\item Randomised to either regular or high fat diet
\item Monitored for 14 weeks
\item Outcome measure: Body weight (g)
\item Experimental factors: Diet (2), Strain (2), Time (8)
\end{itemize}
\end{block}
\tiny Acknowledgements: Ainy Hussain, PhD student 2013
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Message 4: Knowing how to combine information across subgroups can improve inference}
\pause
Comparing yield in five barley varieties (1930s) \\
Experimental factors: 5 varieties of barley, 6 locations, 2 time points. Outcome measure: yield
\begin{columns}
\begin{column}{0.6\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/message4a}
\end{center}
\end{column}
\begin{column}{0.4\textwidth}
\end{column}
\end{columns}
\tiny Acknowledgements: MASS R-package
\end{frame}
%%%%%%%%%%%
\begin{frame}{Message 4: Knowing how to combine information across subgroups can improve inference}
Comparing yield in five barley varieties (1930s) \\
Experimental factors: 5 varieties of barley, 6 locations, 2 time points. Outcome measure: yield
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/message4b}
\end{center}
\end{column}
\begin{column}{0.5\textwidth}
\begin{block}{Controlling for other sources of variation:}
\begin{itemize}
\item Controlling for year = comparing yield WITHIN years and combining these
\end{itemize}
\end{block}
\tiny Acknowledgements: MASS R-package
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Message 4: Knowing how to combine information across subgroups can improve inference}
Comparing yield in five barley varieties (1930s) \\
Experimental factors: 5 varieties of barley, 6 locations, 2 time points. Outcome measure: yield
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/message4c}
\end{center}
\end{column}
\begin{column}{0.5\textwidth}
\begin{block}{Controlling for other sources of variation:}
\begin{itemize}
\item Control for year = compare yield WITHIN years and combine these
\item Control for location = compare yield WITHIN locations and combine these
\end{itemize}
\end{block}
\tiny Acknowledgements: MASS R-package
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Message 4: Knowing how to combine information across subgroups can improve inference}
\begin{columns}
\begin{column}{0.5\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/message4d}
\end{center}
\end{column}
\begin{column}{0.5\textwidth}
\begin{block}{Controlling for other sources of variation:}
\begin{itemize}
\item Control for year = compare yield WITHIN years and combine these
\item Control for location = compare yield WITHIN locations and combine these
\end{itemize}
\end{block}
\tiny Acknowledgements: MASS R-package
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Message 5: Knowing what factors contribute to the variation in outcome helps design experiments and analyses}
\pause
Research question:
How does cold duration impact upon germination in alpine plant \textit{A. glacialis}?
\begin{columns}
\begin{column}{0.4\textwidth}
\begin{center}
\includegraphics[width=\textwidth]{Figures/message5}
\end{center}
\end{column}
\begin{column}{0.6\textwidth}
\begin{block}{Experimental set-up:}
\begin{itemize}
\item Seed collections from alpine region in Australia
\item 3 Regions -- low/high altitude
\item 4 sets of Petri dishes
\item 4 cabinet shelves with different temperatures
\item Response - \% germinated
\end{itemize}
\end{block}
\end{column}
\end{columns}
\vspace{0.1cm}
\textbf{\emph{What factors other than temperature to consider? }}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Summary}
\begin{enumerate}[<+->]
\item A small p-value is not always evidence of a treatment effect. \textbf{Good experimental design matters.}
\item p-values from simple comparisons cannot tell us when differences are “different”. \textbf{For each question / comparison, a specific test}
\item Interpreting experimental results needs more than t-tests. \textbf{Need a statistical model of the experiment, matching scientific question.}
\item Combining information across subgroups can improve inference. \textbf{A statistical model enables accumulation of evidence across experiments.}
\item Knowing what factors contribute to the variation in outcome matters. \textbf{A statistical model allows one to incorporate effect of other factors in the analysis.}
\end{enumerate}
\end{frame}
%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction to Statistical Modelling}
\begin{frame}{Introduction to Statistical Modelling}
\begin{block}{What is a statistical model?}
\pause
\begin{itemize}
\item A formal but simplified representation of the world / an experiment
\item If the representation is good enough for our goal\dots
\item \dots we can learn something from data
\end{itemize}
\end{block}
\pause
\includegraphics[width=0.5\textwidth]{Figures/mapaus}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{Key components of a statistical model of an experiment}
\begin{enumerate}
\item \textbf{Outcome measure}
\begin{itemize}
\item Response variable
\item Measure of interest
\end{itemize}
\item \textbf{Experimental factors}
\begin{itemize}
\item Conditions that can be manipulated
\item Conditions of interest (e.g. genotype, gender)
\item Main questions: do the conditions impact upon the outcome measure?
\end{itemize}
\item \textbf{Blocking factors}
\begin{itemize}
\item Conditions (not of interest) that may impact upon the outcome
\item Sources of variation in the experiment that need to be controlled for
\item Clustering of experimental units
\end{itemize}
\end{enumerate}
\pause
\alert{ALWAYS BEGIN WITH A RESEARCH QUESTION}\\
$=>$ what is outcome / exp factors / blocking factors; \\
$=>$ Do not make-up hypotheses a-posteriori
\end{frame}
%%%%%%%%%%%
\begin{frame}{Key Objectives of a statistical model of an experiment}
\begin{itemize}
\item Compare mean response across different experimental conditions.
\begin{itemize}
\item Obtain estimate of “Treatment effect”
\item Is this “effect” different in subgroups of interest?
\end{itemize}
\item What are the most important factors influencing the mean response?
\item Subsidiary question: how can we design our experiment in future to more efficiently test our hypotheses?
\end{itemize}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Example 1: Does dark respiration differ between C3 and C4 plants?}
\begin{columns}
\begin{column}{0.6\textwidth}
Outcome measure: dark respiration\\
Experimental factor: Plant type (C4/C3)\\
Data: 6 plants each of C4, C3
\begin{block}{Can calculate}
\begin{itemize}
\item Observed overall mean
\item Observed mean C3 plants
\item Observed mean C4 plants
\item Variation around each mean
\end{itemize}
\end{block}
\end{column}
\begin{column}{0.4\textwidth}
\includegraphics[width=0.9\textwidth]{Figures/c34}
\end{column}
\end{columns}
\end{frame}
%%%%%%%%%%%
\begin{frame}{Example 1: Does dark respiration differ between C3 and C4 plants?}
\begin{block}{Can calculate}
\begin{itemize}
\item Observed overall mean
\item Observed mean C3 plants
\item Observed mean C4 plants
\item Variation around each mean
\end{itemize}
\end{block}
\textbf{Statistical model}\\
{\color{purple}{Respiration}} = {\color{blue}{Mean for C3}} + {\color{red}{Difference C4-C3}} * {\color{orange}{(is C4?)}} + {\color{gray}{Noise}}\\
\pause
${\color{purple}{response}} = {\color{blue}{A}} + {\color{red}{D}} \times {\color{orange}{predictor}} + {\color{gray}{\epsilon}}$
${\color{blue}{A}} $ and ${\color{red}{D}}$ are the model PARAMETERS. \\
We want to infer whether ${\color{red}{D}}$ is different from 0
\end{frame}
%%%%%%%%%%%
\begin{frame}{Example 1: Does dark respiration differ between C3 and C4 plants?}
${\color{purple}{response}} = {\color{blue}{A}} + {\color{red}{D}} \times {\color{orange}{predictor}} + {\color{gray}{\epsilon}}$
Can we separate the signal ${\color{red}{D}}$ from the noise ${\color{gray}{\epsilon}}$ ?
\pause
\begin{block}{T-test}
\begin{itemize}
\item Outcome is a continuous variable
\item Experimental factor is one factor with 2 conditions
\item No blocking factor / corrections
\end{itemize}
\end{block}
\pause
$ t = \frac{\color{red}{D}}{\text{\color{gray}{Variation of }}\color{gray}{\epsilon}} \times \frac{\text{Sample Size}}{\sqrt{2}}$
\end{frame}
%%%%%%%%%%%%
\begin{frame}{When can we know whether $D \neq 0$ ?}
\begin{columns}
\begin{column}{0.5\textwidth}
\includegraphics[width=\textwidth]{Figures/figure/ttestdiff-1}
\end{column}
\begin{column}{0.5\textwidth}
$ t = \frac{\color{red}{D}}{\text{\color{gray}{Variation of }}\color{gray}{\epsilon}} \times \frac{\text{Sample Size}}{\sqrt{2}}$
\vspace{1cm}
Is it easier when the true difference is 0.5 or when it is 3 ?
\end{column}
\end{columns}
\pause
\begin{alertblock}{}
\begin{enumerate}
\item Large true difference between the means
\end{enumerate}
\end{alertblock}
\end{frame}
%%%%%%%%%%%
\begin{frame}{When can we know whether $D \neq 0$ ?}
\begin{columns}
\begin{column}{0.5\textwidth}
\includegraphics[width=\textwidth]{Figures/figure/ttestsample-1}
\end{column}
\begin{column}{0.5\textwidth}
$ t = \frac{\color{red}{D}}{\text{\color{gray}{Variation of }}\color{gray}{\epsilon}} \times \frac{\text{Sample Size}}{\sqrt{2}}$
\vspace{1cm}
Is it easier when sample size is 4 or when it is 100?
\end{column}
\end{columns}
\pause
\begin{alertblock}{}
\begin{enumerate}
\item Large true difference between the means
\item Large sample size
\end{enumerate}
\end{alertblock}
\end{frame}
%%%%%%%%%%%
\begin{frame}{When can we know whether $D \neq 0$ ?}
\begin{columns}
\begin{column}{0.5\textwidth}
\includegraphics[width=0.9\textwidth]{Figures/figure/ttestvar-1}
\end{column}
\begin{column}{0.5\textwidth}
$ t = \frac{\color{red}{D}}{\text{\color{gray}{Variation of }}\color{gray}{\epsilon}} \times \frac{\text{Sample Size}}{\sqrt{2}}$
\vspace{1cm}
Is it easier when unexplained variation is 1 or when it is 3?
\end{column}
\end{columns}
\pause
\begin{alertblock}{What makes $t$ large:}
\begin{enumerate}
\item Large true difference between the means
\item Large sample size
\item Small unexplained variation
\end{enumerate}
\end{alertblock}
\end{frame}
%%%%%%%%%%%
\begin{frame}{When can we know whether $D \neq 0$ ?}
\centering \includegraphics[width=0.7\textwidth]{Figures/figure/tvalue-1}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{When can we know whether $D \neq 0$ ?}
\textbf{p-value}: probability (area under curve) of getting a value as extreme as what you observed, when the true D=0
\centering \includegraphics[width=0.7\textwidth]{Figures/figure/tvalueth-1}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{But really, what is a p-value?}
\begin{block}{Candy practical}
\begin{itemize}[<+->]
\item You got a pack of 20 candies with a mix of Halloween and Fruit candies
\item You pick one, it's a Halloween one\dots looks quite disgusting. You put in back
\item You pick a second one. Again a disgusting Halloween candy! You put it back
\item And so on, until 5 candies. You wonder if you have been cheated.
\item Are there more Halloween than Fruit candies in that pack?
\item You decide to use statistics to find out
\end{itemize}
\end{block}
\only<6->{
\begin{exampleblock}{How to?}
\begin{itemize}
\item Draw 5 candies out of the pack
\item Write down how many Halloween candies
\item How often is it 5?
\end{itemize}
\end{exampleblock}
}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{But really, what is a p-value?}
\url{https://docs.google.com/spreadsheets/d/1Y9512z1xxkphjAZ_dYT9SqfQH02UqTDKlW2X0mDEwZY/edit?usp=sharing}
\begin{exampleblock}{}
\begin{itemize}
\item Draw 5 candies out of the pack
\item Write down how many Halloween candies
\item How often is it 5?
\pause
\item Estimate the p-value for the test ``candies have same frequency''
\pause
\item Redo the experiment in R, using random sampling (rbinom)
\pause
\item What is the correct null-distribution?
\end{itemize}
\end{exampleblock}
\end{frame}
%%%%%%%%%%%%
\begin{frame}[fragile]{Back to C3/C4 plants. Analyse real data in R}
1. Set working directory (\texttt{setwd(`` / '')}) or create a R-project\\
2. Load and check data
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
resp <- read.csv("d_respiration.csv”)
str(resp)
View(resp)
\end{verbatim}
\end{kframe}
\end{knitrout}
3. Visualize data
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
library(ggplot2)
ggplot(resp,aes(Plant_type,rrarea,colour=Plant_type))+
geom_point()+facet_wrap(~Variation)
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
%%%%%%%%%%%%
\begin{frame}[fragile]{Fit a t-test in R: \texttt{t.test()}}
\textbf{Subset data by Variation (High and Low)}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
resp_H <- subset(resp,Variation == "High")
resp_L <- subset(resp,Variation == "Low")
\end{verbatim}
\end{kframe}
\end{knitrout}
\pause
\textbf{Compare C3 and C4 plants in “High Variation” subset}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
t.test(rrarea~Plant_type, data=resp_H, var.equal=TRUE)
\end{verbatim}
\end{kframe}
\end{knitrout}
\pause
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.9, 0.9, 0.969}\color{fgcolor}\begin{kframe}
\small
\begin{verbatim}
Two Sample t-test
data: rrarea by Plant_type
t = -0.93776, df = 10, p-value = 0.3705
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
-1.7619349 0.7181446
sample estimates:
mean in group C3 mean in group C4
2.720021 3.241916
\end{verbatim}
\end{kframe}
\end{knitrout}
\pause
${\color{purple}{response}} = {\color{blue}{A}} + {\color{red}{D}} \times {\color{orange}{predictor}} + {\color{gray}{\epsilon}}$
\end{frame}
%%%%%%%%%%%
\begin{frame}[fragile]{Fit a t-test in R: \texttt{t.test()}}
\textbf{Compare C3 and C4 plants in “Low Variation” subset}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
t.test(rrarea~Plant_type, data=resp_L, var.equal=TRUE)
\end{verbatim}
\end{kframe}
\end{knitrout}
\end{frame}
%%%%%%%%%%%
\begin{frame}[fragile]{Fit an anova in R: \texttt{aov()}}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
aov1 <- aov(rrarea~Plant_type, data=resp_H)
summary(aov1)
\end{verbatim}
\end{kframe}
\end{knitrout}
\vspace{-0.15cm}
\pause
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.9, 0.9, 0.969}\color{fgcolor}\begin{kframe}
\footnotesize
\begin{verbatim}
Df Sum Sq Mean Sq F value Pr(>F)
Plant_type 1 0.817 0.8171 0.879 0.37
Residuals 10 9.292 0.9292
\end{verbatim}
\end{kframe}
\end{knitrout}
\pause
${\color{purple}{response}} = {\color{blue}{A}} + {\color{red}{D}} \times {\color{orange}{predictor}} + {\color{gray}{\epsilon}}$
\end{frame}
%%%%%%%%%%%
\begin{frame}[fragile]{Fit a linear model in R: \texttt{lm()}}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
lm1<-lm(rrarea ~ Plant_type, data = resp_L)
summary(lm1)
\end{verbatim}
\end{kframe}
\end{knitrout}
\vspace{-0.15cm}
\pause
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.9, 0.9, 0.969}\color{fgcolor}\begin{kframe}
\footnotesize
\begin{verbatim}
lm(formula = rrarea ~ Plant_type, data = resp_H)
Residuals:
Min 1Q Median 3Q Max
-1.7380 -0.4201 -0.1437 0.6706 1.6754
Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) 2.7200 0.3935 6.912 4.13e-05 ***
Plant_typeC4 0.5219 0.5565 0.938 0.37
---
Signif. codes: 0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
Residual standard error: 0.9639 on 10 degrees of freedom
Multiple R-squared: 0.08083, Adjusted R-squared: -0.01109
F-statistic: 0.8794 on 1 and 10 DF, p-value: 0.3705
\end{verbatim}
\end{kframe}
\end{knitrout}
\pause
${\color{purple}{response}} = {\color{blue}{A}} + {\color{red}{D}} \times {\color{orange}{predictor}} + {\color{gray}{\epsilon}}$
\end{frame}
%%%%%%%%%%%
\begin{frame}[fragile]{Fit a linear model in R: \texttt{lm()}}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\begin{verbatim}
library(emmeans)
emmeans(lm1, ~Plant_type)
\end{verbatim}
\end{kframe}
\end{knitrout}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.9, 0.9, 0.969}\color{fgcolor}\begin{kframe}
\footnotesize
\begin{verbatim}
Plant_type emmean SE df lower.CL upper.CL
C3 2.720021 0.3935305 10 1.843180 3.596861
C4 3.241916 0.3935305 10 2.365076 4.118757
Confidence level used: 0.95
\end{verbatim}
\end{kframe}
\end{knitrout}
\pause
${\color{purple}{response}} = {\color{blue}{A}} + {\color{red}{D}} \times {\color{orange}{predictor}} + {\color{gray}{\epsilon}}$
\end{frame}
%%%%%%%%%%%
\begin{frame}{Compare the output from t.test, aov and lm}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{Three equivalent ways to look at data}
\centering
\only<1>{T-test, focus on difference between two means\\
\includegraphics[width=0.8\textwidth]{Figures/figure/ttestrep-1}}
\only<2>{ANOVA, focus on variation within VS. between\\
\includegraphics[width=0.8\textwidth]{Figures/figure/aovrep-1}}
\only<3>{Linear regression, focus on rate of change\\
\includegraphics[width=0.8\textwidth]{Figures/figure/lmrep-1}}
\end{frame}
%%%%%%%%%%%%
\begin{frame}{All is one\dots}
\pause
\begin{block}{\dots but \texttt{lm()} rules (IMHO)}
\begin{itemize}
\item t-test, ANOVA, regression and others can be mathematically equivalent
\item In R, \texttt{lm()} and related functions can do them all\dots
\item \dots and much more!
\end{itemize}
\end{block}
\end{frame}
%%%%%%%%%%%
\begin{frame}{All is one\dots}
\centering
\includegraphics[width=0.8\textwidth]{Figures/modeldecision}\\
ALL can be done as linear models
\end{frame}
%%%%%%%%%%%
% more on LM, general steps, and another example
\begin{frame}{Focus on linear models}
\textbf{{\color{purple}{Response}} = {\color{blue}{Intercept}} + {\color{red}{Slope}} $\times$ {\color{orange}{Predictor}} + {\color{gray}{Error}}} \\
\centering
\includegraphics[width=0.6\textwidth]{Figures/figure/lmprinc-1}
\end{frame}
%%%%%%%%%%%%
\begin{frame}[fragile]{A simple linear model}
\textbf{{\color{purple}{Response}} = {\color{blue}{Intercept}} + {\color{red}{Slope}} $\times$ {\color{orange}{Predictor}} + {\color{gray}{Error}}} \\
\vspace{-0.1cm}
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\footnotesize
\begin{verbatim}
lm(response ~ 1 + predictor1 + predictor2, data=data)
\end{verbatim}
\end{kframe}
\end{knitrout}
equivalent to
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\footnotesize
\begin{verbatim}
lm(response ~ predictor1 + predictor2, data=data) \end{verbatim}
\end{kframe}
\end{knitrout}
equivalent to
\begin{knitrout}
\definecolor{shadecolor}{rgb}{0.969, 0.969, 0.969}\color{fgcolor}\begin{kframe}
\footnotesize
\begin{verbatim}
lm(response ~ predictor2 + predictor1, data=data) \end{verbatim}
\end{kframe}
\end{knitrout}
\begin{itemize}
\item Intercept can be explicit or implicit
\item Can remove intercept with \texttt{\dots $\sim $ 0 + \dots}
\item Error is implicit
\item Feed the option \texttt{data=} to keep code short, reliable and flexible
\item Order of predictors do not matter
\end{itemize}
\end{frame}
%%%%%%%%%%%
\section{Another look at essential steps}