Skip to content

Commit

Permalink
finalize update for dropping always included variables issue #23
Browse files Browse the repository at this point in the history
  • Loading branch information
merliseclyde committed Jul 13, 2018
1 parent e3f9cdb commit 3892c2d
Show file tree
Hide file tree
Showing 40 changed files with 242 additions and 128 deletions.
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@

* Added option to force lower order terms to be included if higher order terms are present (hierarchical constraint). Currently only supported with `method='MCMC'` and `method='BAS'` with `bas.lm` and `bas.glm`. Updated Vignette to illustrate. [enhancement #19](https://github.com/merliseclyde/BAS/issues/19)

* Added option `drop.always.included` to `image.bas` so that variables that are always included are not shown. The intercept is no longer shown as well. [enhancement #23](https://github.com/merliseclyde/BAS/issues/23)
* Added option `drop.always.included` to `image.bas` so that variables that are always included may be excluded from the image. By default all are shown [enhancement #23](https://github.com/merliseclyde/BAS/issues/23)

* Added option `drop.always.included` and `subset` to `plot.bas` so that variables that are always included may be excluded from the plot showing the marginal posterior inclusion probabilities (`which=4`). By default all are shown [enhancement #23](https://github.com/merliseclyde/BAS/issues/23)

## Bugs

Expand Down
23 changes: 14 additions & 9 deletions R/image.bas.R
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@
#' @param color The color scheme for image intensities. The value "rainbow"
#' uses the rainbow palette. The value "blackandwhite" produces a black and
#' white image (greyscale image)
#' @param subset indices of variables to include in plot; (excludes the intercept)
#' @param subset indices of variables to include/exclude in plot
#' @param drop.always.included logical variable to drop variables that are
#' always in the model. TRUE by default.
#' always forced into the model. FALSE by default.
#' @param offset numeric value to add to intensity
#' @param digits number of digits in posterior probabilities to keep
#' @param vlas las parameter for placing variable names; see par
Expand All @@ -49,14 +49,14 @@
#' require(graphics)
#' data("Hald")
#' hald.ZSprior = bas.lm(Y~ ., data=Hald, prior="ZS-null")
#' image(hald.ZSprior, subset=-1)
#' image(hald.ZSprior, drop.always.included=TRUE) #drop the intercept
#'
#' @rdname image.bas
#' @family bas methods
#' @family bas plots
#' @method image bas
#' @export
image.bas <- function (x, top.models=20, intensity=TRUE, prob=TRUE, log=TRUE, rotate=TRUE, color="rainbow", subset=NULL, drop.always.included = TRUE,
image.bas <- function (x, top.models=20, intensity=TRUE, prob=TRUE, log=TRUE, rotate=TRUE, color="rainbow", subset=NULL, drop.always.included = FALSE,
offset=.75, digits=3, vlas=2,plas=0,rlas=0, ...)
{
postprob = x$postprobs
Expand All @@ -67,10 +67,14 @@ image.bas <- function (x, top.models=20, intensity=TRUE, prob=TRUE, log=TRUE, ro
nvar <- ncol(which.mat)


if (is.null(subset)) subset=2:nvar
keep = x$include.always
subset = subset[!subset %in% keep]
if (length(subset) == 0) stop("no models in subset to show; modify subset or drop.always.included")
if (is.null(subset)) subset=1:nvar
if (drop.always.included) {
keep = x$include.always
if (is.null(keep)) keep = 1
subset = subset[!subset %in% keep]
if (length(subset) == 0) stop("no models in subset to show; modify subset or drop.always.included")
}

which.mat = which.mat[,subset, drop=FALSE]
nvar = ncol(which.mat)
namesx = x$namesx[subset]
Expand All @@ -84,8 +88,9 @@ image.bas <- function (x, top.models=20, intensity=TRUE, prob=TRUE, log=TRUE, ro
# fix problem when scale has duplicate zeros
zeros = which(scale == 0.0)
nzeros = length(zeros)

if (nzeros > 1) {
scale[zeros] = seq(scale[zeros[1]-1],0,length=nzeros)/1000
scale[zeros] = seq(scale[zeros[1]-1],0.0,length=nzeros)/1000
}
}

Expand Down
23 changes: 18 additions & 5 deletions R/plot.bas.R
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#' plots; see also 'panel' above
#' @param label.pos positioning of labels, for the left half and right half of
#' the graph respectively, for plots 1-4
#' @param subset indices of variables to include/exclude in plot of marginal posterior
#' inclusion probabilities (NULL).
#' @param drop.always.included logical variable to drop marginal posterior inclusiond probabilities
#' for variables that are always forced into the model. FALSE by default.
#' @author Merlise Clyde, based on plot.lm by John Maindonald and Martin
#' Maechler
#' @seealso \code{\link{plot.coef.bas}} and \code{\link{image.bas}}.
Expand Down Expand Up @@ -65,7 +69,7 @@ plot.bas = function (x, which = c(1:4),
id.n = 3,
labels.id = NULL,
cex.id = 0.75, add.smooth = getOption("add.smooth"),
label.pos = c(4, 2))
label.pos = c(4, 2), subset=NULL, drop.always.included=FALSE)
{
if (!inherits(x, "bas"))
stop("use only with \"bas\" objects")
Expand Down Expand Up @@ -168,10 +172,19 @@ plot.bas = function (x, which = c(1:4),
text.id(dim[show.m], logmarg[show.m], show.m)
}
if (show[4]) {
probne0 = x$probne0
variables = 1:x$n.vars

if (is.null(subset)) subset=1:x$n.vars
if (drop.always.included) {
keep = x$include.always
if (is.null(keep)) keep = 1
subset = subset[!subset %in% keep]
if (length(subset) == 0) stop("no models in subset to show; modify subset or drop.always.included")
}
probne0 = x$probne0[subset]
nvars = length(subset)
variables = 1:nvars
ylim <- c(0,1)
colors=rep(0, x$n.vars)
colors=rep(0, nvars)
colors[probne0 > .5] = col.in
colors[probne0 <= .5] = col.ex

Expand All @@ -182,7 +195,7 @@ plot.bas = function (x, which = c(1:4),
ylim = ylim, ...)
if (one.fig)
title(sub = sub.caption, ...)
mtext(x$namesx, side=1, line=0.25, at=variables, las=2, cex=cex.lab, ...)
mtext(x$namesx[subset], side=1, line=0.25, at=variables, las=2, cex=cex.lab, ...)
mtext(caption[4], 3, 0.25)
#if (id.n > 0)
# text.id(dim[show.m], logmarg[show.m], show.m)
Expand Down
61 changes: 38 additions & 23 deletions docs/news/index.html

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

Binary file modified docs/reference/BAS-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/BAS-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/reference/BAS-6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 14 additions & 14 deletions docs/reference/BAS.html

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

Binary file modified docs/reference/bas.glm-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 3892c2d

Please sign in to comment.