[R] extract t-values from pairwise.t.test
Petr Pikal
petr.pikal at precheza.cz
Mon Aug 8 12:00:25 CEST 2005
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:
> Hi,
>
> I am not familiar with changing R functions. I
> can see in the code that t-values get calculated
> as t. val, however when I modified the code to
> include t.val under ans and then run the modified
> function I get Object "t.val" not found. How do
> I properly modify the function to list t. val in the output?
>
> Thanks
> Guido
>
>
>
> At 05:20 PM 8/08/2005, Peter Dalgaard wrote:
> >Guido Parra Vergara <guido.parravergara at jcu.edu.au> writes:
> >
> > > Hi,
> > >
> > > how can I extract the t-values after running a pairwise.t.test?
> > > The output just list the p-values. Many thanks for your help.
> >
> >It's not a very complicated function. Why not just modify it to your
> >needs?
> >
> >--
> > O__ ---- Peter Dalgaard Řster Farimagsgade 5, Entr.B
> > c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
> > (*) \(*) -- University of Copenhagen Denmark Ph: (+45)
> > 35327918
> >~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45)
> >35327907
>
> ____________________________________
>
> Guido J. Parra
> School of Tropical Environment Studies and Geography
> James Cook University
> Townsville
> Queensland 4811
>
> Phone: 61 7 47815824
> Fax: 61 7 47814020
> Mobile: 0437630843
> e-mail: guido.parravergara at jcu.edu.au
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide!
> http://www.R-project.org/posting-guide.html
Petr Pikal
petr.pikal at precheza.cz
More information about the R-help
mailing list