Performing t-tests in R/RStudio for Lab7

The lab session on t tests is about comparing outcomes between two groups. We used R to conduct independent and paired t tests, checked assumptions, and visualized the data. We found a significant difference in self-esteem scores between men and women. The effect size was small, indicating a minor impact. Overall, the tests provided valuable insights into statistical interpretation. Let’s keep coding and learning! 📊📈👩‍💻


In this lab, we will be discussing t-tests and how to compare outcomes between two groups using R and RStudio. We will be covering independent t-tests, paired t-tests, and how to write scripts for lab work.

Key Takeaways

The key takeaways from this section are understanding the concepts of independent and paired t-tests, using R packages, and methods for conducting t-tests using RStudio.

Preparing the Data

Data Preparation


We begin by preparing the data for analysis. We have 136 observations and 2 variables. We will be adding new variables and modifying the existing dataset to suit our testing requirements.

Descriptive Statistics

Describing the Data

Missing ValuesMeanStandard Deviation

The descriptive statistics provide insights into the distribution of the data, allowing us to understand the variables and how they relate to our testing objectives.

Visual Inspection

We then proceed to visually inspect the data using histograms to check for normality before performing the Shapiro test.

Hypothesis Testing

Shapiro-Wilk Test

The Shapiro-Wilk test determines the normal distribution of the data. We utilize this test to verify if the data meets the assumption of normality for conducting t-tests.

Levene’s Test

Levene’s test is used to assess the homogeneity of variances between groups. This is crucial for determining the appropriate test to use and the validity of the results.

Independent T-Test

The independent t-test is conducted to analyze if there is a significant difference in average self-esteem scores between men and women.

Effect Size

The effect size is used to measure the magnitude of the difference found in the independent t-test, providing valuable information for interpretation.

Paired T-Test

The paired t-test is utilized to compare self-esteem scores before and after an intervention, providing insights into the effectiveness of the intervention.


Plots and graphs are used to visualize the distributions and results of the t-tests, aiding in the communication of the findings.


In conclusion, this lab has provided a comprehensive overview of conducting t-tests using R and RStudio. The various tests, methods, and visualizations have enabled a thorough analysis of the data and interpretation of the results.

Key Takeaways

  • Understanding the concepts and applications of t-tests
  • Utilizing R packages and functions for hypothesis testing
  • Interpretation and communication of statistical findings


  1. What is the importance of normality in t-tests?

    • Normality is crucial for ensuring the validity of t-test results and the accuracy of statistical inferences.
  2. How does effect size impact the interpretation of t-test results?

    • Effect size provides insights into the magnitude of differences found, aiding in the practical significance of the results.

This article is a comprehensive guide for conducting t-tests in R and RStudio, covering various aspects of hypothesis testing, interpretation, and visualization. By following the outlined methods and utilizing the recommended packages, users can effectively analyze and interpret t-test results for informed decision-making.


About the Author

About the Channel:

Share the Post: