Demonstration of t-Test in Statistics Using R
Experiment
Demonstration of t-Test in Statistics Using R
1. Experiment Title
Hypothesis Testing Using t-Test in R
2. Aim
To study and perform a t-test using R to determine whether the mean of a sample differs significantly from a specified population mean.
3. Objectives
After completing this experiment, students should be able to:
- Understand the concept of hypothesis testing.
- Formulate the null and alternative hypotheses.
- Perform a one-sample t-test.
- Calculate the t-statistic manually using the appropriate formula.
- Perform the t-test using R.
- Interpret the p-value and make a statistical decision.
- Draw a conclusion based on the test result.
4. Theory
4.1 What is a t-Test?
A t-test is a parametric statistical test used to determine whether there is a statistically significant difference between means.
The t-test is commonly used when:
- The population standard deviation is unknown.
- The sample size is relatively small.
- The data are quantitative.
- The observations are independent.
- The data are approximately normally distributed.
There are three commonly used types of t-tests:
- One-sample t-test – compares a sample mean with a known or hypothesized population mean.
- Independent two-sample t-test – compares the means of two independent groups.
- Paired t-test – compares two related measurements.
In this experiment, we demonstrate the one-sample t-test.
5. Problem Statement
A university claims that the average examination score of its students is 70 marks.
A sample of 10 students produced the following marks:
72, 68, 75, 71, 69, 74, 73, 70, 76, 72
Using a significance level of:
determine whether the sample provides sufficient evidence to conclude that the average examination score differs from 70 marks.
6. Hypothesis Formulation
The university claims that the population mean is 70.
Null Hypothesis
There is no significant difference between the population mean and 70.
Alternative Hypothesis
There is a significant difference between the population mean and 70.
Since we are checking whether the mean is different from 70, this is a two-tailed test.
7. Manual Calculation
Step 1: Calculate the Sample Mean
The sample data are:
The sample mean is:
The sum of the observations is:
The number of observations is:
Therefore:
Step 2: Calculate the Sample Standard Deviation
The sample standard deviation is:
For the given observations:
Step 3: Calculate the t-Statistic
The formula for a one-sample t-test is:
where:
- = sample mean
- = hypothesized population mean
- = sample standard deviation
- = sample size
Substituting the values:
The degrees of freedom are:
8. R Program
# One-Sample t-Test in R # Sample examination marks marks <- c(72, 68, 75, 71, 69, 74, 73, 70, 76, 72) # Hypothesized population mean mu <- 70 # Significance level alpha <- 0.05 # Display sample statistics cat("Sample Size =", length(marks), "\n") cat("Sample Mean =", mean(marks), "\n") cat("Sample Standard Deviation =", sd(marks), "\n") # Perform one-sample t-test result <- t.test(marks, mu = mu, alternative = "two.sided", conf.level = 0.95) # Display the result print(result) # Decision based on p-value if (result$p.value < alpha) { cat("\nDecision: Reject the Null Hypothesis\n") cat("Conclusion: The mean is significantly different from", mu) } else { cat("\nDecision: Fail to Reject the Null Hypothesis\n") cat("Conclusion: There is not enough evidence to conclude that the mean differs from", mu) }
9. Explanation of Important R Function
The main function used is:
t.test()
For this experiment:
t.test(marks, mu = 70)
The function performs a one-sample t-test.
Important Arguments
| Argument | Meaning |
|---|---|
marks | Sample data |
mu = 70 | Hypothesized population mean |
alternative = "two.sided" | Tests whether the mean is different |
conf.level = 0.95 | Uses a 95% confidence level |
10.Output
The output will contain information similar to:
Sample Size = 10 Sample Mean = 72 Sample Standard Deviation = 2.581989 One Sample t-test data: marks t = 2.4495, df = 9, p-value = 0.03679 alternative hypothesis: true mean is not equal to 70 95 percent confidence interval: 70.15296 73.84704 sample estimates: mean of x 72 Decision: Reject the Null Hypothesis Conclusion: The mean is significantly different from 70
The exact p-value and confidence interval can be obtained by running the program.
11. Interpretation of the Output
The important values obtained from a t-test are:
1. t-value
The t-value indicates how far the sample mean is from the hypothesized mean relative to the variation in the data.
2. Degrees of Freedom
For a one-sample t-test:
3. p-value
The p-value is used to make the statistical decision.
At:
- If p-value < 0.05, reject .
- If p-value ≥ 0.05, fail to reject .
4. Confidence Interval
The confidence interval gives a range of plausible values for the population mean.
12. Result
Thus, a one-sample t-test was performed using R to test whether the mean examination score differs significantly from the hypothesized population mean of 70. The sample mean, t-statistic, degrees of freedom, p-value, and confidence interval were obtained and used to make a statistical conclusion regarding the null hypothesis.
Comments
Post a Comment