Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

R t.test() Function - t-Test

R t.test() Function - t-Test

R Language Examples R Language Examples

The R t.test() function is used to perform a t-test, comparing whether the means of two groups differ significantly.

The t-test is one of the most commonly used hypothesis testing methods in statistical analysis.

The syntax of the t.test() function is as follows:

t.test(x, y = NULL, alternative = "two.sided", mu = 0, paired = FALSE, conf.level = 0.95)

Parameter Description:

Example

Independent two-sample t-test: comparing the effects of two teaching methods

method_a

<-

c

(

78

,

82

,

85

,

88

,

90

,

75

,

80

,

86

,

92

,

84

)

method_b

<-

c

(

72

,

75

,

78

,

76

,

80

,

70

,

74

,

77

,

79

,

73

)

Perform the t-test

result

<-

t.test

(

method_a, method_b

)

print

(

result

)

The output of the code above is:

    Welch Two Sample t-test



data:  method_a and method_b

t = 4.4029, df = 17.764, p-value = 0.0003513

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

95 percent confidence interval:

  4.640839 13.159161

sample estimates:

mean of x mean of y

     84.0      75.1

From the result, the p-value is far less than 0.05, indicating a significant difference in scores between the two teaching methods.

R Language Examples R Language Examples