Gosset_Welch: Student's and Welch–Satterthwaite Equation

View source: R/Gosset_Welch.R

Gosset_WelchR Documentation

Student's and Welch–Satterthwaite Equation

Description

To determine the degree of freedom, as well as the standard error, of two-sample t-statistic, with or without the equal-variance assumption.

Usage

Gosset_Welch(
  s1,
  s0,
  c1 = 1,
  c0 = 1,
  v1 = s1^2,
  v0 = s0^2,
  n1,
  n0,
  var.equal = FALSE
)

Arguments

s1, s0

(optional) double scalars or vectors, sample standard deviations s_1 and s_0 of the treatment and control sample, respectively

c1, c0

double scalars or vectors, multipliers c_1 and c_0 of the treatment and control sample, respectively, to test the hypothesis H_0: c_1\mu_1 - c_0\mu_0 = 0. Default c_1=c_0=1

v1, v0

double scalars or vectors, sample variances of the treatment and control sample, respectively. Default v_1=s_1^2, v_0=s_0^2.

n1, n0

integer scalars or vectors, sample sizes n_1 and n_0 of the treatment and control sample, respectively

var.equal

logical scalar, whether to assume v_1=v_0, default FALSE (as in function t.test.default).

Details

If v_1=v_0 is assumed, the standard error of two-sample t-statistic from William Sealy Gosset (a.k.a., Student) satisfies that s^2_{\bar\Delta}=s^2_p(1/n_1+1/n_0), with degree-of-freedom \text{df} = n_1+n_0-2, where s_p is the pooled standard deviation,

s^2_p=\dfrac{(n_1-1)v_1+(n_0-1)v_0}{n_1+n_0-2}

If v_1\neq v_0, the standard error of two-sample t-statistic satisfies that s^2_{\bar\Delta}=v_1/n_1 + v_0/n_0, with degree of freedom (Welch–Satterthwaite equation),

\text{df} = \dfrac{\left(\dfrac{v_1}{n_1}+\dfrac{v_0}{n_0}\right)^2}{\dfrac{(v_1/n_1)^2}{n_1-1}+\dfrac{(v_0/n_0)^2}{n_0-1}}

Value

Function Gosset_Welch returns a numeric scalar or vector of the degree of freedom, with attributes,

attr(., 'stderr')

numeric scalar or vector, standard error s_{\bar\Delta};

attr(., 'stderr2')

numeric scalar or vector, standard error squared s^2_{\bar\Delta}, included for downstream compute-intensive functions.

References

Student's t-test by William Sealy Gosset, \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/6.1.1")}.

Welch–Satterthwaite equation by Bernard Lewis Welch \Sexpr[results=rd]{tools:::Rd_expr_doi("10.1093/biomet/34.1-2.28")} and F. E. Satterthwaite \Sexpr[results=rd]{tools:::Rd_expr_doi("10.2307/3002019")}.

Examples

x = rnorm(32L, sd = 1.6); y = rnorm(57L, sd = 2.1)
vx = var(x); vy = var(y); nx = length(x); ny = length(y)
t.test(x, y, var.equal = FALSE)[c('parameter', 'stderr')]
Gosset_Welch(v1 = vx, v0 = vy, n1 = nx, n0 = ny, var.equal = FALSE)
t.test(x, y, var.equal = TRUE)[c('parameter', 'stderr')]
Gosset_Welch(v1 = vx, v0 = vy, n1 = nx, n0 = ny, var.equal = TRUE)

DanielBiostatistics10th documentation built on Oct. 16, 2024, 1:08 a.m.