12.5 C
London
Sunday, July 7, 2024
HomeRHypothesis Tests in RHow to Perform a One Sample T-Test in R

How to Perform a One Sample T-Test in R

Related stories

Learn About Opening an Automobile Repair Shop in India

Starting a car repair shop is quite a good...

Unlocking the Power: Embracing the Benefits of Tax-Free Investing

  Unlocking the Power: Embracing the Benefits of Tax-Free Investing For...

Income Splitting in Canada for 2023

  Income Splitting in Canada for 2023 The federal government’s expanded...

Can I Deduct Home Office Expenses on my Tax Return 2023?

Can I Deduct Home Office Expenses on my Tax...

Canadian Tax – Personal Tax Deadline 2022

  Canadian Tax – Personal Tax Deadline 2022 Resources and Tools...

A one sample t-test is used to determine whether or not the mean of a population is equal to some value.

You can use the following basic syntax in R to perform a one sample t-test:

t.test(data, mu=10)

The following example shows how to use this syntax in practice.

Example: One Sample T-Test in R

Suppose a botanist wants to know if the mean height of a certain species of plant is equal to 15 inches.

She collects a simple random sample of 12 plants and records each of their heights in inches.

She can use the following code to perform a one sample t-test in R to determine if the mean height for this species of plant is actually equal to 15 inches:

#create vector to hold plant heights
my_data #perform one sample t-test
t.test(my_data, mu=15)

	One Sample t-test

data:  my_data
t = -1.6848, df = 11, p-value = 0.1201
alternative hypothesis: true mean is not equal to 15
95 percent confidence interval:
 13.46244 15.20423
sample estimates:
mean of x 
 14.33333 

Here is how to interpret each value in the output:

data: The name of the vector used in the t-test. In this example, we used my_data.

t: The t test-statistic, calculated as (x – μ) / (s√n) = (14.333-15)/(1.370689/√12) = -1.6848.

df: The degrees of freedom, calculated as n-1 = 12-1 = 11.

p-value: The two-tailed p-value that corresponds to a t test-statistic of -1.6848 and 11 degrees of freedom. In this case, p = 0.1201.

95 percent confidence interval: The 95% confidence for the true population mean, calculated to be [13.46244, 15.20423].

The null and alternative hypotheses for this one sample t-test are as follows:

H0µ = 15 (the mean height for this species of plant is 15 inches)

HAµ ≠15 (the mean height is not 15 inches)

Because the p-value of our test (0.1201) is greater than 0.05, we fail to reject the null hypothesis of the test.

This means we do not have sufficient evidence to say that the mean height for this particular species of plant is different from 15 inches.

Additional Resources

The following tutorials explain how to perform other common tests in R:

How to Perform a Two Sample T-Test in R
How to Perform a Paired Samples T-Test in R
How to Perform Welch’s T-Test in R

Subscribe

- Never miss a story with notifications

- Gain full access to our premium content

- Browse free from up to 5 devices at once

Latest stories