# Implementing t-Test Blog

The T-Test is one of the most popular ways to test a hypothesis. It is essential for comparing the average values of the two data sets and determining if they came from the same population. In this blog post, you’ll see and learn how to implement the different types of t-Test (One-Sample t-Test, Two-Sample t-Test with equal and unequal Variance, and Paired t-Test).

ASSUMPTIONS FOR PERFORMING A T-TEST

1. The data should follow a continuous or ordinal scale.

2. The observations in the data should be randomly selected.

3. The data should resemble a bell-shaped curve when we plot it.

4. Large sample size should be taken for the data to approach a normal distribution.

5. Homogeneity of variance. Homogeneous or equal variance exists when the standard deviations of samples are approximately equal.

CHECKING ASSUMPTIONS

Normality

Histogram: To test the assumption of normality, inspect the data visually using a histogram. If your data looks like a bell curve: then it’s probably normal.

Box Plot: The Box Plot is another visualization technique that can be used for detecting non-normal samples. If your data comes from a normal distribution, the points on the graph will form a line.

Outliers

Outliers can be easily identified using boxplot methods, it is typically depicted by quartiles and inter quartiles that helps in defining the upper limit and lower limit beyond which any data lying will be considered as outliers.

Equality of Variance

This can be done using the Levene’s test. If the variances of groups are equal, the p-value should be greater than 0.05. Equal variances across samples is called homogeneity of variance.

IMPLEMENTING T-TEST

Implementing One Sample t-Test

The One-Sample t-Test is commonly used to test the statistical difference between a sample mean and a known or hypothesized value of the mean in the population. It is used to determine whether a sample of observations could have been generated by a process with a specific mean.

Example:

A Mathematics professor wants to know if his introductory statistics class has a good grasp of basic math. Seven students are chosen at random from the class and given a math proficiency test. The professor wants the class to be able to score above 70 on the test. The seven students got scores of 63, 65, 91, 76, 67, 84, and 96. Can the professor have 90% confidence that the mean score for the class on the test would be above 70?

Step 1: Write your null hypothesis statement. null hypothesisH 0: μ = 70

Step 2: Write your alternate hypothesis. alternative hypothesisa : μ > 70

Step 3: Identify the following information you’ll need to calculate the test statistic. The question should give you these items:

1. The sample mean (x̄)
2. The sample standard deviation(s)
3. The number of observations(n)
4. The standard error of the mean (SEM)
5. The hypothesized mean (μ)

1. Compute the sample mean (x̄)

2. Compute standard deviation (s)

3. Number of observations (n)

4. Compute the standard error of the mean (SEM)

5. Hypothesized mean (μ)

You can also calculate the sample mean, standard deviation, standard error, and count using the Descriptive Statistics tool.

Step 4: Compute the t‐value:

Step 5: Find the t-table value. To test the hypothesis, the computed t‐value of 1.49 will be compared to the critical value in the t‐table. You need two values to find this:

1. The alpha level:  A 90% confidence level is equivalent to an alpha level of 0.10
2. The degrees of freedom:

Because extreme values in one rather than two directions will lead to rejection of the null hypothesis, this is a one‐tailed test, and you do not divide the alpha level by 2. Look for 6 degrees of freedom in the left column and 0.10 in the top row. The intersection is 1.440. This is your one-tailed critical t-value. Because the computed t‐value of 1.49 is larger than the critical value in the table, the null hypothesis can be rejected,  and the professor has evidence that the class mean on the math test would be at least 70.

You can also calculate the p-value to test the hypothesis: Since the p-value (0.09) is below the alpha level (0.10), the null hypothesis can be rejected and should accept the alternative hypothesis.

Implementing Two-Sample t-Test

The Two-Sample t-Test is commonly used to determine and test whether the unknown population means of two groups are equal or not. It is used when you want to compare two independent groups to see if their means are different.

Two-Sample t-Test with equal variance

Example 1:

A marketing research firm tests the effectiveness of a new flavoring for a beverage using a sample of 20 people, half of whom taste the beverage with the old flavoring and the other half who taste the beverage with the new flavoring. The people in the study are then given a questionnaire that evaluates how enjoyable the beverage was. Determine whether there is a significant difference between the perception of the two flavorings.

Step 1: Write your null hypothesis statement. null hypothesis: H0μ1 – μ2 = 0; there is no difference between the two flavorings

Step 2: Write your alternate hypothesis. alternative hypothesis: a : μ 1 – μ 2  0

Step 3: Use MS Excel to perform a two-sample t-Test with equal variance: To perform a two-sample t-Test, on the Data tab, in the Analysis group, click Data Analysis. Choose a Two-Sample t-Test with equal variance and click OK.

In the dialog window, specify the Variable 1 RangeVariable 2 Range, Hypothesized Mean Difference which is always 0, and Output Range, then click OK.

Results

Statistical Interpretation of the Results

Since the p-value (0.04) is smaller than the level of significance (0.05), we reject the null hypothesis, concluding that there is a significant difference between the two flavorings.

Two-Sample t-Test with unequal variance

Example 2:

In the example of the Two-Sample t-Test with Equal Variances, we assumed that the population variances were equal since the sample variances were almost the same. We now repeat the analysis but with different data for the new flavoring and assuming that the variances are not necessarily equal.

Step 1: Write your null hypothesis statement. null hypothesis: H0μ1 – μ2 = 0; there is no difference between the two flavorings

Step 2: Write your alternate hypothesis. alternative hypothesis: a : μ 1 – μ 2  0

Step 3: Use MS Excel to perform a two-sample t-Test with unequal variance: To perform a two-sample t-Test, on the Data tab, in the Analysis group, click Data Analysis. Choose  Two-Sample t-Test with unequal variance and click OK.

In the dialog window, specify the Variable 1 RangeVariable 2 Range, Hypothesized Mean Difference which is always 0, and Output Range, then click OK.

Results

Statistical Interpretation of the Results

Since the p-value is much greater than the level of significance, we cannot reject the null hypothesis (for the two-tailed test).

Implementing Paired t-Test

The Paired t-test or sometimes called the dependent sample t-test is commonly used to compare two means that are from the same individual, object, or related units. It is used to determine whether the mean difference between two sets of observations is zero.

Example:

Suppose you work as a dietician and you want to test if the two weeks diet offered to your patient is effective. You collect the following weights in the first and second week.

Step 1: Write your null hypothesis statement. null hypothesis: H0: μ1st = μ2nd

Step 2: Write your alternate hypothesis. alternative hypothesis: Ha: μ1st > μ2nd

Step 3: Use MS Excel to perform a paired t-Test with unequal variance: To perform a paired t-Test, on the Data tab, in the Analysis group, click Data Analysis. Choose Paired t-Test and click OK.

In the dialog window, specify the Variable 1 RangeVariable 2 Range, Hypothesized Mean Difference, and Output Range, then click OK.

Results

Statistical Interpretation of the Results

Since the p-value(one-tail) is lower than the level of significance (0.05), we reject the null hypothesis. and conclude that the diet plan is effective.

Related Links:

How To Perform A One-Sample T-Test In Excel

How to run a t test two sample assuming equal variances in Excel 2013

How to run a t test two sample assuming unequal variances in Excel 2013

How to do a two sample t test paired two sample for means in Excel 2013