T-Test

by

in

In business, the most commonly used t-test is often the Independent Two-Sample t-test. This test is widely utilized to compare the means of two independent groups or samples to determine if there is a significant difference between them.

The Independent Two-Sample t-test is particularly useful in various business scenarios, such as:

  1. Comparing the performance metrics of two different products or services.
  2. Analyzing the effectiveness of different marketing strategies or campaigns.
  3. Assessing the impact of changes in processes or procedures on business outcomes.
  4. Evaluating the differences in customer satisfaction levels between different segments or demographics.
  5. Comparing the financial performance of different investment portfolios or asset classes.


  1. One-Sample t-Test

Purpose:

  • To determine if the mean of a single sample differs significantly from a known or hypothesized population mean.

Example:

  • Scenario: A company wants to compare the average weekly sales of a new product to the historical average weekly sales of similar products, which is $5000.
  • Hypothesis: The mean weekly sales of the new product is different from $5000.
  • Application: The company collects weekly sales data for the new product over several weeks and uses the one-sample t-test to determine if the average sales differ from $5000.

    Calculation
    x-X/sd/SQRT(n)
    Where x = sample mean, X = est., population mean, n = sample size

    Nominator: Mean – hypothesized population mean
    Denominator: sample standard deviation/SQRT(sample size n)

2. Independent Two-sample t-test

Purpose:

  • To compare the means of two independent groups to see if they differ significantly.
  • Null Hypothesis: The means of 2 groups are equal. If rejected, there is a significant difference between the 2 means.

Types:

  • Equal Variance (Pooled) t-Test: Assumes that both groups have the same variance.
  • Unequal Variance (Welch’s) t-Test: Does not assume equal variances between the groups.

    How do we determine if they have the same variance?
    Use the Levenes Test first to determine if the variances are equal between groups


Example (Equal Variance) or Pooled t-Test:

  • Scenario: A retailer wants to compare the average sales of two different stores located in different regions.
  • Hypothesis: The mean sales of Store A are equal to the mean sales of Store B.
  • Application: Sales data from Store A and Store B are collected over the same time period. An independent two-sample t-test assuming equal variances is used to compare the average sales.

    t-Value = Complex Calculation

    Degrees of Freedom
    df=n1​+n2​−2

Example (Unequal Variance, Welch’s t-test):

  • Scenario: A company wants to compare the average salaries of employees in two different departments.
  • Hypothesis: The mean salary in Department X is equal to the mean salary in Department Y.
  • Application: Salary data from both departments are collected. An independent two-sample t-test with unequal variances (Welch’s t-test) is used to compare the average salaries.

    Calculation
    Usage Independent t-test is used when the number of samples and the variance of the two data sets is different.

    T-Value: t = (X1-X2)/SQRT((var1/n1)+(var2/n2))

    Nominator: mean1 – mean2
    Denominator: SQRT((var1/n1)+(var2/n2))

    Degrees of Freedom Calculation more complex.

3. Paired Sample t-Test

Purpose:

  • To compare the means of two related groups (e.g., the same subjects measured at two different times).
  • To test if the sample mean is significantly greater than or less than the hypothesized population mean (used for directional hypotheses).

Business Example:

  • Scenario: A company implements a new training program and wants to determine its effectiveness by comparing employee performance before and after the training.
  • Hypothesis: The mean performance score after training is different from the mean performance score before training.
  • Application: Performance scores of employees are recorded before and after the training. A paired sample t-test is used to compare the average performance scores before and after the training.

    More Examples:

    example: Comparing the mean blood pressure of patients before and after treatment
    example: Testing if a new drug increases recovery rates (greater than) compared to the known recovery rate without the drug.

    Calculation
    T-Value =
    nominator: mean1 – mean2 (difference between the means)
    denominator: s(Diff)/SQRT(n)

    s(Diff) = (standard deviation of the differences of the paired data values)
    n = sample size (number of paired differences)
  • Degrees of Freedom:
  • n-1 = degrees of freedom

One Side or Two-Sided:

a) One-Sided t-Test

Purpose:

  • To test if the sample mean is significantly greater than or less than the hypothesized population mean (used for directional hypotheses).

Example:

  • Scenario: A company believes that a new marketing campaign will increase the average number of customers visiting their store per day compared to the previous average of 100 customers.
  • Hypothesis: The mean number of customers after the campaign is greater than 100.
  • Application: The company collects daily customer visit data after the campaign starts. A one-sided t-test is used to determine if the average number of customers is significantly greater than 100.

    Example 2: Comparing the average test score of a class to a national average

b) Two-Sided t-Test

Purpose:

  • To test if the sample mean is significantly different from the hypothesized population mean (used for non-directional hypotheses).


Example:

  • Scenario: A company wants to compare the customer satisfaction ratings of two different products to see if there is any difference.
  • Hypothesis: The mean satisfaction rating of Product A is different from the mean satisfaction rating of Product B.
  • Application: Customer satisfaction ratings for both products are collected. A two-sided t-test is used to compare the average satisfaction ratings of the two products.


    Levenes Test – Python Code:
    Test if the variances of two independent groups are equal – use for determining whether to use the Equal or Unequal Independent Samples test

    If the p-value for the Levene test is greater than .05, then the variances are not significantly different from each other (i.e., the homogeneity assumption of the variance is met).
    In this case, we can use the Independent Samples Equal Variance T-Test
    If they are significantly different (p<0.05), then we use the Independent Samples Equal Variance T-Test
import scipy.stats as stats

# Data for Set 1 and Set 2
set1 = [19.7, 20.4, 19.6, 17.8, 18.5, 18.9, 18.3, 18.9, 19.5, 21.95]
set2 = [28.3, 26.7, 20.1, 23.3, 25.2, 22.1, 17.7, 27.6, 20.6, 13.7, 23.2, 17.5, 20.6, 18, 23.9, 21.6, 24.3, 20.4, 23.9, 13.3]

# Check if the variances are equal
# Levene's test for equal variances
levene_stat, p_levene = stats.levene(set1, set2)

# Print the results of the Levene's test
print("Levene's test for Equal Variances:")
print(f"F statistic: {levene_stat:.3f}")
print(f"p-value: {p_levene:.3f}")

Comments

One response to “T-Test”

  1. Internet Chicks Very well presented. Every quote was awesome and thanks for sharing the content. Keep sharing and keep motivating others.

Leave a Reply

Your email address will not be published. Required fields are marked *