t-test in R-How to Perform T-tests in R

Student’s t test is the deviation of estimated mean from its population mean expressed in terms of standard error. In this article talking about how to perform t test in R, its assumptions and major properties.

Assumptions about t test:-

Majorly five assumptions for the t test.

  1. Random variable x follow or normal distribution or sample is drawn from normal population.
  2. All observations in the sample are independent.
  3. The sample size is small means that less than 30  and each group should not contain less than five observations.
  4. The hypothetical value of u0 of u is a correct value of population mean.
  5. Sample observations are correctly measured and recorded


The two major properties of t test

  1. t-Test is robust test, that means test which is not vitiated if assumptions not fully hold good.
  2. Most powerful unbiased test

When to use t test?

Test can be used for comparing two sample means. If more than 2 groups use ANOVA and followed by Tukey HSD or Dunnet multiple comparison test.

Types of t-Test:-

Different types of t test are available, which one need to use?

  1. Need to consider about sample type, one sample, two sample or paired sample.
  2. If single sample before and after kind of test use paired t-test.
  3. If two different independent samples use two-sample t-test.
  4. If one group being compared against a standard value, ie the weight of the group is 65kg or <65 kg or >65 kg use one-sample t-test.

One-tailed or two-tailed t-test?

If you only care whether the two populations are different from one another, perform a two-tailed t-test.

If you want to know whether one population mean is greater than or less than the other, perform a one-tailed t-test.

How to perform t test in R?

x1 = rnorm(10)

x2 = rnorm(10)

t.test(x1, x2 )

Welch two sample t-test

When to use welch two sample t-test, is assume unequal smaple variances in each group.

data: x1 and x2

 t = 1.6, df = 16.2, p-value =0.234

alternative hypothesis: true difference in means is not equal to 0

95 percent confidence interval: -0.33 1.6

sample estimates:

mean of x1 0.2444

mean of x2  -0.4533


p value is > 0.05 indicates no significant difference was observed between samples at 95%.

proportion test in R

One sample analysis in R


You may also like...

Leave a Reply

Your email address will not be published.

9 − two =


Subscribe Now