From bcf4c2b156afac33d372fc38abc64f28c458c4a4 Mon Sep 17 00:00:00 2001 From: Syksy Date: Mon, 26 Apr 2021 09:32:01 +0300 Subject: [PATCH] Preliminary binplot --- .gitignore | 2 +- DESCRIPTION | 6 +++--- NAMESPACE | 2 ++ R/visu.R | 52 ++++++++++++++++++++++++++++++++++++++++++++++- man/binplot.Rd | 20 ++++++++++++++++++ man/bs.boxplot.Rd | 11 ++++++++++ 6 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 man/binplot.Rd create mode 100644 man/bs.boxplot.Rd diff --git a/.gitignore b/.gitignore index baf1099..82bbe7f 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,4 @@ src/*.mod *.tws src-i386/* src-x64/* - +fort.* diff --git a/DESCRIPTION b/DESCRIPTION index 5b46f6c..f19d3df 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,7 +1,7 @@ Package: oscar Type: Package Title: Optimal Subset CArdinality Regression (OSCAR) models using the L0-pseudonorm -Version: 0.6.3 +Version: 0.6.4 Date: 2021-04-26 Authors@R: c( person(given="Teemu Daniel", family="Laajala", role=c("aut", "cre"), email="teelaa@utu.fi", comment = c(ORCID = "0000-0002-7016-7354")), @@ -16,8 +16,8 @@ License: GPL-3 LazyData: true NeedsCompilation: yes Depends: R (>= 3.6.0) -Imports: survival, knitr -Suggests: glmnet, hamlet, ePCR, rmarkdown, pROC +Imports: survival, knitr, hamlet +Suggests: glmnet, ePCR, rmarkdown, pROC Encoding: UTF-8 VignetteBuilder: knitr RoxygenNote: 7.1.1 diff --git a/NAMESPACE b/NAMESPACE index 41023fb..d3fefe8 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,8 @@ # Generated by roxygen2: do not edit by hand export(binarize) +export(binplot) +export(bs.boxplot) export(bs.k) export(bs.oscar) export(bs.visu) diff --git a/R/visu.R b/R/visu.R index 470055a..09faff6 100644 --- a/R/visu.R +++ b/R/visu.R @@ -210,7 +210,9 @@ cv.visu <- function( arrows(x0=x, y0=means-sds, x1=x, y1=means+sds, code=3, angle=90, length=0.1) } -## Bootstrap visualization with boxplot, percentage of new additions +#' @title Bootstrap visualization with boxplot, percentage of new additions +#' +#' @export bs.boxplot <- function( bs, # Bootstrap array as produced by bs.oscar ... @@ -241,3 +243,51 @@ bs.boxplot <- function( barplot(t(howoften.new)[,nkits:1,drop=FALSE],horiz=TRUE,col=rainbow(38)) } + +#' @title Visualize binary indicator matrix optionally coupled with cross-validation performance +#' +#' @export +binplot <- function( + fit, # Model fit object + cv, # Cross-validation performance if calculated + kmax, # Maximum k to draw to; if missing, using kmax from fit@kmax + collines = TRUE, # Draw vertical lines to bottom part + rowlines = TRUE, # Draw horizontal lines to highlight variables + cex.axis = 0.6, + heights=c(0.2, 0.8), + ... # Additional parameters passed on to hamlet::hmap +){ + if(!class(fit) %in% c("oscar")){ + stop("'fit' should be a fit oscar object") + } + if(missing(kmax)){ + kmax <- fit@kmax + } + + if(!missing(cv)){ + # Extra CV annotation on top + par(mar=c(0,4,1,1), las=1) + # Set up paneling + layout(matrix(c(1,2), nrow=2), heights=heights) + oscar::cv.visu(cv[,1:kmax]) + axis(1, at=1:kmax) + } + + # Bottom binarized indicator panel + par(mar=c(4,4,1,1)) + bfit <- binarize(fit)[,1:kmax] + plot.new() + plot.window(xlim=c(0.2,0.8), ylim=c(0.2,0.8)) + + h <- hamlet::hmap(oscar::binarize(fit), Colv=NA, Rowv=NA, toplim=0.8, bottomlim=0.2, col=c("lightgrey", "darkgrey"), nbins=2, namerows=FALSE, namecols=FALSE, add=TRUE) + #title(ylab="Non-zero coefficients", xlab="Cardinality 'k'") + title(xlab="Cardinality 'k'") + axis(1, at=h$coltext$xseq[1:kmax], labels=1:kmax) + axis(2, at=h$rowtext$yseq, labels=h$rowtext$rownam, cex.axis=cex.axis, las=1) + # Line annotations + if(collines) abline(v=h$coltext$xseq[1:kmax], col="grey") + if(rowlines) abline(h=h$rowtext$yseq, col="grey") + # Legend + legend("topright", col=c("lightgrey", "darkgrey"), pch=15, legend=c("Excluded", "Included"), bg="white") + box() +} diff --git a/man/binplot.Rd b/man/binplot.Rd new file mode 100644 index 0000000..0575ce3 --- /dev/null +++ b/man/binplot.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/visu.R +\name{binplot} +\alias{binplot} +\title{Visualize binary indicator matrix optionally coupled with cross-validation performance} +\usage{ +binplot( + fit, + cv, + kmax, + collines = TRUE, + rowlines = TRUE, + cex.axis = 0.6, + heights = c(0.2, 0.8), + ... +) +} +\description{ +Visualize binary indicator matrix optionally coupled with cross-validation performance +} diff --git a/man/bs.boxplot.Rd b/man/bs.boxplot.Rd new file mode 100644 index 0000000..8d3a3bd --- /dev/null +++ b/man/bs.boxplot.Rd @@ -0,0 +1,11 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/visu.R +\name{bs.boxplot} +\alias{bs.boxplot} +\title{Bootstrap visualization with boxplot, percentage of new additions} +\usage{ +bs.boxplot(bs, ...) +} +\description{ +Bootstrap visualization with boxplot, percentage of new additions +}