Tests for Difference: Comparing Two groups [Independent Groups]
In this guide we will be going through the steps for tests for difference when comparing two groups. We will be analysing two variables at a time: one variable (scale) and the other variable nominal with two response options. The aim is to identify whether the two groups differ from each other in their response to a scale (DV) variable.
When comparing two groups either a t-test (parametric) or Mann-Whitney test (Non-parametric) is to be used, which test is selected depends upon assumption testing so these always need to be tested for first.
As a reminder the three parametric assumptions are
1. The dependent variable must be measured at the Interval level (Scale/Ordinal) and the
independent variables must be measured at the Categorical level.
2. Be normally distributed
3. Be of equal variance (homogeneity)
Let’s begin with an example…
We will be continuing to use Gender and LifeSat to go through the steps for Test for Difference, we’ve already done parametric assumption testing for these variables, all parametric assumptions were met and a t-test was chosen for further analysis.
You use t-test ONLY if data fulfils the condition of both normality and homogeneity of variance. If one or more conditions aren’t met a Mann-Whitney test should be used.
Running a t-test in R Studio.
To run a t-test in R studio the following command should be inserted into the top left script.
t.test(opintfd$`Life Sat`~ opintfd$Gender)
The following output will be produced documenting the results of the t-test.
Looking at the sig. value we need to compare it with the threshold value (0.05) which we normally use for hypotheses. If the sig. value is less than 0.05, we would reject our null hypothesis and accept our research hypothesis, there is a difference.
In this example this value is more than the threshold value. Therefore, we fail to reject the null hypothesis. The findings of this study do not suggest that British people’s life satisfaction differs by Gender.
The result of the t-test (Mean Male= 7.64; Mean female =7.69; t=-.627; df=1902; p=.530) is not statistically significant at the 0.05 level. We therefore fail to reject the null hypothesis. The findings of this study do not provide evidence to suggest that British people’s life satisfaction differs by gender.
Running a Mann-Whitney test in R Studio
In the previous intensive for parametric assumptions, you were set an activity to test for assumptions for the hypothesis: Life Satisfaction will differ according to ethnicity in Great Britain. If done correctly you will have noticed that this data violated the assumptions for homogeneity and thus a non-parametric test Mann-Whitney would have to be selected. We will use these variables to demonstrate how to conduct a Mann-Whitney test.
Mann-whitney Command: wilcox.test(opintfd$`Life Sat` ~ opintfd$Ethnicity)
The result of the Mann-Whitney test (W= 183403; p=.219) isn’t statistically significant at the 0.05 level. We therefore fail to reject the null hypothesis. The findings of this study failed to provide evidence that British peoples life satisfaction differs by ethnicity.