Module 7 - Comparing Continuous Outcomes
- Page:
- 1
- | 2
- | 3
- | 4
- | 5
- | 6
- | 7
- | 8
- | 9
One Sample t-test
One-tailed and two-tailed tests of significance, a one-tailed test of hypothesis, a two-tailed test of hypothesis, one sample t-test using r.
Investigators wanted to determine whether children who were born very prematurely have poorer cognitive ability than children born at full term. To investigate they enrolled 100 children who had been born prematurely and measured their IQ in order to compare the sample mean to a normative IQ of 100. In essence, the normative IQ is a historical or external (μ 0 ). In the sample of 100 children who had been born prematurely the data for IQ were as follows: X̄ = 95.8, SD = 17.5" . The investigators wish to use a one-tailed test of significance.
A research hypothesis that states that two groups differ without specifying direction, i.e., which is greater, is a two-tailed hypothes is . In contrast, a research hypothesis that specifies direction, e.g., that the mean in a sample group will be less than the mean in a historic comparison group is a one-tailed hypothesis . Similarly, a hypothesis that a mean in a sample group will be greater than the mean in a historic comparison group is also a one-tailed hypothesis .
Suppose we conduct a test of significance to compare two groups (call them A and B) using large samples. The test statistic could be either a t score or a Z score, depending on the test we choose, but if the sample is very large the t or Z scores will be similar. Suppose also that we have specified an "alpha" level of 0.05, i.e., an error rate of 5% for concluding that the groups differ when they really don't. In other words, we will use p≤0.05 as the criterion for statistical significance.
Two-tailed test: The first figure below shows that with a two-tailed test in which we acknowledge that one group's mean could be either above or below the other, the alpha error rate has to be split into the upper and lower tails, i.e., with half of our alpha (0.025) in each tail. Therefore, we need to achieve a test statistic that is either less than -1.96 or greater than +1.96.
One-tailed test (lower tail): In the middle figure the hypothesis is that group A has a mean less than group B, perhaps because it is unreasonable to think the mean IQ in group A would be greater than that in group B. If so, all of the 5% alpha is in the lower tail, and we only need to achieve a test statistic less than 1.645 to achieve "statistical significance."
One-tailed test (upper tail): The third image shows a one-tailed test in which the hypothesis is that group A has a mean value greater than that of group B, so all of the alpha is in the upper tail, meaning that we need a test statistic greater than +1.645 to achieve statistical significance.
Clearly, the two-tailed test is more conservative because, regardless of direction, the test statistic has to be more than 1.96 units away from the null. The vast majority of tests that are reported are two-tailed tests. However, there are occasionally situations in which a one-tailed test hypothesis can be justified.
A one-tailed test could be justified in the study examining whether children who had been born very prematurely have lower IQ scores than children who had a normal, full term gestation, since there is no reason to believe that those born prematurely would have higher IQs.
First, we set up the hypotheses: Null hypothesis : H 0 : μ prem = 100 (i.e., that there is no difference or association) Children born prematurely have mean IQs that are not different from those of the general population (μ=100)
Alternative hypothesis (i.e., the research hypothesis): H 0 :μ prem < 100) Children born prematurely have lower mean IQ than the general population (μ<100).
The t statistic= -2.4. We can look up the corresponding p-value with df=99, or we can use R to compute the probability.
> pt(-2.4,99) [1] 0.009132283
Since p=0.009, we reject the null hypothesis and accept the alternative hypothesis. We conclude that children born prematurely have lower mean IQ scores than children in the general population who had a full term gestation.
What if we had performed a two-tailed test of hypothesis on the same data?
The null hypothesis would be the same, but the alternative hypothesis would be:
Alternative hypothesis (research hypothesis: H A : μ prem ≠100 Children born prematurely have IQ scores that are different (either lower or higher) from children from the general population who had full term gestation.
The calculation of the t statistic would also be the same, but the p-value will be different.
> 2*pt(-2.4,99) [1] 0.01826457
The probability is the area under the standard normal distribution that is either lower than -2.40 or greater than +2.40. So the probability is 0.009+0.009 = 0.018, i.e., a probability of 0.009 in both the lower and upper tail. We still conclude that children born prematurely have a significantly lower mean IQ than the general population (mean=95.8, s=17.5, p=0.018).
When performing two-tailed tests, direction is not specified in the hypothesis, but one should report the direction in any report, publication, or presentation, e.g., "Children who had been born prematurely had lower mean IQ scores than in the general population."
In the example for IQ tests above we were given the mean IQ and standard deviation for the children who had been born prematurely. However, suppose we were given an Excel spreadsheet with the raw data listed in a column for "iq"?
In Excel we could save this data as a .CSV file using the "Save as" function. We could then import the data in the .CSV file into R and analyze the data as follows:
[Note that R defaults to performing the more conservative two-tailed test unless a one-tailed test is specified as we will describe below.]
> t.test(iq,mu=100)
One Sample t-test data: iq t = -2.3801, df=99, p-value = 0.01922 alternative hypothesis: true mean is not equal to 100 95 percent confidence interval: 92.35365 99.30635 Sample estimates mean of x 95.83
In order to perform a one-tailed test, you need to specify the alternative hypothesis. For example:
> t.test(iq,mu=100, alternative="less")
> t.test(iq,mu=100, alternative="greater")
return to top | previous page | next page
Content ©2021. Some Rights Reserved. Date last modified: October 13, 2021. Wayne W. LaMorte, MD, PhD, MPH
One Sample t-test: Definition, Formula, and Example
A one sample t-test is used to test whether or not the mean of a population is equal to some value.
This tutorial explains the following:
- The motivation for performing a one sample t-test.
- The formula to perform a one sample t-test.
- The assumptions that should be met to perform a one sample t-test.
- An example of how to perform a one sample t-test.
One Sample t-test: Motivation
Suppose we want to know whether or not the mean weight of a certain species of turtle in Florida is equal to 310 pounds. Since there are thousands of turtles in Florida, it would be extremely time-consuming and costly to go around and weigh each individual turtle.
Instead, we might take a simple random sample of 40 turtles and use the mean weight of the turtles in this sample to estimate the true population mean:
However, it’s virtually guaranteed that the mean weight of turtles in our sample will differ from 310 pounds. The question is whether or not this difference is statistically significant . Fortunately, a one sample t-test allows us to answer this question.
One Sample t-test: Formula
A one-sample t-test always uses the following null hypothesis:
- H 0 : μ = μ 0 (population mean is equal to some hypothesized value μ 0 )
The alternative hypothesis can be either two-tailed, left-tailed, or right-tailed:
- H 1 (two-tailed): μ ≠ μ 0 (population mean is not equal to some hypothesized value μ 0 )
- H 1 (left-tailed): μ < μ 0 (population mean is less than some hypothesized value μ 0 )
- H 1 (right-tailed): μ > μ 0 (population mean is greater than some hypothesized value μ 0 )
We use the following formula to calculate the test statistic t:
t = ( x – μ) / (s/√ n )
- x : sample mean
- μ 0 : hypothesized population mean
- s: sample standard deviation
- n: sample size
If the p-value that corresponds to the test statistic t with (n-1) degrees of freedom is less than your chosen significance level (common choices are 0.10, 0.05, and 0.01) then you can reject the null hypothesis.
One Sample t-test: Assumptions
For the results of a one sample t-test to be valid, the following assumptions should be met:
- The variable under study should be either an interval or ratio variable .
- The observations in the sample should be independent .
- The variable under study should be approximately normally distributed. You can check this assumption by creating a histogram and visually checking if the distribution has roughly a “bell shape.”
- The variable under study should have no outliers. You can check this assumption by creating a boxplot and visually checking for outliers.
One Sample t-test : Example
Suppose we want to know whether or not the mean weight of a certain species of turtle is equal to 310 pounds. To test this, will perform a one-sample t-test at significance level α = 0.05 using the following steps:
Step 1: Gather the sample data.
Suppose we collect a random sample of turtles with the following information:
- Sample size n = 40
- Sample mean weight x = 300
- Sample standard deviation s = 18.5
Step 2: Define the hypotheses.
We will perform the one sample t-test with the following hypotheses:
- H 0 : μ = 310 (population mean is equal to 310 pounds)
- H 1 : μ ≠ 310 (population mean is not equal to 310 pounds)
Step 3: Calculate the test statistic t .
t = ( x – μ) / (s/√ n ) = (300-310) / (18.5/√ 40 ) = -3.4187
Step 4: Calculate the p-value of the test statistic t .
According to the T Score to P Value Calculator , the p-value associated with t = -3.4817 and degrees of freedom = n-1 = 40-1 = 39 is 0.00149 .
Step 5: Draw a conclusion.
Since this p-value is less than our significance level α = 0.05, we reject the null hypothesis. We have sufficient evidence to say that the mean weight of this species of turtle is not equal to 310 pounds.
Note: You can also perform this entire one sample t-test by simply using the One Sample t-test calculator .
Additional Resources
The following tutorials explain how to perform a one-sample t-test using different statistical programs:
How to Perform a One Sample t-test in Excel How to Perform a One Sample t-test in SPSS How to Perform a One Sample t-test in Stata How to Perform a One Sample t-test in R How to Conduct a One Sample t-test in Python How to Perform a One Sample t-test on a TI-84 Calculator
Featured Posts
Hey there. My name is Zach Bobbitt. I have a Masters of Science degree in Applied Statistics and I’ve worked on machine learning algorithms for professional businesses in both healthcare and retail. I’m passionate about statistics, machine learning, and data visualization and I created Statology to be a resource for both students and teachers alike. My goal with this site is to help you learn statistics through using simple terms, plenty of real-world examples, and helpful illustrations.
5 Replies to “One Sample t-test: Definition, Formula, and Example”
This is very helpful. Thanks a lot.
am impressed with the note statology links give us. thanks
The sample size for t test cannot be more than 30.
Since in this example we do not compare the t-statistics obtained as a result of calculations with the critical value of t, but immediately calculate the P-value, the fact that we are dealing with a two-tailed case remains hidden here (the fact, that the critical value must be calculated for the confidence level 0.05 divided by 2). The calculator simply immediately produces the doubled p-value. I hope I was able to express my thoughts clearly enough. Anyway, Zach, thank you so much for the great tutorial.
Hi Oleg…Thank you for your feedback! Let us know if we can help answer any questions.
Leave a Reply Cancel reply
Your email address will not be published. Required fields are marked *
Join the Statology Community
Sign up to receive Statology's exclusive study resource: 100 practice problems with step-by-step solutions. Plus, get our latest insights, tutorials, and data analysis tips straight to your inbox!
By subscribing you accept Statology's Privacy Policy.
IMAGES
VIDEO