t_test: Student's t-Test using values

View source: R/t_test.R

t_testR Documentation

Student's t-Test using values

Description

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

Usage

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')

# Example 11.5 from A. F. Siegel & C. Morgan 
t_test(meanx=100, varx=12^2, nx=9,
       mu=83, alternative='two.sided')
       
# Example 11.6 from Murray        
t_test(meanx=0.053, varx=0.003^2, nx=10,
       mu=0.050, alternative='two.sided') 
       
# --- 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)
      
# 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)  
        
# --- 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)   
    

fhernanb/stests documentation built on March 29, 2025, 10:36 a.m.