extracting t value out of pairwise.t.test

随声附和 提交于 2019-12-01 18:30:41

问题


I would like to know if I could extract t values out of the pairwise.t.test function since it is only reporting the p values. I used the pairwise.t.test() for multiple comparisons after running a repeated-measures anova which reported a significant main effect.

Thank you alot in advance!


回答1:


There are some simple things to try when trying to figure something like this out (there is, of course, no guarantee that they will work in any given instance). The first thing to try is to look at the documentation (?pairwise.t.test) and see what's listed under Value. In this case it only says:

Object of class "pairwise.htest"

The second thing to try is to get an example object and assign it to a variable, then you can run str(obj). The following uses the example from the documentation:

attach(airquality)
Month <- factor(Month, labels = month.abb[5:9])
obj <- pairwise.t.test(Ozone, Month)
str(obj)
List of 4
 $ method         : chr "t tests with pooled SD"
 $ data.name      : chr "Ozone and Month"
 $ p.value        : num [1:4, 1:4] 1 0.000264 0.000195 1 NA ...
  ..- attr(*, "dimnames")=List of 2
  .. ..$ : chr [1:4] "Jun" "Jul" "Aug" "Sep"
  .. ..$ : chr [1:4] "May" "Jun" "Jul" "Aug"
 $ p.adjust.method: chr "holm"
 - attr(*, "class")= chr "pairwise.htest"

Unfortunately, that doesn't show what we'd like to see (e.g., something like $ t.stat).

Your last option is to look at the code. You can get it by typing the function call without parentheses at the command prompt:

> pairwise.t.test
function (x, g, p.adjust.method = p.adjust.methods, pool.sd = !paired, 
    paired = FALSE, alternative = c("two.sided", "less", "greater"), 
    ...) 
{
    <code omitted>
    if (pool.sd) {
        <code omitted>
        }
    }
    else {
        <code omitted>
        compare.levels <- function(i, j) {
            xi <- x[as.integer(g) == i]
            xj <- x[as.integer(g) == j]
            t.test(xi, xj, paired = paired, alternative = alternative, 
                ...)$p.value
        }
    }
    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
}

The key portion is the defined function compare.levels, which is only retaining the p-value from the underlying t-test. Thus, the straight answer to your question is no, you can't extract t-statistics.




回答2:


You can get t values (and also dfs) from pairwise.t.test by writing a custom function. See my previous post.



来源:https://stackoverflow.com/questions/28119426/extracting-t-value-out-of-pairwise-t-test

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!