The one-sample Z-test is a statistical hypothesis test used to determine whether the mean of a single sample is significantly different from a known population mean. It is used to draw conclusions about a population based on sample data.
In this article, we will discuss the concept of a one-sample z-test in R with practical examples.
Why Use the One-Sample Z-Test
The one-sample z-test statistical tool can be used:
- Hypothesis Testing: It helps you to assess whether your sample data provides enough evidence to support or reject a hypothesis about a population parameter.
- Quality Control: Z-Tests can be used to ensure product quality meets specified standards.
- Research Validation: Z-Test can be used to validate research findings and draw a conclusion about the entire population based on sample data.
What is the Formula of One-Sample Z-Test
The formula for one-sample Z-Test statistic is:
z <- (x̄ - μ) / (σ / sqrt(n))
Where:
-
x̄: observed sample mean
-
μ: population mean under the null hypothesis
-
n: sample size
-
σ: population standard deviation
How to Perform One-Sample Z-Test in R
To conduct a one-sample z-test in R, follow these steps:
Step 1: Collect and Prepare Data
Collect your sample data and ensure it meets the assumption of normality. If the sample size is sufficiently large (typically n > 30), the Central Limit Theorem allows you to assume normality.
Step 2: Formulate Hypotheses
Define your null (Ho) and alternative Hypotheses (Ha):
Null Hypothesis (Ho): The sample mean is equal to the population mean (μ).
Alternative Hypothesis (Ha): The sample mean is not equal to the population mean (μ).
Step 3: Set Significance Level
Choose a significance level (α) typically 0.05, to determine the threshold for statistical significance.
Step 4: Calculate the Test Statistic
In R, you can use the following formula to calculate the Z-test statistic:
z <- (x̄ - μ) / (σ / sqrt(n))
Step 5: Determine the Critical Value
Find the critical Z-value using a Z-table or R function like ‘qnorm()‘ based on the chosen significance level (α) and the two-tailed nature of the Z-Test.
Step 6: Perform the Test
Compare the calculated Z-Test statistic in R to the critical value:
-
If the |Z| > Critical Value: Reject the null hypothesis.
-
If the |Z| ≤ Critical Value: Fail to reject the null hypothesis.
How to Perform One-Sample Z-Test in R
Let’s understand the one-sample Z-Test in R with a practical example.
Suppose we have a sample of 50 students, and we want to determine if the average test score differs significantly from the population mean test score of 75.
# Sample data
sample_scores <- c(72, 78, 82, 70, 76, 79, 85, 68, 74, 77,
73, 71, 80, 81, 75, 79, 76, 72, 77, 78,
76, 70, 74, 73, 78, 75, 72, 70, 79, 81,
77, 79, 76, 74, 78, 82, 75, 72, 76, 73,
80, 78, 75, 70, 72, 74, 79, 75, 76, 78)
# Perform the one-sample Z-test
pop_mean_score <- 75
# Choose significance level
alpha <- 0.05
# Calcualte the Test statistic
z <- (mean(sample_scores) - pop_mean_score) / (sd(sample_scores) / sqrt(length(sample_scores)))
# Calculate critical Z-value for a two-tailed test
critical_value <- qnorm(1 - alpha / 2)
# Compare the test statistic to the critical value
if (abs(z) > critical_value) {
cat("Reject the null hypothesis: The sample mean is significantly different from the population mean.\n")
} else {
cat("Fail to reject the null hypothesis: The sample mean is not significantly different from the population mean.\n")
}
The output of the above one-sample z-test in the R program is:
Fail to reject the null hypothesis: The sample mean is not significantly different from the population mean.
Conclusion
I hope the above article on one-sample z-test in R is helpful to you. The one-sample z-test is a valuable statistical tool for conducting hypothesis testing, and drawing conclusions about population parameters based on the sample data.