Two sample T-Test Approach

It is used to help us to understand whether the difference between the two means is real or simply by chance. 
The general form of the test is t.test(y1, y2, paired=FALSE). By default, R assumes that the variances of y1 and y2 are unequal, thus defaulting to Welch’s test. To toggle this, we use the flag var.equal=TRUE.

For Example: 

R




set.seed(0)
 
shopOne <- rnorm(50, mean = 140, sd = 4.5)
shopTwo <- rnorm(50, mean = 150, sd = 4)
 
t.test(shopOne, shopTwo, var.equal = TRUE)


Output:

    Two Sample t-test

data:  shopOne and shopTwo
t = -13.158, df = 98, p-value < 2.2e-16
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
 -11.482807  -8.473061
sample estimates:
mean of x mean of y 
 140.1077  150.0856 
  • Sample estimates: 140.1077 for the mean of x and 150.0856 for the mean of y the sample means (x and y), which are the sample estimates. In this instance, shopOne’s mean is 140.1077, whereas shopTwo’s mean is 150.0856.

T-Test Approach in R Programming

We will be trying to understand the T-Test in R Programming with the help of an example. Suppose a businessman with two sweet shops in a town wants to check if the average number of sweets sold in a day in both stores is the same or not. 

So, the businessman takes the average number of sweets sold to 15 random people in the respective shops. He found out that the first shop sold 30 sweets on average whereas the second shop sold 40. So, from the owner’s point of view, the second shop was doing better business than the former. But the thing to notice is that the data set is based on a mere number of random people and they cannot represent all the customers. This is where T-testing comes into play it helps us to understand whether the difference between the two means is real or simply by chance.

Mathematically, what the t-test does is, take a sample from both sets and establish the problem assuming a null hypothesis that the two means are the same.

Classification of T-tests

  • One Sample T-test
  • Two sample T-test
  • Paired sample T-test

Similar Reads

One Sample T – Test Approach

The One-Sample T-Test is used to test the statistical difference between a sample mean and a known or assumed/hypothesized value of the mean in the population....

Two sample T-Test Approach

...

Paired Sample T-test

It is used to help us to understand whether the difference between the two means is real or simply by chance. The general form of the test is t.test(y1, y2, paired=FALSE). By default, R assumes that the variances of y1 and y2 are unequal, thus defaulting to Welch’s test. To toggle this, we use the flag var.equal=TRUE....

Differences between one-sample, two-sample, and paired-sample t-tests:

...