an introduction to r: basic statistics with...
TRANSCRIPT
![Page 1: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/1.jpg)
An introduction to R:Basic Statistics with R
Noemie Becker, Benedikt Holtmann & Dirk Metzler 1
[email protected] - [email protected]
Winter semester 2016-17
1Special thanks to: Prof. Dr. Martin Hutzenthaler and Dr. Sonja Grath forcourse development
![Page 2: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/2.jpg)
1 Theory of statistical tests
2 Student T test: reminder
3 T test in R
4 Power of a test
5 Questions for the exam
![Page 3: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/3.jpg)
Theory of statistical tests
Contents
1 Theory of statistical tests
2 Student T test: reminder
3 T test in R
4 Power of a test
5 Questions for the exam
![Page 4: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/4.jpg)
Theory of statistical tests
A simple example
You want to show that a treatment is effective.
You have data for 2 groups of patients with and withouttreatment.80% patients with treatment recovered whereas only 30%patients without recovered.A pessimist would say that this just happened by chance.What do you do to convince the pessimist?You assume he is right and you show that under thishypothesis the data would be very unlikely.
![Page 5: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/5.jpg)
Theory of statistical tests
A simple example
You want to show that a treatment is effective.You have data for 2 groups of patients with and withouttreatment.
80% patients with treatment recovered whereas only 30%patients without recovered.A pessimist would say that this just happened by chance.What do you do to convince the pessimist?You assume he is right and you show that under thishypothesis the data would be very unlikely.
![Page 6: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/6.jpg)
Theory of statistical tests
A simple example
You want to show that a treatment is effective.You have data for 2 groups of patients with and withouttreatment.80% patients with treatment recovered whereas only 30%patients without recovered.
A pessimist would say that this just happened by chance.What do you do to convince the pessimist?You assume he is right and you show that under thishypothesis the data would be very unlikely.
![Page 7: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/7.jpg)
Theory of statistical tests
A simple example
You want to show that a treatment is effective.You have data for 2 groups of patients with and withouttreatment.80% patients with treatment recovered whereas only 30%patients without recovered.A pessimist would say that this just happened by chance.What do you do to convince the pessimist?
You assume he is right and you show that under thishypothesis the data would be very unlikely.
![Page 8: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/8.jpg)
Theory of statistical tests
A simple example
You want to show that a treatment is effective.You have data for 2 groups of patients with and withouttreatment.80% patients with treatment recovered whereas only 30%patients without recovered.A pessimist would say that this just happened by chance.What do you do to convince the pessimist?You assume he is right and you show that under thishypothesis the data would be very unlikely.
![Page 9: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/9.jpg)
Theory of statistical tests
In statistical words
What you want to show is the alternative hypothesis H1.The pessimist (by chance) is the null hypothesis H0.
Show that the observation and everything more ’extreme’ issufficiently unlikely under this null hypothesis. Scientistshave agreed that it suffices that this probability is at most5%.This refutes the pessimist. Statistical language: We rejectthe null hypothesis on the significance level 5%.p = P(observation and everything more ’extreme’ /H0 istrue )
If the p value is over 5% you say you cannot reject the nullhypothesis.
![Page 10: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/10.jpg)
Theory of statistical tests
In statistical words
What you want to show is the alternative hypothesis H1.The pessimist (by chance) is the null hypothesis H0.Show that the observation and everything more ’extreme’ issufficiently unlikely under this null hypothesis. Scientistshave agreed that it suffices that this probability is at most5%.This refutes the pessimist. Statistical language: We rejectthe null hypothesis on the significance level 5%.
p = P(observation and everything more ’extreme’ /H0 istrue )
If the p value is over 5% you say you cannot reject the nullhypothesis.
![Page 11: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/11.jpg)
Theory of statistical tests
In statistical words
What you want to show is the alternative hypothesis H1.The pessimist (by chance) is the null hypothesis H0.Show that the observation and everything more ’extreme’ issufficiently unlikely under this null hypothesis. Scientistshave agreed that it suffices that this probability is at most5%.This refutes the pessimist. Statistical language: We rejectthe null hypothesis on the significance level 5%.p = P(observation and everything more ’extreme’ /H0 istrue )
If the p value is over 5% you say you cannot reject the nullhypothesis.
![Page 12: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/12.jpg)
Theory of statistical tests
Statistical tests in R
There is a huge variety of statistical tests that you can performin R.We will cover on example of test in this lecture.
![Page 13: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/13.jpg)
Student T test: reminder
Contents
1 Theory of statistical tests
2 Student T test: reminder
3 T test in R
4 Power of a test
5 Questions for the exam
![Page 14: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/14.jpg)
Student T test: reminder
T test main idea
We have measured a variable in one or two samples and wewant to test:
One-sample: test if the mean is equal to a certain value(often 0)Two-samples: test if the two means are different
In case of two samples there are several possibilities:The same individuals are measured twice (ex: before andafter a treatment): paired T testIndependent samples: unpaired T test
In case of unpaired there are several possibilities:Variance in the two samples is assumed equalVariance in the two samples is not assumed equal
![Page 15: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/15.jpg)
Student T test: reminder
T test main idea
We have measured a variable in one or two samples and wewant to test:
One-sample: test if the mean is equal to a certain value(often 0)Two-samples: test if the two means are different
In case of two samples there are several possibilities:The same individuals are measured twice (ex: before andafter a treatment): paired T testIndependent samples: unpaired T test
In case of unpaired there are several possibilities:Variance in the two samples is assumed equalVariance in the two samples is not assumed equal
![Page 16: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/16.jpg)
Student T test: reminder
T test main idea
We have measured a variable in one or two samples and wewant to test:
One-sample: test if the mean is equal to a certain value(often 0)Two-samples: test if the two means are different
In case of two samples there are several possibilities:The same individuals are measured twice (ex: before andafter a treatment): paired T testIndependent samples: unpaired T test
In case of unpaired there are several possibilities:Variance in the two samples is assumed equalVariance in the two samples is not assumed equal
![Page 17: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/17.jpg)
Student T test: reminder
More details about the One-sample T test
Given: Observations
X1,X2, . . . ,Xn
Null hypothesis H0: µX = c (We test for a value c, usuallyc = 0)Level of significance: α (usually α = 5%)Test: t-Test
Compute test statistic
t :=X − c
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 18: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/18.jpg)
Student T test: reminder
More details about the One-sample T test
Given: Observations
X1,X2, . . . ,Xn
Null hypothesis H0: µX = c (We test for a value c, usuallyc = 0)Level of significance: α (usually α = 5%)
Test: t-TestCompute test statistic
t :=X − c
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 19: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/19.jpg)
Student T test: reminder
More details about the One-sample T test
Given: Observations
X1,X2, . . . ,Xn
Null hypothesis H0: µX = c (We test for a value c, usuallyc = 0)Level of significance: α (usually α = 5%)Test: t-Test
Compute test statistic
t :=X − c
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 20: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/20.jpg)
Student T test: reminder
More details about the One-sample T test
Given: Observations
X1,X2, . . . ,Xn
Null hypothesis H0: µX = c (We test for a value c, usuallyc = 0)Level of significance: α (usually α = 5%)Test: t-Test
Compute test statistic
t :=X − c
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 21: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/21.jpg)
Student T test: reminder
More details about the paired T test
Given: paired observations
(Y1,Z1), (Y2,Z2), . . . , (Yn,Zn)
Null hypothesis H0: µY = µZ
Level of significance: α (usually α = 5%)Test: paired t-Test (more precisely: two-sided paired t-Test)
Compute the difference X := Y − ZCompute test statistic
t :=X
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 22: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/22.jpg)
Student T test: reminder
More details about the paired T test
Given: paired observations
(Y1,Z1), (Y2,Z2), . . . , (Yn,Zn)
Null hypothesis H0: µY = µZ
Level of significance: α (usually α = 5%)
Test: paired t-Test (more precisely: two-sided paired t-Test)Compute the difference X := Y − ZCompute test statistic
t :=X
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 23: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/23.jpg)
Student T test: reminder
More details about the paired T test
Given: paired observations
(Y1,Z1), (Y2,Z2), . . . , (Yn,Zn)
Null hypothesis H0: µY = µZ
Level of significance: α (usually α = 5%)Test: paired t-Test (more precisely: two-sided paired t-Test)
Compute the difference X := Y − ZCompute test statistic
t :=X
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 24: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/24.jpg)
Student T test: reminder
More details about the paired T test
Given: paired observations
(Y1,Z1), (Y2,Z2), . . . , (Yn,Zn)
Null hypothesis H0: µY = µZ
Level of significance: α (usually α = 5%)Test: paired t-Test (more precisely: two-sided paired t-Test)
Compute the difference X := Y − ZCompute test statistic
t :=X
s(X )/√
n
p-value = Pr(|Tn−1| ≥ |t |) (n − 1 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 25: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/25.jpg)
Student T test: reminder
More details about the unpaired T test withequal varianceGiven: unpaired observations
X1,X2, . . . ,XnandY1,Y2, . . . ,Ym
Null hypothesis H0: µX = µYLevel of significance: α (usually α = 5%)Test: unpaired t-Test (more precisely: two-sided unpaired t-Test)
Compute common variance of the sample
s2p =
(n − 1) · s2X + (m − 1) · s2
Ym + n − 2
Compute test statistic
t =X − Y
sp ·√
1n + 1
m
p-value = Pr(|Tn+m−2| ≥ |t |) (n + m − 2 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 26: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/26.jpg)
Student T test: reminder
More details about the unpaired T test withequal varianceGiven: unpaired observations
X1,X2, . . . ,XnandY1,Y2, . . . ,Ym
Null hypothesis H0: µX = µYLevel of significance: α (usually α = 5%)
Test: unpaired t-Test (more precisely: two-sided unpaired t-Test)Compute common variance of the sample
s2p =
(n − 1) · s2X + (m − 1) · s2
Ym + n − 2
Compute test statistic
t =X − Y
sp ·√
1n + 1
m
p-value = Pr(|Tn+m−2| ≥ |t |) (n + m − 2 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 27: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/27.jpg)
Student T test: reminder
More details about the unpaired T test withequal varianceGiven: unpaired observations
X1,X2, . . . ,XnandY1,Y2, . . . ,Ym
Null hypothesis H0: µX = µYLevel of significance: α (usually α = 5%)Test: unpaired t-Test (more precisely: two-sided unpaired t-Test)
Compute common variance of the sample
s2p =
(n − 1) · s2X + (m − 1) · s2
Ym + n − 2
Compute test statistic
t =X − Y
sp ·√
1n + 1
m
p-value = Pr(|Tn+m−2| ≥ |t |) (n + m − 2 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 28: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/28.jpg)
Student T test: reminder
More details about the unpaired T test withequal varianceGiven: unpaired observations
X1,X2, . . . ,XnandY1,Y2, . . . ,Ym
Null hypothesis H0: µX = µYLevel of significance: α (usually α = 5%)Test: unpaired t-Test (more precisely: two-sided unpaired t-Test)
Compute common variance of the sample
s2p =
(n − 1) · s2X + (m − 1) · s2
Ym + n − 2
Compute test statistic
t =X − Y
sp ·√
1n + 1
m
p-value = Pr(|Tn+m−2| ≥ |t |) (n + m − 2 degrees of freedom)Reject null hypothesis, if p-value ≤ α
![Page 29: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/29.jpg)
T test in R
Contents
1 Theory of statistical tests
2 Student T test: reminder
3 T test in R
4 Power of a test
5 Questions for the exam
![Page 30: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/30.jpg)
T test in R
Function t.test()
The function used in R is called t.test().
?t.test
t.test(x, y = NULL,
alternative = c("two.sided", "less", "greater"),
mu = 0, paired = FALSE, var.equal = FALSE,
conf.level = 0.95, ...)
![Page 31: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/31.jpg)
T test in R
Martian example
Dataset containing height of martian of different colours.See the code on the R console.
We cannot reject the null hypothesis.It was an unpaired test because the two samples areindependent.
![Page 32: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/32.jpg)
T test in R
Martian example
Dataset containing height of martian of different colours.See the code on the R console.
We cannot reject the null hypothesis.It was an unpaired test because the two samples areindependent.
![Page 33: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/33.jpg)
T test in R
Shoe example
Dataset containing wear of shoes of 2 materials A and B. Thesame persons have weared the two types of shoes and we havea measure of use of the shoes.
Paired test because some persons will cause more damage tothe shoe than others.See the code on the R console.
We can reject the null hypothesis.
![Page 34: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/34.jpg)
T test in R
Shoe example
Dataset containing wear of shoes of 2 materials A and B. Thesame persons have weared the two types of shoes and we havea measure of use of the shoes.Paired test because some persons will cause more damage tothe shoe than others.See the code on the R console.
We can reject the null hypothesis.
![Page 35: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/35.jpg)
T test in R
Shoe example
Dataset containing wear of shoes of 2 materials A and B. Thesame persons have weared the two types of shoes and we havea measure of use of the shoes.Paired test because some persons will cause more damage tothe shoe than others.See the code on the R console.
We can reject the null hypothesis.
![Page 36: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/36.jpg)
Power of a test
Contents
1 Theory of statistical tests
2 Student T test: reminder
3 T test in R
4 Power of a test
5 Questions for the exam
![Page 37: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/37.jpg)
Power of a test
Definition
There are two types of error for a statistical test:Type I error (or first kind or alpha error or false positive):rejecting H0 when it is true.
Type II error (or second kind or beta error or false negative):failing to reject H0 when it is not true.
Power of a test = 1 - βIf power=0: you will never reject H0.The choice of H1 is important because it will influence the power.In general the power increases with sample size.
![Page 38: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/38.jpg)
Power of a test
Definition
There are two types of error for a statistical test:Type I error (or first kind or alpha error or false positive):rejecting H0 when it is true.Type II error (or second kind or beta error or false negative):failing to reject H0 when it is not true.
Power of a test = 1 - βIf power=0: you will never reject H0.The choice of H1 is important because it will influence the power.In general the power increases with sample size.
![Page 39: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/39.jpg)
Power of a test
Definition
There are two types of error for a statistical test:Type I error (or first kind or alpha error or false positive):rejecting H0 when it is true.Type II error (or second kind or beta error or false negative):failing to reject H0 when it is not true.
Power of a test = 1 - βIf power=0: you will never reject H0.
The choice of H1 is important because it will influence the power.In general the power increases with sample size.
![Page 40: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/40.jpg)
Power of a test
Definition
There are two types of error for a statistical test:Type I error (or first kind or alpha error or false positive):rejecting H0 when it is true.Type II error (or second kind or beta error or false negative):failing to reject H0 when it is not true.
Power of a test = 1 - βIf power=0: you will never reject H0.The choice of H1 is important because it will influence the power.In general the power increases with sample size.
![Page 41: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/41.jpg)
Power of a test
Power in R
Use the functions power.t.test() to calculate the minimalsample size needed to show a certain difference.
We will try this with the following example:
We know there is a third colour of martians (yellow) and wewant to test whether their size is different from that of thegreen ones (64 cm).We assume they have the same standard deviation in size(8 cm).We would like to be able to find significant a difference of 5cm with power 90%.
What is the planned test?One-sample t test.
![Page 42: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/42.jpg)
Power of a test
Power in R
Use the functions power.t.test() to calculate the minimalsample size needed to show a certain difference.We will try this with the following example:
We know there is a third colour of martians (yellow) and wewant to test whether their size is different from that of thegreen ones (64 cm).We assume they have the same standard deviation in size(8 cm).We would like to be able to find significant a difference of 5cm with power 90%.
What is the planned test?
One-sample t test.
![Page 43: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/43.jpg)
Power of a test
Power in R
Use the functions power.t.test() to calculate the minimalsample size needed to show a certain difference.We will try this with the following example:
We know there is a third colour of martians (yellow) and wewant to test whether their size is different from that of thegreen ones (64 cm).We assume they have the same standard deviation in size(8 cm).We would like to be able to find significant a difference of 5cm with power 90%.
What is the planned test?One-sample t test.
![Page 44: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/44.jpg)
Power of a test
Power in R
One-sample t test.power.t.test(n=NULL, delta=5, sd=8,
sig.level=0.005,power=0.9, type="one.sample",
alternative="two.sided")
One-sample t test power calculation
n = 46.77443
delta = 5
sd = 8
sig.level = 0.005
power = 0.9
alternative = two.sided
![Page 45: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/45.jpg)
Power of a test
Power in R
One-sample t test.power.t.test(n=NULL, delta=5, sd=8,
sig.level=0.005,power=0.9, type="one.sample",
alternative="two.sided")
One-sample t test power calculation
n = 46.77443
delta = 5
sd = 8
sig.level = 0.005
power = 0.9
alternative = two.sided
![Page 46: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/46.jpg)
Questions for the exam
Contents
1 Theory of statistical tests
2 Student T test: reminder
3 T test in R
4 Power of a test
5 Questions for the exam
![Page 47: An introduction to R: Basic Statistics with Revol.bio.lmu.de/_statgen/Rcourse/ws1617/slides/Day9_BasicStat_lect… · An introduction to R: Basic Statistics with R Noemie Becker,](https://reader034.vdocuments.site/reader034/viewer/2022052009/601e267a368cab3dd20c3247/html5/thumbnails/47.jpg)
Questions for the exam
Questions for the exam
The exam will be on paper (no computer).You still need to know the precise commands and scriptstructureYou are allowed to bring a two-sided A4 formula sheet (onyour own handwriting only).The exam takes place on Friday at 10am in B00.019Be on time!
Do you have questions?