Unequal Variance t-test in R:- Welch’s t-Test

Unequal Variance t-test in R, When the variances of two independent groups are not considered to be equal, Welch’s t-test is used to compare their means.

We can use the t.test() function in R to execute Welch’s t-test, which has the following syntax.

t.test(x, y, alternative = c(“two.sided”, “less”, “greater”))

where:

x: For the first group, a numeric vector of data values

y: For the second group, a numeric vector of data values

alternative: For the test, the alternative hypothesis. two.sided is the default.

paired t-test tabled value vs p-value »

The following example explains how to execute a Welch’s t-test in R using this function.

Example: Welch’s t-test in R

An instructor wishes to compare the exam scores of 12 students who used an exam prep guide A vs B.

The following vectors depict the exam results for each set of students:

A <- c(80, 75, 78, 99, 91, 71, 72, 88, 82, 81, 99, 98)
B<- c(54, 85, 61, 75, 80, 88, 77, 76, 74, 76, 83, 81)

We may generate boxplots to visualize the distribution of results for each group before performing a Welch’s t-test:

boxplot(A, B, names=c("A","B"))

Welch’s t-test in R

The “A” group has a higher mean score and shows differences in variances.

var(A)
[1] 106.0909
var(B)
[1] 93.60606

We can use Welch’s t-test to determine whether the mean scores between the groups are substantially different:

do a Welch’s t-test

t.test(A, B)
               Welch Two Sample t-test
data:  A and B
t = 2.1245, df = 21.914, p-value = 0.04515
alternative hypothesis: true difference in means is not equal to 0
95 percent confidence interval:
  0.2046142 17.1287192
sample estimates:
mean of x mean of y
 84.50000  75.83333

The t-test statistic is 2.12, and the related p-value is 0.045, as shown in the output.

We may reject the null hypothesis and conclude that there is a statistically significant difference in mean exam scores between the two groups because the p-value is less than 0.05.

We can also get the following information from the t.test() function:

The difference in mean exam scores between the two groups has a 95 percent confidence interval of [0.20, 17.12].

The first group’s average exam score is 84.5, whereas the second group’s average exam score is 75.83.

You may also like...

Leave a Reply

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

3 × four =