Lakens / TOSTER

TOST equivalence test and power functions
35 stars 18 forks source link

Suppress output #24

Closed rdotsch closed 6 years ago

rdotsch commented 6 years ago

Hi Daniel,

Thanks for the wonderful package. I am using it in a simulation scenario, where I only need to have the result object, but don't need to have all the verbal output printed to console. It would be useful to have a function argument to suppress output in functions such as TOSTone.raw.

Best,

Ron

Lakens commented 6 years ago

Hi Ron, yes, this is a feature we had been thinking about ourselves. We fooled ourselves this would not be used too much, but perhaps we were wrong :) We'll try to add a ' verbose=FALSE' option. For now, it might be relatively easy to take the code for the function, and just delete the lines that provide the output, and save it as a custom function? We are working on an update where the TOSTER functions will calculate both equivalence tests and Bayes factors (with Neil McLatchie and Zoltan Dienes). I'll add this to our to do list.

rdotsch commented 6 years ago

Hi Daniel,

Yes, a custom function is my current solution as well. TOSTER functions that give both eq tests and BFs are much more important. ;)

Thanks,

Ron

pederisager commented 6 years ago

Hi Ron,

You can suppress all output and assign it to an object (as a list) instead. Here is an example:

library(TOSTER)

invisible(capture.output(x <- TOSTtwo(1,1,1,1,4,4,-1,1)))

x

Now, this will also suppress the plot unfortunately. But with the data stored in x, you can recreate the plot, for example by using ggplot2:

library(ggplot2)

ggplot(data.frame()) +
  scale_x_continuous(breaks=NULL) +
  coord_flip() + # flip coordinates (puts labels on y axis)
  theme_classic(base_size = 10) + # use a white background
  geom_hline(yintercept=0, lty=1) +
  theme(plot.title = element_text(size = rel(1), face = "bold"),
        axis.title.y = element_blank(),
        axis.text.y = element_blank(),
        axis.ticks.y = element_blank(),
        axis.title.x = element_text(size=rel(0.7), lineheight = 0.5)) +
  annotate(geom = "pointrange", x = 0.5, y = x$diff, ymin = x$LL_CI_TTEST, ymax = x$UL_CI_TTEST, size = 1, fatten = 5) +
  annotate(geom = "pointrange", x = 0.5, y = x$diff, ymin = x$LL_CI_TOST, ymax = x$UL_CI_TOST, size = 2, fatten = 5) +
  geom_hline(yintercept=x$low_eqbound, lty=2) +
  geom_hline(yintercept=x$high_eqbound, lty=2) +
  labs(title = "Example title", y = "Effect (mean difference)") +
  ylim(c(x$low_eqbound*1.8, x$high_eqbound*1.8))

This might be easier than home-brewing the functions, and also allows you to store your plots as objects and customize them.

Hope that helps!

Peder

rdotsch commented 6 years ago

Hi Peder,

Thanks for the elaborate answer!

I had tried that too, but it interferes with the dplyr::progress_estimated() progress bar that I use (for some reason there's still some white space output that is not captured). I don't need the plot by the way, just the stats, so that's fine.

Ron

pederisager commented 6 years ago

Interesting, and good for us to know! Unfortunately, I don't have a quick fix for that one.

We have discussed whether a verbose option would make sense before, but then @Lakens came up with the capture.output() solution. However, if that does not mix well with dplyr functionality we should definitely include an option for this in a future update.

Peder

Lakens commented 6 years ago

I think it is time to fix the cat() printed text anyway - while at it, we might as well add the verbose option.

Lakens commented 6 years ago

I have added a verbose option (TRUE or FALSE) to the package on Github (this version is not yet on CRAN).