How to perform one sample t-test

oluwafemi oloye - updated on March 27, 2024 . 3 Min Read

Why do we perform One sample t-test

One sample t-test is commonly used when researchers want to test the effect of a new treatment on a single group of patients. This paired comparisons t-test is computed from the difference in each patient, of a particular measure before and after treatment.

How do we perform one sample t-test

The formular for one sample t-test is given as follows:
$$t= \frac{{\bar{x} - \mu}}{{s/\sqrt{n}}}$$ where:

\(\bar{x}\) is the sample mean
\(\mu\) is the population mean
s is the sample variance
n is is the sample size.

In rstudio we have functions that can enable us to perfom the one sample t-test, for this tutorial we will be using the t-test() function in rstudio, this will automatically give you a p-value and the test statistics.

Hypothesis

$$ H0: \mu =1$$ $$ H0: \mu \neq 1$$

                
my_data <- c(12, 45, 12, 35, 40,38, 32, 15, 19)
t_test_result <- t.test(myData, mu = 1)
          
            
                	One Sample t-test

data:  my_data
t = 6.1142, df = 8, p-value = 0.000285
alternative hypothesis: true mean is not equal to 1
95 percent confidence interval:
 17.53990 37.57121
sample estimates:
mean of x 
 27.55556 
            
Interpretation

t = 6.1142: This is the t-statistic, which measures the size of the difference relative to the variation in your sample data. A larger absolute value of t indicates a larger difference between your sample mean and the hypothesized value. df = 8: This is the degrees of freedom, which is related to the number of observations in your data. In a one-sample t-test, it’s typically the number of observations minus 1. p-value = 0.000285: The p-value is a measure of the probability that an effect as large as the observed effect could occur by chance if the null hypothesis is true. In this case, the p-value is very small, suggesting that it’s very unlikely the observed difference occurred by chance, and thus the null hypothesis (that the true mean is equal to 1) is likely to be rejected. alternative hypothesis: true mean is not equal to 1: This is the alternative hypothesis you’re testing. In this case, you’re testing whether the true mean is different from 1. 95 percent confidence interval: 17.53990 37.57121: This is the range of values within which you can be 95% confident that the true population mean lies, based on your sample data. sample estimates: mean of x 27.55556: This is the mean (average) of your sample data.

Summary

In summary, the test suggests that the mean of my_data is significantly different from 1, with a 95% confidence interval of approximately 17.54 to 37.57. The sample mean is approximately 27.56. The low p-value (0.000285) indicates strong evidence against the null hypothesis. Therefore, you would reject the null hypothesis and conclude that the true mean of the population is not equal to 1.