The two-sample t-test and
the paired t-test
Review of steps in hypothesis testing
Copyright By PowCoder代写 加微信 powcoder
1. Specify null and alternative hypotheses.
2. Select a significance level α (acceptable Type I error).
3. Choose a test statistic: a single value to be calculated from data.
4. Collect data and calculate the test statistic.
5. Calculate the P-value: If it is less than α, reject the null hypothesis.
Versions of the t-test • One-sample t-test
– For hypotheses about the mean of a population • Two-sample t-test
– For hypotheses about the difference between the means of two populations.
• Paired t-test
– For hypotheses about the mean difference between two populations.
Two-sample t-test
Is the mean size of island lizards different from that of mainland ones?
Heath monitor lizard
Kangaroo Island
Null and alternative hypotheses
• H0: μA − μB = 0
The mean lengths of island and
mainland lizards are the same. • HA: μA − μB ≠ 0
The mean lengths of island and mainland lizards are different.
To carry out a two-sample t-test, you need two samples, one from each population
A sample of size nA from population A
A sample of size nB from population B
Test statistic for a one-sample t-test:
Test statistic for a two-sample t-test:
𝑋# − 𝜇 # 𝑠%$
𝑋# − 𝑋# − 𝜇 − 𝜇 ! ” ! ”
Central question for 2-sample test:
Is the true difference between 𝜇! and 𝜇” the same as the difference proposed by H0?
Simplified formula if the hypothesized difference is zero (the usual case):
𝑋# − 𝑋# !”
The standard error of the difference between the means (μA – μB)
Calculating 𝒔𝑿!𝑨#𝑿!𝑩 for a 2-sample t-test First, make this assumption:
The two populations have the same variance.
𝜎# =𝜎# “! “”
Represent both with the same symbol, σ2
Calculating 𝒔𝑿!𝑨#𝑿!𝑩 for a 2-sample t-test Next, estimate σ2
The best estimate of σ2 is the pooled variance, 𝒔𝟐𝒑
∑𝑋 −𝑋) &+∑𝑋 −𝑋) & 𝑠%&=’!’ (!(
𝑛’−1 + 𝑛(−1
Calculating 𝒔𝑿!𝑨#𝑿!𝑩 for a 2-sample t-test Finally, calculate 𝑠*)”+*)#
Standard error of the mean of a variable:
Standard error of the difference between means of two variables:
𝑠$# = 𝑠 = 𝑠% 𝑛𝑛
𝑠&’ 𝑠&’ 𝑠%$##%$$= 𝑛(+𝑛)
Summary: How to calculate t for the two-sample t-test
XA −XB s 2p + s 2p
are the sample averages. 𝑆&% is the pooled variance.
𝑛!and 𝑛” are the sample sizes.
𝑋& and 𝑋& !”
Calculate the P value
Prob ⎡⎣t < −tobs ⎤⎦ Prob ⎡⎣t > tobs ⎤⎦
–tobs tobs
P = the sum of these two probabilities (or 2×either one)
Question 1
How many degrees of freedom does a 2-sample t test have?
A.nA +nB B.nA +nB–1 C.nA +nB–2 D. (nA + nB)/2
nA + nB – 2. Start with the total number of independent observations (nA + nB) and subtract the number of parameters you needed to estimate (two: 𝜇! and 𝜇”).
Example of a 2-sample t-test
Take a random sample of each population.
XA (Mainland): 45.1, 40.8, 42.6, 50.8, 55.8, 45.6, 40.6, 39.0, 47.3, 44.0 XB (Island): 42.1, 33.7, 41.9, 39.2, 39.3, 46.4, 35.2, 35.8, 41.8, 49.0
nA = nB = 10 Calculate sample averages:
XA =45.16 XB =40.44 Calculate the pooled variance:
s2= (XAi −XA)+ (XBi −XB)=24.90
n −1+ n −1 ()()
Example of a 2-sample t-test Calculate sXA − XB
s2 s2 24.9 24.9
s = p+p= + =2.232
n n 10 10 AB
Calculate t
t=XA−XB =45.16−40.44=2.11
sXA−XB 2.232
Degrees of freedom
ν=nA +nB −2=18
Example of a 2-sample t-test P value
P = 2*(1–pt(t, ν)) = 2*(1–pt(2.11, 18)) = 0.049 Conclusion
At a significance level of 0.05, we reject the null hypothesis that the means are equal, in favor of the alternative that mainland lizards are larger (t-test: t18 = 2.11, P = 0.049).
The paired t-test
Versions of the t-test • One-sample t-test
– For hypotheses about the mean of a population • Two-sample t-test
– For hypotheses about the difference between the means of two populations.
• Paired t-test
– For hypotheses about the mean difference between two populations.
Blood pressure measured in a random sample of men and women
XF = 134.1
XM = 131.5
Female Male
Blood pressure (mm HG)
Question 2
Based on these data, do you think there is a difference in blood pressure between males and females?
XF = 134.1
XM = 131.5
Female Male
Blood pressure (mm HG)
New information: The data are sibling pairs
A line connects each brother and sister pair
XF = 134.1
XM = 131.5
Sister Brother
Blood pressure (mm HG)
Question 3
Based on these data, do you think there is a difference in blood pressure between males and females?
XF = 134.1
XM = 131.5
Family Sister
Blood pressure (mm HG)
Data are paired when each observation in one sample is uniquely associated with one observation in the other sample
Example: Blood pressure measurements from brother/sister pairs (mmHg)
Gender effect may be obscured by variation among families.
Family Sister
A paired t-test is a one-sample t-test in disguise
• The variable being tested is the difference (d) between the members of each pair.
• There is only one sample of differences (one from each pair).
Carrying out a paired t-test Basic strategy
• Take the difference d between each
• Perform a one- sample t-test on d.
FSeimstaelre
BrMoathleer
(Sister − Brother)
Null and alternative hypotheses
• H0:μd =0
The mean difference between males and females is zero (no gender effect on blood pressure).
• HA:μd ≠0
The mean difference between males and females is not zero (there is a gender effect on blood pressure).
Test statistic for the paired t-test
𝑑̅ − 𝜇(, 𝑠()
•d is the average of the observed differences.
•μd0 is the mean difference under the null hypothesis.
•sd is the standard error of the mean difference.
Calculate the test statistic
• Average difference 𝑑̅ = 2.6
• Sample standard deviation 𝑠 = 3.03
• Calculate 𝑠!”
• Calculate t 𝑡 = 𝑑̅ − 𝜇!!
𝑠-) = 10 = 0.96
𝑡 = 2.6 − 0 = 2.71 0.96
Calculate p-value from the t distribution
For this data set, how many degrees of freedom does the paired t-test have?
(Sister − Brother)
There are 9 degrees of freedom (the number of pairs minus 1).
P = 2*(1-pt(2.71, 9)) P = 0.024
Conclusion
At a significance level of 0.05, we reject the null hypothesis that mean difference in blood pressure between brothers and sisters equals zero (t9 = 2.71, p = 0.024).
Two-sample t-test vs. paired t-test
5.6 3.4 2.2
DoesμA−μB =0?
4.1 3.1 1.0 2.7 1.7 1.0
DoesμA−B =0?
4.9 4.8 0.1
2.3 1.4 0.9
Two-sample t-test vs. paired t-test
• If there is a logical basis for pairing, the paired test is better able to detect a true difference between the means.
• If there is no logical basis for pairing, use the two-sample test.
程序代写 CS代考 加微信: powcoder QQ: 1823890830 Email: powcoder@163.com