Laerd Statistics LoginCookies & Privacy

Independent-samples t-test using R, Excel and RStudio (page 3)

On the previous page you learnt how to set up your data using Excel, R and RStudio, based on the example we use throughout this introductory guide. On this page we show you how to: (a) carry out an independent-samples t-test using the t.test () function; (b) generate useful descriptive statistics including the group means, standard deviations, sample sizes, and the mean difference. Therefore, start by learning how to use the t.test () function to carry out an independent-samples t-test in the next section.

R and RStudio

Running an independent-samples t-test using R in RStudio

The independent-samples t-test is run using R code in RStudio, which you enter into the RStudio Console (i.e., under the Consule tab in RStudio tab), as shown below:

The Console box in RStudio where R code is entered to run an independent-samples t-test

In the three steps that follow we explain how to run an independent-samples t-test using R:

The t.test() function we have just demonstrated provides the minimum results required to understand an independent-samples t-test, such as the t-value, degrees of freedom (df), statistical significance value (i.e., the p-value), 95% confidence interval (CI) of the mean difference, and the mean score for each of your two groups. Each of these statistics will be explained later in the section: Interpreting the independent-samples t-test results. However, there are additional descriptive statistics that are required to get a more complete understanding of your results when running an independent-samples t-test that are not provided by the t.test() function. Therefore, in the next section we explain how to generate these descriptive statistics using R in RStudio.

R and RStudio

Generating descriptive statistics for an independent-samples t-test using R in RStudio

When carrying out an independent-samples t-test, we want to be able to compare the two groups of our independent variable descriptively in terms of the dependent variable. Useful descriptive statistics include the group means, standard deviations, sample sizes, and the mean difference, which is the difference between the two group means. Only the group means are generated by the t.test() function in the previous section. Therefore, the following five steps show you how to generate these descriptive statistics.

You have now run the independent-samples t-test and generated useful descriptive statistics to help you determine whether there is a statistically significant difference between the two groups of your independent variable in terms of your dependent variable. On the next page we explain how to interpret these results.

1 2 3 4