2025-02-10

t-Test

The t-Test is a statistical test used to determine if there is a significant difference between the means of two groups.

It is commonly used in hypothesis testing when the sample size is small and the population standard deviation is unknown.

Assumptions of the t-test:

  • The data should be normally distributed (especially for small samples).

  • The samples should be randomly selected.

  • In an independent t-test, the two groups should have equal variance (homogeneity of variance).

  • In a paired t-test, the observations should be dependent (related to each other).

Formula

For an independent t-test, the formula is:

\[ t = \frac{(\bar{x}_1 - \bar{x}_2)}{\sqrt{\frac{s_1^2}{n_1} + \frac{s_2^2}{n_2}}} \]

where:

  • \(\bar{x}_1\) and \(\bar{x}_2\) are the means of the two groups.

  • \(s_1^2\) and \(s_2^2\) are the variances of the two groups.

  • \(n_1\) and \(n_2\) are the sample sizes of the two groups.

Formula (continued)

For a paired t-test, the formula is:

\[ t = \frac{\bar{d}}{\frac{s_d}{\sqrt{n}}} \]

where:

  • \(\bar{d}\) is the mean of the differences between the paired observations.

  • \(s_d\) is the standard deviation of the differences.

  • \(n\) is the number of paired observations.

Example

The Office of the Superintendent of Bankruptcy (OSB) is responsible for administration of the Bankruptcy and Insolvency Act (BIA), as well as certain duties under the Companies’ Creditors Arrangement Act (CCAA) in Canada.

We take the monthly data of bankruptcies in Canada from 2024 and compare the mean of bankruptcies in the first half of the year to the mean of bankruptcies in the second half of the year (Superintendent of Bankruptcy 2024).

Example (continued)

Now suppose we take a sample of the data based on 75 randomly selected bankruptcy reports. The average debt is $5.32 million with a standard deviation of $5.87 million.

We want to construct a 95% confidence interval for the mean debt of Canadian companies filing reports for this year.

For this problem we are given:

  • Sample mean: \(\bar{x} = 5.32\)

  • Sample standard deviation: \(s = 5.87\)

  • Sample size: \(n = 75\)

  • Confidence level: \(\alpha = 0.95\)

Example (continued)

We can find the degrees of freedom using the formula:

\[ df = n - 1 = 75 - 1 = 74 \]

We can find the critical value using software or a t-table. For a 95% confidence level,

\[ t^* \approx 1.993 \]

The standard error is:

\[ SE = \frac{s}{\sqrt{n}} = \frac{5.87}{\sqrt{75}} \approx 0.678 \]

Example (continued)

The margin of error is:

\[ ME = t^* \times SE = 1.993 \times 0.678 \approx 1.351 \]

The confidence interval is:

\[ CI = \bar{x} \pm ME = 5.32 \pm 1.351 = (3.969, 6.671) \]

Therefore, we are 95% confident that the mean debt of Canadian companies filing reports for this year is between $3.969 million and $6.671 million.

Data

Monthly Bankruptcies in Canada (2024) - First Half
Month Bankruptcies
Jan 2818
Feb 2804
Mar 2826
Apr 3007
May 3241
Jun 2696

Data (continued)

Monthly Bankruptcies in Canada (2024) - Second Half
Month Bankruptcies
Jul 2874
Aug 2683
Sep 2668
Oct 3030
Nov 2871
Dec 2293

Plot ggplot

More Data

Lets now look at the historical data of bankruptcies in Canada from 1987 to 2024. (Superintendent of Bankruptcy 2025)

Plot

3D Plotly Plot

Code block for the 3D Plotly Plot

plot_ly() %>%
  add_surface(
    z = as.matrix(total_insolvencies), 
    x = colnames(total_insolvencies), 
    y = rownames(total_insolvencies), 
    showscale = FALSE, 
    name = "Total Insolvencies") %>%
  add_surface(
    z = as.matrix(total_bankruptcies), 
    x = colnames(total_bankruptcies), 
    y = rownames(total_bankruptcies), 
    showscale = FALSE, 
    name = "Total Bankruptcies", 
    opacity = 0.7) %>%
  add_surface(
    z = as.matrix(total_proposals), 
    x = colnames(total_proposals), 
    y = rownames(total_proposals), 

Code block for the 3D Plotly Plot (continued)

    showscale = FALSE, 
    name = "Total Proposals",
    opacity = 0.7) %>%
  layout(
    title = 
      "3D Plot of Insolvencies, Bankruptcies, and Proposals (1987-2024)",
    scene = list(
      xaxis = list(title = "Month"),
      yaxis = list(title = "Year"),
      zaxis = list(title = "Count")
    ),
    legend = list(
      title = list(text = "Legend"),
      x = 1.05,
      y = 1
    )
  )

References