Sure, let’s walk through an example of a t-test.

Let’s say we’re working with a software company that claims the average load time for its website is 3 seconds. We think it might be longer, so we collect load times from a sample of 15 different networks. The sample data we collected is as follows:

\text{{load_times}} = [3.6, 3.9, 4.1, 3.7, 3.2, 3.1, 3.5, 3.8, 3.7, 3.3, 3.4, 3.9, 3.6, 3.2, 3.5]

Our null hypothesis () is that the average load time is 3 seconds, as the company claims. The alternative hypothesis () is that the average load time is greater than 3 seconds.

To conduct a one-sample t-test, we need to calculate the t statistic using the following formula:

where:

  •  is the sample mean,
  • is the population mean (3 seconds according to the company),
  • is the sample standard deviation,
  • is the sample size (15 in this case).

We’ll use a significance level of 0.05. If our calculated t-value is greater than the critical t-value (for a one-tailed test with =0.05 and 14 degrees of freedom, the critical t-value is approximately 1.761), we’ll reject the null hypothesis.

Let’s perform the calculations.

import numpy as np
from scipy import stats

# given values
load_times = np.array([3.6, 3.9, 4.1, 3.7, 3.2, 3.1, 3.5, 3.8, 3.7, 3.3, 3.4, 3.9, 3.6, 3.2, 3.5])
pop_mean = 3 # population mean

# calculate sample mean and standard deviation
sample_mean = np.mean(load_times)
sample_std = np.std(load_times, ddof=1) # ddof=1 for sample std deviation
n = len(load_times) # sample size

# calculate t-score
t = (sample_mean - pop_mean) / (sample_std / np.sqrt(n))
t, stats.t.sf(t, df=n-1) # sf is survival function, equivalent to 1 - cdf
RESULT
(7.517205590395159, 1.4023639205416641e-06)

The calculated t-value is approximately 7.52, and the p-value is approximately 1.40×10−6.

When we compare this t-value with the critical t-value (approximately 1.761 for a one-tailed test with =0.05 and 14 degrees of freedom), we find that 7.52 is greater than 1.761.

Moreover, the p-value is less than our significance level of 0.05.

Hence, we reject the null hypothesis. This means that the sample data provides strong evidence to conclude that the average load time of the company’s website is longer than 3 seconds.

Please note that the t-test is a more robust test than the z-test and is generally preferred when the sample size is small or the population standard deviation is unknown.

Leave a Reply

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

DeepNeuron