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:

  1. Understand the concept of hypothesis testing.
  2. Formulate the null and alternative hypotheses.
  3. Perform a one-sample t-test.
  4. Calculate the t-statistic manually using the appropriate formula.
  5. Perform the t-test using R.
  6. Interpret the p-value and make a statistical decision.
  7. 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:

  1. One-sample t-test – compares a sample mean with a known or hypothesized population mean.
  2. Independent two-sample t-test – compares the means of two independent groups.
  3. 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:

α=0.05\alpha = 0.05

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

H0:μ=70H_0:\mu=70

There is no significant difference between the population mean and 70.

Alternative Hypothesis

H1:μ≠70H_1:\mu\neq70

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:

72,68,75,71,69,74,73,70,76,7272,68,75,71,69,74,73,70,76,72

The sample mean is:

xˉ=∑xin\bar{x}=\frac{\sum x_i}{n}

The sum of the observations is:

72+68+75+71+69+74+73+70+76+72=72072+68+75+71+69+74+73+70+76+72=720

The number of observations is:

n=10n=10

Therefore:

xˉ=72010=72\bar{x}=\frac{720}{10}=72

Step 2: Calculate the Sample Standard Deviation

The sample standard deviation is:

s=∑(xi−xˉ)2n−1s=\sqrt{\frac{\sum(x_i-\bar{x})^2}{n-1}}

For the given observations:

s≈2.582s\approx2.582

Step 3: Calculate the t-Statistic

The formula for a one-sample t-test is:

t=xˉ−μ0s/nt=\frac{\bar{x}-\mu_0}{s/\sqrt{n}}

where:

  • xˉ\bar{x} = sample mean
  • μ0\mu_0 = hypothesized population mean
  • ss = sample standard deviation
  • nn = sample size

Substituting the values:

t=72−702.582/10t=\frac{72-70}{2.582/\sqrt{10}}
t≈2.45
t\approx2.45

The degrees of freedom are:

df=n−1=10−1=9df=n-1=10-1=9

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

ArgumentMeaning
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:

df=n−1df=n-1

3. p-value

The p-value is used to make the statistical decision.

At:

α=0.05\alpha=0.05
  • If p-value < 0.05, reject H0H_0.
  • If p-value ≥ 0.05, fail to reject H0H_0.

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

Popular posts from this blog

Statistical Methods Lab ( R Language) PCCBL308 Semester 3 KTU BTech CB and CU 2024 Scheme - Dr Binu V P

Programs in R - using control statements - Assignment 2

Programs to try using Functions in R - Assignment 3