Skip to content

Commit

Permalink
some first workings
Browse files Browse the repository at this point in the history
  • Loading branch information
audreyyeoCH committed Jan 7, 2025
1 parent c475a98 commit e500868
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 15 deletions.
25 changes: 21 additions & 4 deletions R/plotOc.R
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
#' 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
#'
#' @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)
Expand Down
45 changes: 41 additions & 4 deletions examples/plotOc.R
Original file line number Diff line number Diff line change
@@ -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())
51 changes: 44 additions & 7 deletions man/plotOc.Rd

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

0 comments on commit e500868

Please sign in to comment.