Closed landroni closed 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
Thanks for this idea -- please see above commit & let me know how it works.
Looks good! Thanks
Please add a
cutoffs=c(0.05, 0.01, 0.001)
argument toadd.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)
.