Skip to content
Prev 75134 / 398502 Next

extract t-values from pairwise.t.test

Hallo

I am not sure but this could be what you want. You has to change 
function compare.levels not only add t.val in ans. If you want t-
values AND p-values together in one table it probably is not so 
simple.

my.pairded.t.test <- function (x, g, p.adjust.method = 
p.adjust.methods, pool.sd = TRUE,
    ...)
{
    DNAME <- paste(deparse(substitute(x)), "and", 
deparse(substitute(g)))
    g <- factor(g)
    p.adjust.method <- match.arg(p.adjust.method)
    if (pool.sd) {
        METHOD <- "t tests with pooled SD"
        xbar <- tapply(x, g, mean, na.rm = TRUE)
        s <- tapply(x, g, sd, na.rm = TRUE)
        n <- tapply(!is.na(x), g, sum)
        degf <- n - 1
        total.degf <- sum(degf)
        pooled.sd <- sqrt(sum(s^2 * degf)/total.degf)
        compare.levels <- function(i, j) {
            dif <- xbar[i] - xbar[j]
            se.dif <- pooled.sd * sqrt(1/n[i] + 1/n[j])
            t.val <- dif/se.dif
            #  2 * pt(-abs(t.val), total.degf) 	this is commented out
            t.val    # this is added
        }
    }
    else {
        METHOD <- "t tests with non-pooled SD"
        compare.levels <- function(i, j) {
            xi <- x[as.integer(g) == i]
            xj <- x[as.integer(g) == j]
            t.test(xi, xj, ...)$statistic     	# this is changed in case 
					          	# pool.sd=F
        }
    }
    PVAL <- pairwise.table(compare.levels, levels(g), 
p.adjust.method)
    ans <- list(method = METHOD, data.name = DNAME, p.value 
= PVAL,
        p.adjust.method = p.adjust.method)
    class(ans) <- "pairwise.htest"
    ans
}

HTH
Petr
On 8 Aug 2005 at 18:28, Guido Parra Vergara wrote:

            
Petr Pikal
petr.pikal at precheza.cz