if(require("data.table"))setDTthreads(1L)#for CRAN check.
## Simple synthetic example with two changes in error function.
simple.df <- data.frame(
example=1L,
min.lambda=c(0, exp(1), exp(2), exp(3)),
fp=c(6,2,2,0),
fn=c(0,1,1,5))
(simple.diffs <- aum::aum_diffs_penalty(simple.df))
if(requireNamespace("ggplot2"))plot(simple.diffs)
(simple.rates <- aum::aum_diffs_penalty(simple.df, denominator="rate"))
if(requireNamespace("ggplot2"))plot(simple.rates)
## Simple real data with four example, one has non-monotonic fn.
if(requireNamespace("penaltyLearning")){
data(neuroblastomaProcessed, package="penaltyLearning", envir=environment())
## assume min.lambda, max.lambda columns only? use names?
nb.err <- with(neuroblastomaProcessed$errors, data.frame(
example=paste0(profile.id, ".", chromosome),
min.lambda,
max.lambda,
fp, fn))
(nb.diffs <- aum::aum_diffs_penalty(nb.err, c("1.2", "1.1", "4.1", "4.2")))
if(requireNamespace("ggplot2"))plot(nb.diffs)
}
## More complex real data example
data(fn.not.zero, package="aum", envir=environment())
pred.names <- unique(fn.not.zero$example)
(fn.not.zero.diffs <- aum::aum_diffs_penalty(fn.not.zero, pred.names))
if(requireNamespace("ggplot2"))plot(fn.not.zero.diffs)
if(require("ggplot2")){
name2id <- structure(seq(0, length(pred.names)-1L), names=pred.names)
fn.not.zero.wide <- fn.not.zero[, .(example=name2id[example], min.lambda, max.lambda, fp, fn)]
fn.not.zero.tall <- data.table::melt(fn.not.zero.wide, measure=c("fp", "fn"))
ggplot()+
geom_segment(aes(
-log(min.lambda), value,
xend=-log(max.lambda), yend=value,
color=variable, linewidth=variable),
data=fn.not.zero.tall)+
geom_point(aes(
-log(min.lambda), value,
fill=variable),
color="black",
shape=21,
data=fn.not.zero.tall)+
geom_vline(aes(
xintercept=pred),
data=fn.not.zero.diffs)+
scale_size_manual(values=c(fp=2, fn=1))+
facet_grid(example ~ ., labeller=label_both)
}
Run the code above in your browser using DataLab