10. Comparing Two Population Means

# 10.7 RStudio Lesson 6: Independent Sample t-Test

Let’s first download the excel dataset “Lesson 6 Data” from our course website and insert it into R. For this purpose, go to File Import Dataset From Excel… in R and click on Browse in the upper right of the new pop-up window to select the downloaded dataset from your computer. Then click Import.

To get the descriptive statistics, we will utilize the function \textit{describeBy} from the package psych. Remember to install the package if you already don’t have it.

Now to conduct the Levene’s Test for homogeneity of variances for the two groups, first we need to factor the species. Then we will use the function \textit{leveneTest} from the package car to perform this test.

To conduct the T-test to identify the equality of means, we will use the function \textit{t.test}. Here a thing to note is that since in Levene’s test we found that the variances of Sepal Lengths for the two species are different, we will set var.equal = FALSE in the argument of t-test.

Finally, to get the graphs of confidence interval and box plot for the two groups, we will utilize several functions from the packages dplyr and ggplot2. 