You are on page 1of 39

Biostatistics

Hypothesis tests.
One-sample and paired t-tests.

Ferenc Rárosi PhD and Krisztina Boda PhD


Department of Medical Physics and Informatics,
University of Szeged
Sample and statistical population

◼ Sample data set ◼ Population


▪ Questionnaire filled ▪ Pharmacy students
in by a group of ▪ Students
pharmacy students
▪ Blood pressure of ▪ Blood pressure of
20 healthy women women (whoever)
▪… ▪…

Krisztina Boda Biostat 4. 2


Sample Population
(approximates)
◼ Mean  (unknown)
◼ Mean x (known)
◼ Standard deviation 
◼ Standard deviation (SD) (unknown)
(known)
◼ Median (unknown)
◼ Median (known)
Body height
30

20

10
Frequency

Std. Dev = 8.52


Mean = 170.4
0 N = 87.00
150.0 160.0 170.0 180.0 190.0
155.0 165.0 175.0 185.0 195.0

Body height

Krisztina Boda Biostat 4. 3


Motivating example
◼ Two lecturers argue about the mean age of the first year
medical students.
▪ Lecturer#1 claims that the mean age of the first year medical
students is 20.
▪ Lecturer#2 does not agree.
▪ Who is right?
◼ Statistically speaking: the population is the set of ALL
first year medical students (anywhere, any time).
◼ Lecturer#1 claims that the population mean μ=20.
◼ Lecturer#2 claims that the population mean μ ≠ 20

Krisztina Boda 4
Question: which of the following hyptheses to accept
H0: population mean µ=20
Ha: population mean µ≠20.
How to find the answer?
◼ To be sure, we have two know the age of the TOTAL population
(impossible)
◼ To be confident, we draw a sample from the population (i.e., get the
age of some first year medical students). n=137
◼ Calculate mean age of the sample: x = 20.87
◼ If the sample is representative, we believe that the sample mean
approximates the population mean: x ~ 
◼ To be 95% confident, calculate the 95% confidence interval for the
population mean: 95% CI: (20.35-21.39)
◼ We are 95% confident, that if true population mean (i.e. the mean age
of the ALL first year medical students) were known, it would lie
somewhere between 20.35 and 21.39.
◼ Answer: ??

Krisztina Boda 5
Hypothesis testing
Hypothesis testing

◼ Hypothesis: a statement about the


population.
◼ Based on our data (sample) we conclude to
the whole phenomenon (population).
◼ We examine whether our result (difference
in samples) is greater then the difference
caused only by chance.

Krisztina Boda 7
Hypothesis
◼ Hypothesis: a statement about the population.
◼ Examples
▪ H1: p=0.5 (a coin is fair - half the flips would result in Heads and half, in
Tails)
▪ H2: p≠0.5 ( a coin is not fair)
▪ H3: =20 (the population mean is 20)
▪ H4:  ≠20 (the population mean is not 20)
◼ Statisticians usually test the hypothesis which tells them what to
expect by giving a specific value to work with. They refer to this
hypothesis as the null hypothesis and symbolize it as H0.
◼ The null hypothesis is often the one that assumes fairness, honesty,
regularity, lack of effect, lack of correlation, independence or
equality.
◼ The opposite hypothesis is called alternative hypothesis and is
symbolized by Ha. This hypothesis, however, is often the one that is
of interest. (Often called the research hypothesis. The claim to be
tested.)

Krisztina Boda 8
Steps of hypothesis-testing
◼ Step 1. State the motivated (alternative) hypothesis Ha (Involves
the claim to be tested).
◼ Step 2. State the null hypothesis H0.
◼ Step 3. Select the , the probability of Type I error, or the α
significance level. α =0.05 or α =0.01.
◼ Step 4. Choose the size n of the random sample. (Hard math
problem.)
◼ Step 5. Select a random sample from the appropriate population
and obtain your data.
◼ Step 6. Calculate the decision rule –it depends on problem,
assumptions, type of data, etc...
◼ Step 7. Decision.
▪ a) Reject the null hypothesis (accept the alternative hypothesis) and say:
the difference is significant at α100% level.
▪ b) Fail to reject the null hypothesis (accept it) and say:
the difference is not significant at α 100% level.

Krisztina Boda 9
Testing the mean  of a sample drawn from a
normal population: one-sample t-test

◼ H0: =c , c is a given constant


◼ Ha: c
◼ Decision rules (equivalent) based on
▪ confidence interval
▪ test statistic (t-value) and critical value
▪ p-value

Krisztina Boda 10
Decision rule based on confidence interval

◼ Calculate the (1- α )100% confidence interval for the population


mean.
Decision rule: check whether the hypothesised mean (c) is in
the interval or not
◼ Decision.
▪ a) if c is not in the interval, we reject the null hypothesis and claim
that the alternative hypothesis was correct the difference is significant at
5% level.
▪ b) if c is in the interval, we fail to reject the null hypothesis (we accept
it) and claim that your null hypothesis was correct, the difference is not
significant at 5% level.

Krisztina Boda 11
Two-sided alfa

Decision rule based on t-value df


1
2
3
0.2
3.078
1.886
1.638
0.1
6.314
2.920
2.353
0.05
12.706
4.303
3.182
0.02
31.821
6.965
4.541
0.01
63.657
9.925
5.841
0.001
636.619
31.599
12.924
4 1.533 2.132 2.776 3.747 4.604 8.610
5 1.476 2.015 2.571 3.365 4.032 6.869
6 1.440 1.943 2.447 3.143 3.707 5.959
◼ Calculate the decision rule. 7 1.415 1.895 2.365 2.998 3.499 5.408
8 1.397 1.860 2.306 2.896 3.355 5.041
▪ Calculate the following formula (called test-statistic): 9
10
1.383
1.372
1.833
1.812
2.262
2.228
2.821
2.764
3.250
3.169
4.781
4.587

x−c
11 1.363 1.796 2.201 2.718 3.106 4.437
12 1.356 1.782 2.179 2.681 3.055 4.318
t= 13
14
1.350
1.345
1.771
1.761
2.160
2.145
2.650
2.624
3.012
2.977
4.221
4.140
SE 15 1.341 1.753 2.131 2.602 2.947 4.073
16 1.337 1.746 2.120 2.583 2.921 4.015


17 1.333 1.740 2.110 2.567 2.898 3.965
If H0 is true, this test-statistic has a t-distribution with n-1 18 1.330 1.734 2.101 2.552 2.878 3.922
19 1.328 1.729 2.093 2.539 2.861 3.883
degrees of freedom. 20 1.325 1.725 2.086 2.528 2.845 3.850
21 1.323 1.721 2.080 2.518 2.831 3.819
22 1.321 1.717 2.074 2.508 2.819 3.792
23 1.319 1.714 2.069 2.500 2.807 3.768
▪ The acceptance (non-rejection) interval is the set of values for 24
25
1.318
1.316
1.711
1.708
2.064
2.060
2.492
2.485
2.797
2.787
3.745
3.725
which we accept the null hypothesis (- ttable, ttable) 26
27
1.315
1.314
1.706
1.703
2.056
2.052
2.479
2.473
2.779
2.771
3.707
3.690
▪ ttable is the critical t-value in the Student t-table in the row of df 28
29
1.313
1.311
1.701
1.699
2.048
2.045
2.467
2.462
2.763
2.756
3.674
3.659
and in the column of . 30

1.310
1.282
1.697
1.645
2.042
1.960
2.457
2.326
2.750
2.576
3.646
3.291

▪ The critical interval (rejection interval) is the set of values for


which the null hypothesis is rejected.

▪ Decision rule: check whether the calculated t-value (t) is in


the acceptance interval or not
◼ Decision:
▪ if the calculated t is not in the acceptance region
(t> ttable or t< - ttable, i.e, |t|>ttable ),,
we reject H0 and say that the difference is significant at α level
▪ if t is in the acceptance interval
(- ttable<t< ttable, i.e. |t|<ttable), ,
we accept H0 and say the difference is not significant at α level
Acceptance interval

Krisztina Boda 12
Decision rule based on t-value, example
◼ Calculate the decision rule. y=student(x;136)
▪ Calculate the test-statistic: 0.5 1.0
x − c 20.87 − 20
t= = = 3.321
SE 0.262 0.4 0.8

▪ If H0 is true, this test-statistic has a t-distribution with n-1


degrees of freedom. 0.3 0.6

▪ If =0.05 and df=136, the critical t-value ( t or ttable)=1.977


0.2 0.4
The acceptance (non-rejection) interval is the set of values for
which we accept the null hypothesis (- 1.977, 1.977)
0.1 0.2

▪ The critical interval (rejection interval) is the set of values for


which the null hypothesis is rejected.
0.0 0.0
-3 -2 -1 0 1 2 3 -3

▪ Decision rule: check whether the calculated t-value (t) is in


the acceptance interval or not Acceptance interval
◼ Step 7. Decision:
▪ Our calculated t=3.321, it is not in the acceptance interval, t=3.321
3.321>1.977, |t|>ttable,
▪ so we decide to reject H0 and say: the difference is significant
at 5% level

Krisztina Boda 13
Decision rule based on p-value
◼ p-value (calculated by computer): it is the two
tailed tail area under the curve cut by our
calculated t-value
◼ It is the probability of obtaining a test statistic at
least as extreme as the one that was actually
observed, assuming that the null hypothesis is
true.
◼ Decision:
▪ If p<, we decide that the difference is significant
at  100% level
▪ If p>, we decide that the difference is not
significant at  100% level

◼ Decision, example:
▪ p=0.001152 (red shaded area).
▪ p<0.05, Acceptance interval
we decide to reject H0 and say: the difference is t=3.321
significant at 5% level p=.001152

Krisztina Boda 14
Decision rule based on p-value
◼ p-value (calculated by computer): it is the two
tailed tail area under the curve cut by our
calculated t-value
◼ It is the probability of obtaining a test statistic at
least as extreme as the one that was actually
observed, assuming that the null hypothesis is
true.
◼ Decision:
▪ If p<, we decide that the difference is significant
at  100% level
▪ If p>, we decide that the difference is not
significant at  100% level

◼ Decision, example:
▪ p=0.001152 (red shaded area).
▪ p<0.05, Acceptance interval
we decide to reject H0 and say: the difference is t=3.321
significant at 5% level p=.001152

Krisztina Boda 15
Summary of the equivalent decision rules for one-sample t-test
Assumption: normality (the sample is drawn from a normal distribution)
1. H0: =c, (c given constant).
2. Ha: c.
3. Select 
4. Find the sample size n
5. Select a random sample x1 , x2 ,..., xn ., calculate the sample mean and SD
6. The decision rule:

Confidence Critical points p-value


interval (t-value)
Decision rules ( x −t
s
,x +t
s x −c x −c p-values are
n n
) t= =
SD SE calculated by
n computer
programs
t/2= critical two-tailed t-value from t-table

7. Decision:
Decision
Confidence Critical points p-value
interval (t-value)
a) Ha : reject H0, the confidence
the difference is interval does not t  t p<
significant at 100%- contain c
level.
a) H0 : do not reject H0, the confidence
the difference is interval contains the t  t p>
not significant at value c
100%-level.

Krisztina Boda 16
SPSS result
One-Sample Statistics
Std. Error
N Mean Std. Deviation Mean
Age Age in years 137 20.87 3.071 .262

One-Sample Test
Test Value = 20
95% Confidence
Interval of the
Mean Difference
t df Sig. (2-tailed) Difference Lower Upper
Age Age in years 3.324 136 .001 .872 .35 1.39

p-value,
To decide based on t-value If p<, the difference is significant,
and degrees of freedom, If p>, the difference is not significant.
we need a t-table Now p=0.001<0.05 the difference
is significant at 5% level

Krisztina Boda 17
Results using R
> t.test(Age,mu=20)

One Sample t-test

data: Age
t = 3.324, df = 136, p-value = 0.00114
alternative hypothesis: true mean is not equal to 20
95 percent confidence interval:
20.35332 21.39120
sample estimates:
mean of x p-value
20.87226 If p<, the difference is
t-value (test statistic) significant at  level,
and degrees of freedom.
To decide, we need a t-
Confidence interval for the population’s
table mean. We check whether the constant of
the null hypothesis (=true mean) is in this
interval or not

Krisztina Boda 18
Krisztina Boda 19
One-sample t-test, example 2.
◼ A company produces a 16 ml bottle of some drug (solution). The
bottles are filled by an automated bottle-filling process. If this process is
substantially overfilling or under filling bottles, then this process must be
shut down and readjusted. Overfilling results in lost profits for the company,
while under filling is unfair to consumers. For a given adjustment of the
bottles consider the infinite population of all the bottle fills that could
potentially be produced. We let denote the mean of the infinite population
of all the bottle fills.
◼ The company has decided that it will shut down and readjust the process if
it can be very certain that the mean fill is above or below the desired 16 ml.
◼ Now suppose that the company observes the following sample of n=6 bottle
fills:
◼ 15.68, 16.00, 15.61, 15.93, 15.86, 15.72
◼ It can be verified that this sample has mean=15.8 and standard deviation
SD=0.156.
◼ Question: Is it „true” that the mean bottle fill in the population is 16?

HO: the population mean is16, =16


Ha: the population mean is not 16 , 16 (two tailed)
Krisztina Boda 20
Decision rule based on confidence
interval

Find the 95% confidence interval for the population mean:


=0.05, df=5, t5,0.05=2.57, sample mean=15.8, SD=0.153
SE=SD/ n=0.153/6.
95% CI: (sample mean – t5,0.05*SE, sample mean+ t5,0.05 * SE )=
(15.8-2.57* 0.153/6, 15.8-2.57* 0.153/6)
=(15.64, 15.96)
Decision:
The constant in H0 (16) is not in the confidence interval, so we decide to reject H0 and say
that the population mean is significantly different from 16 at 5% level.

Krisztina Boda 21
Decision rule based on t-value
◼ Calculate our t-statistic:

(15.8 − 16)
t= 6 = −3.2
0.153

◼ Degree of freedom: n-1=6-1=5


◼ Critical t-value in the table: t5,0.05=2.57:

◼ Decision: |-3.2|>2.57, our t-value lies outside the


acceptance region, we reject H0 and say that the
difference is significant at 5% level

t=-3.2

Krisztina Boda 22
Decision rule based on p-value
◼ p-value (calculated by computer): it
is the two tailed tail area under the
curve cut by our calculated t-value*
◼ It is the probability of obtaining a
test statistic at least as extreme as
the one that was actually observed,
assuming that the null hypothesis is
true
◼ Decision:
▪ If p<, we decide that the difference
is significant at  100% level
▪ If p>, we decide that the difference
is not significant at  100% level

◼ In our case: t=-3.2


p=0.024<0.05, the difference is significant
at 5% level

*When Ha:  c – two tailed test – see later


Krisztina Boda 23
|t|=3.2
df=5
p=0.024

probability
df 0.2 0.1 0.05 0.02 0.01 0.001
1 3.077684 6.313752 12.7062 31.82052 63.65674 636.6192
2 1.885618 2.919986 4.302653 6.964557 9.924843 31.59905
3 1.637744 2.353363 3.182446 4.540703 5.840909 12.92398
4 1.533206 2.131847 2.776445 3.746947 4.604095 8.610302
5 1.475884 2.015048 2.570582 3.36493 4.032143 6.868827
6 1.439756 1.94318 2.446912 3.142668 3.707428 5.958816
7 1.414924 1.894579 2.364624 2.997952 3.499483 5.407883
8 1.396815 1.859548 2.306004 2.896459 3.355387 5.041305
9 1.383029 1.833113 2.262157 2.821438 3.249836 4.780913
10 1.372184 1.812461 2.228139 2.763769 3.169273 4.586894
11 1.36343 1.795885 2.200985 2.718079 3.105807 4.436979
12 1.356217 1.782288 2.178813 2.680998 3.05454 4.317791
13 1.350171 1.770933 2.160369 2.650309 3.012276 4.220832
14 1.34503 1.76131 2.144787 2.624494 2.976843 4.140454
15 1.340606 1.75305 2.13145 2.60248 2.946713 4.072765

Krisztina Boda 24
1. H0: =c, (c given constant). H0: =16.
2. Ha: c. Ha:  16
3. Select  =0.05or =0.01
4. Find the sample size n n=6
5. Select a random sample x1 , x2 ,..., xn . 15.68, 16.00, 15.61, 15.93, 15.86, 15.72
6. The decision rule:

Confidence Critical points p-value


interval (t-value)
s s x −c x −c p
(x − t / 2 , x + t / 2 ) t= = and
n n SD SE (Sig. level
n Sig. 2 tail
find t Prob....)

(15.8 − 16) 2-tail Sig=0.024


0.1532 0.1532 t= 6 = −3.197
(15.8 − 2.57 ,15.8 + 2.57 ) = (15.639, 15.96) 0.1532
6 6 t2 =2.57

16 is not in the interval (15.64, 15.96) |t|> t


|-3.197|=3.197>2.57 0.024 < 0.05
the difference is significant at 5%-level

Krisztina Boda 25
A one-sample t test for paired differences
(paired t-test)
◼ Self-control experiment
◼ Related data:
▪ before treatment – after treatment
▪ left side – right side
▪ matched pairs.
◼ Null hypothesis: there is no treatment-effect, the
difference is only by chance
H0: before= after or difference= 0.
◼ Alternative hypothesis: there is a treatment effect
Ha: before≠ after or difference≠ 0.
◼ Assumption: the differences are normally distributed.

Krisztina Boda 26
Paired t-test, example
◼ A study was conducted to determine
weight loss, body composition, etc.
in obese women before and after 12 Before After Difference
weeks of treatment with a very-low- 85 86 -1
calorie diet .
95 90 5
◼ We wish to know if these data
provide sufficient evidence to allow 75 72 3
us to conclude that the treatment is 110 100 10
effective in causing weight reduction 81 75 6
in obese women. 92 88 4
◼ The mean difference is actually 4. Is 83 83 0
it a real difference? Big or small? If
the study were to be repeated, would 94 93 1
we get the same result or less, even 88 82 6
0? 105 99 6
◼ Idea: if the treatment is not effective, Mean 90.8 86.8 4
the mean sample difference is small SD 10.79 9.25 3.333
(close to 0), if it is effective, the mean
difference is big
◼ We perform a paired t-test the check
whether the mean difference is 0 in
the population

Krisztina Boda 27
Paired t-test, example (cont).
◼ H0: before= after or difference= 0 (c=0)!!
◼ Ha: before≠ after or difference≠ 0
◼ Let =0.05
◼ Degrees of freedom=10-1=9,
◼ ttable=t0.05,9=2.262
◼ Mean=4, SD=3.333
◼ SE=3.333/10=1.054
◼ 95%CI: (4-2.262*1.054, 4+2.262*1.054)=(1.615, 6.384). The mean
loss of body weight was 4 kg. We are 95% confident, that the true
population mean would be even 6.36 but minimum 1.615.
◼ Decision based on confidence interval: 0 is outside the confidence
interval, we decide to reject H0 and say, the difference is significant
at 5% level, the treatment was effective.

Krisztina Boda 28
◼ Decision based on test statistic
(t-value):
x−c x−0 4
t= = = = 3.795
SE SE 1.054
▪ This t has to be compared to
the critical t-value in the table.
▪ |t|=3.795>2.262(=t0.05,9), the
difference is significant at 5%
level
◼ Decision based on p-value:
▪ p=0.004, p<0.05, the
difference is significant at 5%
level Acceptance region
tcomputed, test statistic

ttable, critical value

Krisztina Boda 29
Results using SPSS

Krisztina Boda 30
Results using R
> hist(after-before)
> t.test(before, after, paired=TRUE)

Paired t-test

data: before and after


t = 3.7947, df = 9, p-value = 0.004252
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
1.615477 6.384523
sample estimates:
mean of the differences
4

Krisztina Boda 31
Example from the medical literature

Krisztina Boda 32
A few repetition

ABOUT THE BINOMIAL TEST

Krisztina Boda 33
Krisztina Boda 34
Krisztina Boda 35
Krisztina Boda 36
Krisztina Boda 37
Thank you for your attention!

Krisztina Boda 38
Review questions and problems
◼ What is a hypothesis
◼ Null-and alternative hypothesis
◼ Steps of hypothesis testing
◼ The null- and alternative hypothesis of the one-sample t-test
◼ The assumption of the one-sample t-test
◼ Decision rules of the one-sample t-test
◼ Testing significance based on a confidence interval
◼ Testing significance based on t-statistic
◼ Testing significance based on p-value
◼ Meaning of the p-value
◼ In a study, systolic blood pressure of 10 healthy women was measured. The mean
was 119, the standard error 0.664. Supposing that this sample was drawn from a
normal distribution, check whether the population mean is 125! (=0.05, ttable=2.26).
◼ To test the effect of a new drug, the systolic blood pressure was measured on the
same 5 patients before and after the treatment. The mean of the differences is = 6,
the standard error of the differences is SE=4.65. To test the effect of the drug, what
is the appropriate test? Find the value of the test statistics and decide whether the
difference is significant or not. ( =0.05, ttable=2.57)

Krisztina Boda 39

You might also like