One-Sample Test

Introduction

In hypothesis testing, the one-sample z-test and one-sample t-test are used to determine if a sample mean is significantly different from a known or hypothesized population mean. These tests are widely used in various fields, such as medicine, social sciences, and business research.

One-Sample Z-Test

The one-sample z-test is appropriate when the population standard deviation is known. The test statistic follows a standard normal distribution.

Hypotheses

Three Methods of Hypothesis Testing

1. Critical Value Method

  1. Set the significance level (α).
  2. Compute the test statistic: z = (x̄ - μ) / (σ / sqrt(n)), where x̄ is the sample mean, μ is the population mean, σ is the population standard deviation, and n is the sample size.
  3. Determine the critical value(s) corresponding to the desired confidence level or significance level.
  4. Compare the test statistic with the critical value(s).
  5. Make a decision: Reject the null hypothesis if the test statistic is outside the critical region; otherwise, fail to reject the null hypothesis.

2. P-Value Method

  1. Set the significance level (α).
  2. Compute the test statistic: z = (x̄ - μ) / (σ / sqrt(n)).
  3. Calculate the p-value, which represents the probability of obtaining a test statistic as extreme as the observed value (or more extreme), assuming the null hypothesis is true.
  4. Compare the p-value with the significance level (α).
  5. Make a decision: Reject the null hypothesis if the p-value is less than or equal to α; otherwise, fail to reject the null hypothesis.

3. Confidence Interval Method

  1. Set the confidence level (1 - α).
  2. Compute the test statistic: z = (x̄ - μ) / (σ / sqrt(n)).
  3. Calculate the confidence interval for the sample mean using the formula: (x̄ - z * (σ / sqrt(n)), x̄ + z * (σ / sqrt(n))), where x̄ is the sample mean, σ is the population standard deviation, n is the sample size, and z is the critical value corresponding to the desired confidence level.
  4. Determine if the hypothesized population mean falls within the confidence interval.
  5. Make a decision: If the hypothesized population mean is within the confidence interval, fail to reject the null hypothesis; otherwise, reject the null hypothesis.

Example: One-Sample Z-Test

Problem

Suppose we want to test if the average weight of a certain product is different from 50 grams. We collect a sample of 50 products and find that the sample mean weight is 52 grams. The population standard deviation is known to be 5 grams.

Hypotheses

Critical Value Method

  1. Set the significance level (α).
  2. Compute the test statistic:
    • Test statistic: z = \(\frac{{\bar{x} - \mu}}{{\sigma / \sqrt{n}}}\)
    • Sample mean (\(\bar{x}\)): 52 grams
    • Population mean (\(\mu\)): 50 grams
    • Population standard deviation (\(\sigma\)): 5 grams
    • Sample size (n): 50
  3. Determine the critical value(s) corresponding to the desired confidence level or significance level.
    • For a 95% confidence level (α = 0.05), the critical values are ±1.96.
  4. Compare the test statistic with the critical value(s).
    • If |z| > 1.96, reject the null hypothesis.
    • Otherwise, fail to reject the null hypothesis.

Calculation

x_bar <- 52
mu <- 50
sigma <- 5
n <- 50

z <- (x_bar - mu) / (sigma / sqrt(n))
critical_value <- 1.96

z
[1] 2.828427

Since the calculated test statistic (z = 2.8284271) is greater than the critical value (1.96), we reject the null hypothesis.

P-Value Method

  1. Set the significance level (α).
  2. Compute the test statistic:
    • Test statistic: z = \(\frac{{\bar{x} - \mu}}{{\sigma / \sqrt{n}}}\)
    • Sample mean (\(\bar{x}\)): 52 grams
    • Population mean (\(\mu\)): 50 grams
    • Population standard deviation (\(\sigma\)): 5 grams
    • Sample size (n): 50
  3. Calculate the p-value, which represents the probability of obtaining a test statistic as extreme as the observed value (or more extreme), assuming the null hypothesis is true.
    • P-value = \(2 \times (1 - \Phi(|z|))\)
    • Where \(\Phi()\) represents the cumulative distribution function of the standard normal distribution.
  4. Compare the p-value with the significance level (α).
    • If p-value ≤ α, reject the null hypothesis.
    • Otherwise, fail to reject the null hypothesis.

Calculation

p_value <- 2 * (1 - pnorm(abs(z)))

p_value
[1] 0.004677735

Since the calculated p-value (p = 0.0046777) is less than the significance level (α = 0.05), we reject the null hypothesis.

Confidence Interval Method

  1. Set the confidence level (1 - α).
  2. Compute the test statistic:
    • Test statistic: z = \(\frac{{\bar{x} - \mu}}{{\sigma / \sqrt{n}}}\)
    • Sample mean (\(\bar{x}\)): 52 grams
    • Population mean (\(\mu\)): 50 grams
    • Population standard deviation (\(\sigma\)): 5 grams
    • Sample size (n): 50
  3. Determine the critical value(s) corresponding to the desired confidence level.
    • For a 95% confidence level (α = 0.05), the critical values are ±1.96.
  4. Calculate the confidence interval for the population mean.
    • Confidence interval: \(\bar{x} \pm z \times \frac{{\sigma}}{{\sqrt{n}}}\)
  5. Check if the hypothesized population mean falls within the confidence interval.
    • If the hypothesized mean is within the interval, fail to reject the null hypothesis.
    • Otherwise, reject the null hypothesis.

Calculation

lower <- x_bar - critical_value * (sigma / sqrt(n))
upper <- x_bar + critical_value * (sigma / sqrt(n))
hypothesized_mean <- 50

lower 
[1] 50.61407
upper
[1] 53.38593

Since the hypothesized mean (50 grams) falls outside the confidence interval (50.6140707 grams to 53.3859293 grams), we reject the null hypothesis.

Conclusion

Using the critical value method, p-value method, and confidence interval method, we have shown that there is sufficient evidence to reject the null hypothesis that the average weight of the product is equal to 50 grams. The sample data suggests that the average weight is significantly different from 50 grams.

r Code

# Critical Value Method
x_bar <- 52
mu <- 50
sigma <- 5
n <- 50

z <- (x_bar - mu) / (sigma / sqrt(n))
alpha <- 0.05
critical_value <- qnorm(1 - alpha/2)

if (z < -critical_value | z > critical_value) {
  decision <- "Reject H0"
} else {
  decision <- "Fail to reject H0"
}

decision
[1] "Reject H0"
# P-Value Method
p_value <- 2 * (1 - pnorm(abs(z)))

if (p_value <= alpha) {
  decision <- "Reject H0"
} else {
  decision <- "Fail to reject H0"
}

decision
[1] "Reject H0"
# Confidence Interval Method
z <- qnorm(1 - alpha/2)
lower <- x_bar - z * (sigma / sqrt(n))
upper <- x_bar + z * (sigma / sqrt(n))
hypothesized_mean <- 50

if (hypothesized_mean >= lower & hypothesized_mean <= upper) {
  decision <- "Fail to reject H0"
} else {
  decision <- "Reject H0"
}

decision
[1] "Reject H0"

One-Sample T-Test

The one-sample t-test is used when the population standard deviation is unknown and must be estimated from the sample. The test statistic follows a t-distribution.

Hypotheses

Three Methods of Hypothesis Testing

1. Critical Value Method

Same as the one-sample z-test, but using the t-distribution instead of the standard normal distribution.

2. P-Value Method

Same as the one-sample z-test, but using the t-distribution instead of the standard normal distribution.

3. Confidence Interval Method

Same as the one-sample z-test, but using the t-distribution instead of the standard normal distribution.

Example: One-Sample T-Test

Problem

Suppose we want to test if the average height of a certain population is different from 170 cm. We collect a sample of 30 individuals and find that the sample mean height is 172 cm. The sample standard deviation is 8 cm.

Hypotheses

Critical Value Method

  1. Set the significance level (α).
  2. Compute the test statistic:
    • Test statistic: t = \(\frac{{\bar{x} - \mu}}{{s / \sqrt{n}}}\)
    • Sample mean (\(\bar{x}\)): 172 cm
    • Population mean (\(\mu\)): 170 cm
    • Sample standard deviation (s): 8 cm
    • Sample size (n): 30
  3. Determine the critical value(s) corresponding to the desired confidence level or significance level.
    • For a 95% confidence level (α = 0.05) and 29 degrees of freedom (n - 1), the critical values are ±2.045.
  4. Compare the test statistic with the critical value(s).
    • If |t| > 2.045, reject the null hypothesis.
    • Otherwise, fail to reject the null hypothesis.

Calculation

x_bar <- 172
mu <- 170
s <- 8
n <- 30

t <- (x_bar - mu) / (s / sqrt(n))
critical_value <- qt(1 - 0.05/2, df = n - 1)

t
[1] 1.369306

Since the calculated test statistic (t = 1.3693064) is less than the critical value (2.045), we fail to reject the null hypothesis.

P-Value Method

  1. Set the significance level (α).
  2. Compute the test statistic:
    • Test statistic: t = \(\frac{{\bar{x} - \mu}}{{s / \sqrt{n}}}\)
    • Sample mean (\(\bar{x}\)): 172 cm
    • Population mean (\(\mu\)): 170 cm
    • Sample standard deviation (s): 8 cm
    • Sample size (n): 30
  3. Calculate the p-value, which represents the probability of obtaining a test statistic as extreme as the observed value (or more extreme), assuming the null hypothesis is true.
    • P-value = \(2 \times (1 - \text{{pt}}(|t|, \text{{df}}))\)
    • Where \(\text{{pt}}()\) represents the cumulative distribution function of the t-distribution.
  4. Compare the p-value with the significance level (α).
    • If p-value ≤ α, reject the null hypothesis.
    • Otherwise, fail to reject the null hypothesis.

Calculation

p_value <- 2 * (1 - pt(abs(t), df = n - 1))

p_value
[1] 0.1814154

Since the calculated p-value (p = 0.1814154) is greater than the significance level (α = 0.05), we fail to reject the null hypothesis.

Confidence Interval Method

  1. Set the confidence level (1 - α).
  2. Compute the test statistic:
    • Test statistic: t = \(\frac{{\bar{x} - \mu}}{{s / \sqrt{n}}}\)
    • Sample mean (\(\bar{x}\)): 172 cm
    • Population mean (\(\mu\)): 170 cm
    • Sample standard deviation (s): 8 cm
    • Sample size (n): 30
  3. Determine the critical value(s) corresponding to the desired confidence level.
    • For a 95% confidence level (α = 0.05) and 29 degrees of freedom (n - 1), the critical values are ±2.045.
  4. Calculate the confidence interval for the population mean.
    • Confidence interval: \(\bar{x} \pm t \times \frac{{s}}{{\sqrt{n}}}\)
  5. Check if the hypothesized population mean falls within the confidence interval.
    • If the hypothesized mean is within the interval, fail to reject the null hypothesis.
    • Otherwise, reject the null hypothesis.

Calculation

lower <- x_bar - critical_value * (s / sqrt(n))
upper <- x_bar + critical_value * (s / sqrt(n))
hypothesized_mean <- 170

lower
[1] 169.0128
upper
[1] 174.9872

Since the hypothesized mean (170 cm) falls within the confidence interval (169.0127509 cm to 174.9872491 cm), we fail to reject the null hypothesis.

Conclusion

Using the critical value method, p-value method, and confidence interval method, we have shown that there is insufficient evidence to reject the null hypothesis that the average height of the population is equal to 170 cm. The sample data does not provide enough support to conclude that the average height is significantly different from 170 cm.

r Code

# Critical Value Method
x_bar <- 172
mu <- 170
s <- 8
n <- 30

t <- (x_bar - mu) / (s / sqrt(n))
alpha <- 0.05
critical_value <- qt(1 - alpha/2, df = n - 1)

if (t < -critical_value | t > critical_value) {
  decision <- "Reject H0"
} else {
  decision <- "Fail to reject H0"
}

decision
[1] "Fail to reject H0"
# P-Value Method
p_value <- 2 * (1 - pt(abs(t), df = n - 1))

if (p_value <= alpha) {
  decision <- "Reject H0"
} else {
  decision <- "Fail to reject H0"
}

decision
[1] "Fail to reject H0"
# Confidence Interval Method
t <- qt(1 - alpha/2, df = n - 1)
lower <- x_bar - t * (s / sqrt(n))
upper <- x_bar + t * (s /

 sqrt(n))
hypothesized_mean <- 170

if (hypothesized_mean >= lower & hypothesized_mean <= upper) {
  decision <- "Fail to reject H0"
} else {
  decision <- "Reject H0"
}

decision
[1] "Fail to reject H0"

Conclusion

In hypothesis testing, the one-sample z-test is used when the population standard deviation is known, while the one-sample t-test is used when the population standard deviation is unknown and must be estimated from the sample. By applying the critical value method, p-value method, and confidence interval method, we can make informed decisions regarding the null hypothesis. These tests provide valuable insights into the significance of sample means compared to population means, enabling researchers to draw meaningful conclusions from their data.