Performs Tamhane's T2 (or T2') all-pairs comparison test for normally distributed data with unequal variances.
tamhaneT2Test(x,...)## Default S3 method:tamhaneT2Test(x, g, welch =TRUE,...)## S3 method for class 'formula'tamhaneT2Test(formula, data, subset, na.action, welch =TRUE,...)## S3 method for class 'aov'tamhaneT2Test(x, welch =TRUE,...)
Arguments
x: a numeric vector of data values, a list of numeric data vectors or a fitted model object, usually an aov fit.
...: further arguments to be passed to or from methods.
g: a vector or factor object giving the group for the corresponding elements of "x". Ignored with a warning if "x" is a list.
welch: indicates, whether Welch's approximate solution for calculating the degree of freedom shall be used or, as usually, df=N−2. Defaults to TRUE.
formula: a formula of the form response ~ group where response gives the data values and group a vector or factor of the corresponding groups.
data: an optional matrix or data frame (or similar: see model.frame) containing the variables in the formula formula. By default the variables are taken from environment(formula).
subset: an optional vector specifying a subset of observations to be used.
na.action: a function which indicates what should happen when the data contain NAs. Defaults to getOption("na.action").
Returns
A list with class "PMCMR" containing the following components:
method: a character string indicating what type of test was performed.
data.name: a character string giving the name(s) of the data.
statistic: lower-triangle matrix of the estimated quantiles of the pairwise test statistics.
p.value: lower-triangle matrix of the p-values for the pairwise tests.
alternative: a character string describing the alternative hypothesis.
p.adjust.method: a character string describing the method for p-value adjustment.
model: a data frame of the input data.
dist: a string that denotes the test distribution.
Details
For all-pairs comparisons in an one-factorial layout with normally distributed residuals but unequal groups variances the T2 test (or T2' test) of Tamhane can be performed. Let Xij denote a continuous random variable with the j-the realization (1≤j≤ni) in the i-th group (1≤i≤k). Furthermore, the total sample size is N=∑i=1kni. A total of m=k(k−1)/2
hypotheses can be tested: The null hypothesis is Hij:μi=μj(i=j) is tested against the alternative Aij:μi=μj (two-tailed). Tamhane T2 all-pairs test statistics are given by
tij(sj2/nj+si2/ni)1/2Xˉi−Xjˉ,(i=j)
with si2 the variance of the i-th group. The null hypothesis is rejected (two-tailed) if
Pr{∣tij∣≥tvijα′/2∣H}ij=α.
T2 test uses Welch's approximate solution for calculating the degree of freedom.
T2' test applies the following approximation for the degree of freedom
vij=ni+nj−2
The p-values are computed from the TDist-distribution and adjusted according to Dunn-Sidak.
pij′=min{1,(1−(1−pij)m)}
Note
T2 test is basically an all-pairs pairwise-t-test. Similar results can be obtained with pairwise.t.test(..., var.equal=FALSE, p.adjust.mehod = FALSE).
A warning message appears in the modified T2' test, if none of in Tamhane (1979) given conditions for nearly balanced sample sizes and nearly balanced standard errors is true.
Thanks to Sirio Bolaños for his kind suggestion for adding T2' test into this function.
Examples
fit <- aov(weight ~ feed, chickwts)shapiro.test(residuals(fit))bartlett.test(weight ~ feed, chickwts)# var1 = varNanova(fit)## also works with fitted objects of class aovres <- tamhaneT2Test(fit)summary(res)summaryGroup(res)res
## compare with pairwise.t.testWT <- pairwise.t.test(chickwts$weight, chickwts$feed, pool.sd =FALSE, p.adjust.method ="none")p.adj.sidak <-function(p, m) sapply(p,function(p) min(1,1-(1- p)^m))p.raw <- as.vector(WT$p.value)m <- length(p.raw[!is.na(p.raw)])PADJ <- matrix(ans <- p.adj.sidak(p.raw, m), nrow =5, ncol =5)colnames(PADJ)<- colnames(WT$p.value)rownames(PADJ)<- rownames(WT$p.value)PADJ
## same without Welch's approximate solutionsummary(T2b <- tamhaneT2Test(fit, welch =FALSE))
References
Tamhane, A. C. (1979) A Comparison of Procedures for Multiple Comparisons of Means with Unequal Variances, Journal of the American Statistical Association 74 , 471--480.