Rapporter / pander

An R Pandoc Writer: Convert arbitrary R objects into markdown
http://rapporter.github.io/pander/
Open Software License 3.0
294 stars 66 forks source link

please add cutoffs in add.significance.stars() #255

Closed landroni closed 8 years ago

landroni commented 8 years ago

Please add a cutoffs=c(0.05, 0.01, 0.001) argument to add.significance.stars(). Now the function defaults to the same cut off points as used in base R, c(0.05, 0.01, 0.001), but in other contexts other values may be more suitable (e.g. c(0.10, 0.05, 0.01).

landroni commented 8 years ago

Here's my attempt at addressing this:

add.significance.stars <- function(p, cutoffs=c(0.05, 0.01, 0.001)){
    stopifnot(length(cutoffs)==3)
    if (inherits(p, c("matrix", "data.frame")) && length(dim(p)) == 2) {
        apply(p, c(1, 2), add.significance.stars, cutoffs = cutoffs)
    }
    else {
        if (length(p) > 1) {
            sapply(p, add.significance.stars, cutoffs = cutoffs)
        }
        else {
            ifelse(p > cutoffs[1], "", ifelse(p > cutoffs[2], " *", 
                                              ifelse(p > cutoffs[3], " * *", " * * *")))
        }
    }
}
> xa <- c(2.34067096410392e-14, 0.045492875421418, 1.91932500195526e-40, 3.42330287138604e-15, NA)
> add.significance.stars(xa)  ##R defaults
[1] " * * *" " *"     " * * *" " * * *" NA      
> add.significance.stars(xa, c(0.10, 0.05, 0.01))  ##stargazer defaults
[1] " * * *" " * *"   " * * *" " * * *" NA      
daroczig commented 8 years ago

Thanks for this idea -- please see above commit & let me know how it works.

landroni commented 8 years ago

Looks good! Thanks