From e500868b3d2d5ef5596175d338b493c1d6a867dc Mon Sep 17 00:00:00 2001 From: Audrey Yeo Date: Tue, 7 Jan 2025 10:50:31 +0100 Subject: [PATCH] some first workings --- R/plotOc.R | 25 +++++++++++++++++++---- examples/plotOc.R | 45 +++++++++++++++++++++++++++++++++++++---- man/plotOc.Rd | 51 ++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 106 insertions(+), 15 deletions(-) diff --git a/R/plotOc.R b/R/plotOc.R index c4765cdd..9806db9a 100644 --- a/R/plotOc.R +++ b/R/plotOc.R @@ -1,9 +1,10 @@ #' Display the operating characteristics using an oc object #' -#' Reads results from \code{\link{ocPredprob}}, \code{\link{ocPostprob}} +#' Reads results from [ocPredprob()] #' etc. and displays a bar plot of the operating characteristics #' -#' @param z returned oc value +#' @typed oc : list +#' returned oc parameters #' @return nothing, only plots as side effect #' #' @importFrom graphics barplot title @@ -11,9 +12,25 @@ #' @example examples/plotOc.R #' @export #' @keywords graphics -plotOc <- function(z) { +plotOc <- function(oc) { + + if (wiggle == FALSE) { + data <- table(oc$Decision, oc$SampleSize) / oc$params$sim + } else { + + } + +ggplot(oc, aes(x = name, y = value)) + + geom_bar(stat = "identity") + + ggtitle("Percentage of trials that Go and Stop per look") + + ylabs("Percentage %") + + xlabs("Looks and sample size") + + + ## plot function for oc.predprob or oc.postprob, or the dist versions of them - graphics::barplot(table(z$Decision, z$SampleSize) / z$params$sim, beside = TRUE) + graphics::barplot(table(oc$Decision, oc$SampleSize) / oc$params$sim, beside = TRUE) + ## get the parameter parDat <- lapply(z$params, deparse) diff --git a/examples/plotOc.R b/examples/plotOc.R index 930ca464..647979d1 100644 --- a/examples/plotOc.R +++ b/examples/plotOc.R @@ -1,9 +1,46 @@ # get operating character result from oc.postprob -res1 <- ocPostprob( +oc <- ocPostprob( nnE = c(10, 20, 30), truep = 0.4, p0 = 0.2, - p1 = 0.3, tL = 0.6, tU = 0.8, parE = c(1, 1), sim = 50000 + p1 = 0.3, tL = 0.6, tU = 0.8, parE = c(1, 1), sim = 100, wiggle = FALSE ) -res1$oc +oc$oc +# plotOc(oc) -plotOc(res1) + +oc <- ocPostprob( + nnE = c(10, 20, 30), truep = 0.4, p0 = 0.2, + p1 = 0.3, tL = 0.6, tU = 0.8, parE = c(1, 1), sim = 100, wiggle = TRUE +) +oc$oc + +data <- data.frame(Decision = as.factor(oc$Decision), + Looks = oc$SampleSize) + +table(data$Decision, data$Looks) + +data %>% group_by(Decision, Looks) %>% summarise(n = n()) + +data %>% group_by(SampleSize) %>% summarise(n = n()) + +ggplot(dat, aes(x = SampleSize, y = Decision)) + + geom_bar(stat = "identity") + +data %>% group_by(Looks, Decision) %>% summarise(tot = n()) + + +table(oc$Decision, oc$SampleSize) / oc$params$sim +table(oc$Decision, oc$SampleSize) + +oc$Decision <- ifelse(oc$Decision == TRUE, "GO", + ifelse(oc$Decision == FALSE, "Stop", "Grey")) + +oc$Decision + +data.frame(looks = c(res1$wiggled_nnrE)) + +table(oc$Decision, oc$SampleSize) + +tt = data.frame(Decision = res$Decision, + look = res$SampleSize) +tt %>% group_by(look) %>% summarise(success = per()) diff --git a/man/plotOc.Rd b/man/plotOc.Rd index 16389213..76965376 100644 --- a/man/plotOc.Rd +++ b/man/plotOc.Rd @@ -4,27 +4,64 @@ \alias{plotOc} \title{Display the operating characteristics using an oc object} \usage{ -plotOc(z) +plotOc(oc) } \arguments{ -\item{z}{returned oc value} +\item{oc}{(\code{list}):\cr returned oc parameters} } \value{ nothing, only plots as side effect } \description{ -Reads results from \code{\link{ocPredprob}}, \code{\link{ocPostprob}} +Reads results from \code{\link[=ocPredprob]{ocPredprob()}} etc. and displays a bar plot of the operating characteristics } \examples{ # get operating character result from oc.postprob -res1 <- ocPostprob( +oc <- ocPostprob( nnE = c(10, 20, 30), truep = 0.4, p0 = 0.2, - p1 = 0.3, tL = 0.6, tU = 0.8, parE = c(1, 1), sim = 50000 + p1 = 0.3, tL = 0.6, tU = 0.8, parE = c(1, 1), sim = 100, wiggle = FALSE ) -res1$oc +oc$oc +# plotOc(oc) -plotOc(res1) + +oc <- ocPostprob( + nnE = c(10, 20, 30), truep = 0.4, p0 = 0.2, + p1 = 0.3, tL = 0.6, tU = 0.8, parE = c(1, 1), sim = 100, wiggle = TRUE +) +oc$oc + +data <- data.frame(Decision = as.factor(oc$Decision), + Looks = oc$SampleSize) + +table(data$Decision, data$Looks) + +data \%>\% group_by(Decision, Looks) \%>\% summarise(n = n()) + +data \%>\% group_by(SampleSize) \%>\% summarise(n = n()) + +ggplot(dat, aes(x = SampleSize, y = Decision)) + + geom_bar(stat = "identity") + +data \%>\% group_by(Looks, Decision) \%>\% summarise(tot = n()) + + +table(oc$Decision, oc$SampleSize) / oc$params$sim +table(oc$Decision, oc$SampleSize) + +oc$Decision <- ifelse(oc$Decision == TRUE, "GO", + ifelse(oc$Decision == FALSE, "Stop", "Grey")) + +oc$Decision + +data.frame(looks = c(res1$wiggled_nnrE)) + +table(oc$Decision, oc$SampleSize) + +tt = data.frame(Decision = res$Decision, + look = res$SampleSize) +tt \%>\% group_by(look) \%>\% summarise(success = per()) } \keyword{graphics}