Visualizing a two-tailed t-test in R

Anjan Dhungana
2 min readOct 31, 2023

All you are going to need is a base R and the library “gginference”. First, import your data or make a new dataset. In my case, I am given the live weights of one-year-old catfish in a pond.

I need to test whether or not the population mean of catfish weights is equal to 1.25 lbs. This means that this will be a two-tailed test.

Null hypothesis -> H­o: µ = 1.25

Alternative hypothesis -> Ha: µ ≠1.25

  1. Install “gginference” package:
install.packages("gginference")

2. You can import your dataset using file path using

data = read.csv("filepath\example.csv")

Here, I am making my own dataset with a single column.

data = c(1, 1.2, 0.9, 1.5, 0.7, 0.92, 2.01, 1.95, 1.72, 2)

3. Perform a t-test

Using the base R function t.test, you can perform a t-test. Here, I am assigning a variable t_test_result to my results of the t-test. Data is our data column and mu is the hypothetical population mean.

t_test_result = t.test(data, mu=1.25)

If you have multiple columns of data, you can select a single column by replacing the data argument in the following code with data$columnName.

The function t.test also takes an argument other than data and mu, named alternative. The above line gives the same result as the following code because the…

--

--

Anjan Dhungana
Anjan Dhungana

Written by Anjan Dhungana

Graduate @KYSU conducting research on ruminants. I talk about everything food and tech.

Responses (1)