This function performs the t-test for one and two samples using summarized values, not the vectors.

t_test(
  meanx,
  varx,
  nx,
  meany = NULL,
  vary = NULL,
  ny = NULL,
  alternative = "two.sided",
  mu = 0,
  conf.level = 0.95,
  var.equal = FALSE
)

Arguments

meanx

sample mean for sample x.

varx

sample variance for sample x.

nx

sample size for sample x.

meany

sample mean for sample y.

vary

sample variance for sample y.

ny

sample size for sample y.

alternative

a character string specifying the alternative hypothesis, must be one of "two.sided" (default), "greater" or "less". You can specify just the initial letter.

mu

the hypothesized number (mean) in the null hypothesis.

conf.level

confidence level of the interval, by default its value is 0.95.

var.equal

a logical variable indicating whether to treat the two variances as being equal. If TRUE then the pooled variance is used to estimate the variance otherwise the Welch (or Satterthwaite) approximation to the degrees of freedom is used.

Value

A list with class "htest" containing the following components:

statistic

the value of the statistic.

parameter

the degrees of freedom for the t-statistic.

p.value

the p-value for the test.

conf.int

a confidence interval for the mean appropiate to the alternative hypothesis.

estimate

the estimated mean or difference in means depending on whether it was a one-sample test or a two-sample test.

null.value

the specified hypothesized value for alternative hypothesis value for the mean or mean difference depending on whether it was a one-sample test or a two-sample test.

alternative

a character string describing the alternative hypothesis.

method

a character string indicating the type of test performed.

Examples

# Examples with ONE sample

# Example 9.2 from Walpole
t_test(meanx=42, varx=11.9^2, nx=12, 
       mu=50, alternative='less')
#> 
#> 	One Sample t-test
#> 
#> data:  meanx = 42, var = 141.61 and nx = 12
#> t = -2.3288, df = 11, p-value = 0.01998
#> alternative hypothesis: true mean is less than 50
#> 95 percent confidence interval:
#>      -Inf 48.16928
#> sample estimates:
#> mean of x 
#>        42 
#> 

# Example 11.5 from A. F. Siegel & C. Morgan 
t_test(meanx=100, varx=12^2, nx=9,
       mu=83, alternative='two.sided')
#> 
#> 	One Sample t-test
#> 
#> data:  meanx = 100, var = 144 and nx = 9
#> t = 4.25, df = 8, p-value = 0.002799
#> alternative hypothesis: true mean is not equal to 83
#> 95 percent confidence interval:
#>   90.77598 109.22402
#> sample estimates:
#> mean of x 
#>       100 
#> 
       
# Example 11.6 from Murray        
t_test(meanx=0.053, varx=0.003^2, nx=10,
       mu=0.050, alternative='two.sided') 
#> 
#> 	One Sample t-test
#> 
#> data:  meanx = 0.053, var = 9e-06 and nx = 10
#> t = 3.1623, df = 9, p-value = 0.01151
#> alternative hypothesis: true mean is not equal to 0.05
#> 95 percent confidence interval:
#>  0.05085393 0.05514607
#> sample estimates:
#> mean of x 
#>     0.053 
#> 
       
# --- Examples with TWO-SAMPLES and equal variances ---

# Example 9.3 From Walpole
t_test(meanx=85, varx=4^2, nx=12,
       meany=81, vary=5^2, ny=10, 
       alternative='two.sided', mu=0, var.equal=TRUE)
#> 
#> 	Two Sample t-test
#> 
#> data:  meanx = 85 , nx = 12 , meany = 81 and ny = 10
#> t = 2.0863, df = 20, p-value = 0.04996
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  0.0006943214 7.9993056786
#> sample estimates:
#> mean of x mean of y 
#>        85        81 
#> 
      
# Example 13.5 from J. Freund's
t_test(meanx=546, varx=31^2, nx=4,
       meany=492, vary=26^2, ny=4, 
       alternative='two.sided', mu=0, var.equal=TRUE)  
#> 
#> 	Two Sample t-test
#> 
#> data:  meanx = 546 , nx = 4 , meany = 492 and ny = 4
#> t = 2.6693, df = 6, p-value = 0.03706
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>    4.499149 103.500851
#> sample estimates:
#> mean of x mean of y 
#>       546       492 
#> 
        
# --- Examples with TWO-SAMPLES and different variances ---

# Example from
t_test(meanx =6.8, varx=1.8^2, nx=13,
       meany=5.3, vary=1.6^2,  ny=15, 
       alternative='two.sided', mu=0, var.equal=FALSE)   
#> 
#> 	Welch Two Sample t-test
#> 
#> data:  meanx = 6.8, nx = 13, meany = 5.3 and ny = 15
#> t = 2.3148, df = 24.296, p-value = 0.02938
#> alternative hypothesis: true difference in means is not equal to 0
#> 95 percent confidence interval:
#>  0.1634666 2.8365334
#> sample estimates:
#> mean of x mean of y 
#>       6.8       5.3 
#>