Skip to content

Commit

Permalink
updates documentation and add units argument
Browse files Browse the repository at this point in the history
  • Loading branch information
Ignacio Martinez committed Apr 17, 2019
1 parent 0d9f691 commit 6e64958
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 25 deletions.
15 changes: 9 additions & 6 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
Package: IMPosterior
Title: Plot the posterior distribution
Version: 0.5
Version: 0.6
Authors@R: c(
person("Ignacio", "Martinez", email = "[email protected]", role = c("aut", "cre")),
person("Linus", "Marco", email = "LMarco@mathematica-mpr.com", role = "aut"))
Description: What the package does (one paragraph).
person("Linus", "Marco", email = "lmarco163@gmail.com", role = "aut"))
Description: Plot the posterior distribution and the probabilities of being to the right or left of a threshold.
Depends: R (>= 3.4.2)
License: GPL-3
Encoding: UTF-8
LazyData: true
Imports: dplyr,
Imports:
dplyr,
tidyr,
glue
RoxygenNote: 6.0.1
glue,
htmlwidgets,
magrittr
RoxygenNote: 6.1.1
2 changes: 1 addition & 1 deletion NAMESPACE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Generated by roxygen2: do not edit by hand

export("%>%")
export(IMPosterior)
export(IMPosteriorOutput)
export(renderIMPosterior)
import(htmlwidgets)
importFrom(magrittr,"%>%")
57 changes: 43 additions & 14 deletions R/IMPosterior.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,31 @@
#' <Add Title>
#' @title IMPosterior
#'
#' <Add Description>
#'
#' @import htmlwidgets
#' @importFrom magrittr "%>%"
#' @param x draws from the the posterior
#' @param MME minimum meaninful effect
#' @param threshold if the probability is greater than this threshold, you would feel confortable making a decision
#' @param units the units of x. For example, dollars or applications
#' @param colors colors for the left, middle, and right areas. The defaults are c("#e41a1c", "#377eb8", "#4daf4a")
#' @param width width for shiny
#' @param height height for shiny
#' @param elementId elementID for shiny
#'
#' @return
#' @export
IMPosterior <- function(x, MME = 0, threshold = 0.75, colors,
#'
#' @examples
#' if(interactive()){
#' set.seed(9782)
#' x <- rnorm(1000)
#' library(IMPosterior)
#' IMPosterior(x= x, MME=1)
#' }

IMPosterior <- function(x, MME = 0, threshold = 0.75, units = NULL,
colors,
width = NULL, height = NULL,
elementId = NULL) {
if(MME<0) stop("MME should be non-negative")
if(MME<0) stop("MME should be greater than 0")
if(threshold<=0 | threshold>=1) stop("threshold should be between 0 and 1")
# Set colors

if(missing(colors)){
Expand All @@ -36,17 +52,30 @@ IMPosterior <- function(x, MME = 0, threshold = 0.75, colors,
tidyr::complete(section, fill=list(prob="0%"))

# Gen text
left <- glue::glue('Your data suggest that there is a {sp$prob[[1]]} probability that the intervention has a negative effect of {MME} or more.')
if(MME!=0){
middle <- glue::glue('Your data suggest that there is a {sp$prob[[2]]} probability that the effect of the intervention between -{MME} and {MME}, which we consider negligible')
right <- glue::glue('Your data suggest that there is a {sp$prob[[3]]} probability that the intervention has a positive effect of {MME} or more.')
text <- c(left, middle, right)
if(is.null(units)){
left <- glue::glue('Your data suggest that there is a {sp$prob[[1]]} probability that the intervention has a negative effect of {MME} or more.')
if(MME!=0){
middle <- glue::glue('Your data suggest that there is a {sp$prob[[2]]} probability that the effect of the intervention between -{MME} and {MME}, which is considered negligible')
right <- glue::glue('Your data suggest that there is a {sp$prob[[3]]} probability that the intervention has a positive effect of {MME} or more.')
text <- c(left, middle, right)
}else{
right <- glue::glue('Your data suggest that there is a {sp$prob[[2]]} probability that the intervention has a positive effect of {MME} or more.')
text <- c(left, right)
}
}else{
right <- glue::glue('Your data suggest that there is a {sp$prob[[2]]} probability that the intervention has a positive effect of {MME} or more.')
text <- c(left, right)
left <- glue::glue('Your data suggest that there is a {sp$prob[[1]]} probability that the intervention has a negative effect of {MME} {units} or more.')
if(MME!=0){
middle <- glue::glue('Your data suggest that there is a {sp$prob[[2]]} probability that the effect of the intervention between -{MME} and {MME} {units}, which is considered negligible')
right <- glue::glue('Your data suggest that there is a {sp$prob[[3]]} probability that the intervention has a positive effect of {MME} {units} or more.')
text <- c(left, middle, right)
}else{
right <- glue::glue('Your data suggest that there is a {sp$prob[[2]]} probability that the intervention has a positive effect of {MME} {units} or more.')
text <- c(left, right)
}
}



if(MME!=0){
bars <- data.frame(y = as.numeric(sub("%", "", sp$prob))/100,
x = c("Worse", "Equivalent", "Better"),
Expand Down
33 changes: 29 additions & 4 deletions man/IMPosterior.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6e64958

Please sign in to comment.