Search code examples
rfdr

R 'fdrtool' package: how to use t statistic


Can one use t statistics from a Student's t-test directly in the fdrtool() function of fdrtool package (ver. 1.2.12)? The paper (Strimmer-K BMC Bioinfo. 2008, 9:303) mentions this but as far as I can see the parameters only recognize "normal", "correlation" and "pvalue". Is there a workaround for a non-statistician ?


Solution

  • I think it's a typo.

    I took a look at the source for the fdrtool function and found that the statistic argument first gets passed through match.arg and then to fdrtool:::get.nullmodel.

    Then, lo and behold:

    args(fdrtool:::get.nullmodel)
    # function (statistic = c("normal", "correlation", "pvalue", "studentt")) 
    # NULL
    

    and indeed there is a fully-implemented case in that function for the student t:

    if (statistic == "studentt") {
        f0 = function(x, param, log = FALSE) {
            return(dt(x, df = param, log = log))
        }
        F0 = function(x, param) {
            return(pt(x, df = param))
        }
        iqr = function(param) {
            return(qt(0.75, df = param) - qt(0.25, df = param))
        }
        get.support = function() return(c(1, 1000))
    }
    

    Now, before I tell you how to access this option, I want to warn you that it's very possible it was disabled on purpose. I can't imagine why, because at first glance it seems like it should work fine. But if you're planning to use this in a research result you ought to document the fact that this was essentially a "hidden" option and that you had to do some hacking to access it. Moreover, I haven't actually tested this on my computer, so beware of typos.

    Now, as for that hacking, the easiest way to get this to work would be to first simply type fdrtool into the R console. Then, copy and paste the output to a new R script (or use sink if you're fancy like that). The first few lines should look like:

    function (x, statistic = c("normal", "correlation", "pvalue"), 
        plot = TRUE, color.figure = TRUE, verbose = TRUE, cutoff.method = c("fndr", 
            "pct0", "locfdr"), pct0 = 0.75) 
    {
        statistic = match.arg(statistic)
    ...
    

    Then all you have to do is change c("normal", "correlation", "pvalue") to c("normal", "correlation", "pvalue", "studentt"). That is, the first few lines should now look like

    function (x, statistic = c("normal", "correlation", "pvalue", "studentt"), 
        plot = TRUE, color.figure = TRUE, verbose = TRUE, cutoff.method = c("fndr", 
            "pct0", "locfdr"), pct0 = 0.75) 
    {
        statistic = match.arg(statistic)
    ...
    

    Finally, reassign this function to fdrtool (don't worry, this won't break the underlying package, it will just act like a "mask" until you remove it with rm):

    fdrtool <- function (x, statistic = c("normal", "correlation", "pvalue", "studentt"), 
        plot = TRUE, color.figure = TRUE, verbose = TRUE, cutoff.method = c("fndr", 
            "pct0", "locfdr"), pct0 = 0.75) 
    {
        statistic = match.arg(statistic)
    ...
    

    And run the whole thing or source the script. Then you should be good to go.