Skip to content

Commit

Permalink
Version 2.4-1
Browse files Browse the repository at this point in the history
  • Loading branch information
pbreheny committed Jun 23, 2017
1 parent dcbd432 commit c9132c4
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 29 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Package: visreg
Title: Visualization of Regression Models
Version: 2.4-1
Date: 2017-06-09
Date: 2017-06-23
Author: Patrick Breheny, Woodrow Burchett
Maintainer: Patrick Breheny <[email protected]>
Imports: lattice
Suggests: rgl, MASS, survival, knitr, ggplot2
Enhances: nlme
VignetteBuilder: knitr
Description: Provides a convenient interface for constructing plots to visualize the fit of regression models arising from a wide variety of models in R ('lm', 'glm', 'coxph', 'rlm', 'gam', 'locfit', 'randomForest', etc.)
Description: Provides a convenient interface for constructing plots to visualize the fit of regression models arising from a wide variety of models in R ('lm', 'glm', 'coxph', 'rlm', 'gam', 'locfit', 'lmer', 'randomForest', etc.)
License: GPL-3
URL: http://pbreheny.github.io/visreg
12 changes: 12 additions & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
2.4-1 (2017-06-23)
* New: Can now specify reference level for contrast plots by including x
variable in 'cond' list (thank you GitHub@jealie for implementing this!)
* Changed: Default for transformed outcomes now rug=2
* Changed: Default color for persp plot
* Changed: visreg(fit) no longer plots constant objects
* Changed: Appearance of strip names for numeric 'by' variables
* Fixed: plot.visreg wasn't plotting gg objects by default
* Fixed: Bug in formula parsing w/ complicated interactions
* Fixed: Bugs in ggFactorPlot
* Fixed: print.cond warning using warning() instead of printing text

2.4-0 (2017-06-09)
* New: gg=TRUE works for regular plots, not just cross-sectional plots
* New: gg=TRUE returns a gg object, which can then be manipulated further
Expand Down
6 changes: 3 additions & 3 deletions R/plot.visreg.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plot.visreg <- function(x, overlay=FALSE, print.cond=FALSE, whitespace=0.2, partial=identical(x$meta$trans, I), band=TRUE, rug=(2*!partial),
strip.names=is.numeric(x$fit[,x$meta$by]), legend=TRUE, line.par=NULL, fill.par=NULL,
points.par=NULL, gg=FALSE, ...) {
plot.visreg <- function(x, overlay=FALSE, print.cond=FALSE, whitespace=0.2, partial=identical(x$meta$trans, I), band=TRUE,
rug=ifelse(partial, 0, 2), strip.names=is.numeric(x$fit[,x$meta$by]), legend=TRUE, line.par=NULL,
fill.par=NULL, points.par=NULL, gg=FALSE, ...) {
warn <- FALSE
if (missing(print.cond)) {
if (!("by" %in% names(x$meta)) & x$meta$hasInteraction) print.cond <- warn <- TRUE
Expand Down
28 changes: 18 additions & 10 deletions R/setupX.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
setupX <- function(fit, f, name, nn, cond, ...) {
## Set up n x p matrix for (conditional) partial residuals
x <- f[,name]
# Get the reference to plot contrasts from `cond` - if not present, fall back on using the mean (numerical) or the first factor
xref <- if (is.factor(x)) {
if (name %in% names(cond)) {
if (cond[[name]] %in% levels(x)) which(levels(x) == cond[[name]]) else xref = type.convert(cond[[name]], na.strings='')
} else {
1
}
} else {
if (name %in% names(cond)) cond[[name]] else mean(x)
}
if (is.factor(x)) {
xref <- 1
if (name %in% names(cond)) {
if (cond[[name]] %in% levels(x)) {
xref <- which(levels(x) == cond[[name]])
} else if (cond[[name]] %in% 1:length(levels(x))) {
xref <- cond[[name]]
} else {
warning(paste0("You have specified a value for ", name, " that is not one of its levels.\n Using reference level instead."))
}
}
} else {
if (name %in% names(cond)) {
xref <- cond[[name]]
} else {
xref <- mean(x)
}
}
x <- if (is.factor(x)) factor(c(xref, as.integer(x)), labels=levels(x)) else c(xref, x)
xdf <- data.frame(x)
names(xdf) <- name
Expand Down
27 changes: 20 additions & 7 deletions inst/tests/visreg-contrast.R
Original file line number Diff line number Diff line change
@@ -1,15 +1,28 @@
## Tests of contrast plots
## Real example; overparameterized model
CO2$Plant <- factor(as.character(CO2$Plant))
fit <- lm(uptake~.,CO2)
visreg(fit,"conc",type="contrast")
visreg(fit,"Plant",type="contrast")
# Tests of contrast plots

# Basic functionality
ozone <- airquality[complete.cases(airquality),]
ozone$Heat <- cut(ozone$Temp,3,labels=c("Cool","Mild","Hot"))
fit <- lm(Ozone ~ Wind*Heat,data=ozone)
visreg(fit,"Wind", type="contrast", by="Heat",layout=c(3,1))
visreg(fit,"Wind", type="contrast", cond=list(Heat="Mild"))
visreg(fit,"Wind", type="contrast", cond=list(Heat="Cool"), print.cond=FALSE)
visreg(fit,"Wind", type="contrast", cond=list(Heat="Hot"), print.cond=FALSE)
fit <- lm(Ozone ~ Wind + Heat,data=ozone)
visreg(fit, "Wind", type="contrast", cond=list(Heat="Cool"))
visreg(fit, "Wind", type="contrast", cond=list(Heat="Hot"))
visreg(fit, "Wind", type="contrast", cond=list(Wind=5))
visreg(fit, "Wind", type="contrast", cond=list(Wind=20))
visreg(fit, "Heat", type="contrast")
visreg(fit, "Heat", type="contrast", cond=list(Heat="Hot"))
visreg(fit, "Heat", type="contrast", cond=list(Heat=3))
visreg(fit, "Heat", type="contrast", cond=list(Heat=10))

# Real example; overparameterized model
CO2$Plant <- factor(as.character(CO2$Plant))
fit <- lm(uptake~.,CO2)
visreg(fit,"conc",type="contrast")
visreg(fit,"Plant",type="contrast")


## Toy example
x1 <- rep(1:10,2)
Expand Down
7 changes: 4 additions & 3 deletions man/plot.visreg.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ accepts a \code{visreg} or \code{visregList} object as calculated by
\usage{
\method{plot}{visreg}(x, overlay=FALSE, print.cond=FALSE,
whitespace=0.2, partial=identical(x$meta$trans, I), band=TRUE,
rug=!partial, strip.names=is.numeric(x$fit[,x$meta$by]), legend=TRUE,
line.par=NULL, fill.par=NULL, points.par=NULL, gg=FALSE, ...)
rug=ifelse(partial, 0, 2), strip.names=is.numeric(x$fit[,x$meta$by]),
legend=TRUE, line.par=NULL, fill.par=NULL, points.par=NULL, gg=FALSE,
...)
}
\arguments{

Expand Down Expand Up @@ -121,7 +122,7 @@ line.par=NULL, fill.par=NULL, points.par=NULL, gg=FALSE, ...)
Patrick Breheny and Woodrow Burchett
}
\seealso{
\code{\url{http://pbreheny.github.io/visreg/options.html}}
\url{http://pbreheny.github.io/visreg/options.html}
\code{\link{visreg}}
\code{\link{visreg2d}}
\code{\link{visreg-faq}}
Expand Down
2 changes: 1 addition & 1 deletion man/visreg.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ cond=list(), jitter=FALSE, collapse=FALSE, plot=TRUE, ...)
Patrick Breheny and Woodrow Burchett
}
\seealso{
\code{\url{http://pbreheny.github.io/visreg}}
\url{http://pbreheny.github.io/visreg}
\code{\link{plot.visreg}}
\code{\link{visreg2d}}
\code{\link{visreg-faq}}
Expand Down
7 changes: 4 additions & 3 deletions man/visreg2d.Rd
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ response in regression models.
}
\usage{
visreg2d(fit, xvar, yvar, type=c("conditional", "contrast", "effect"),
trans=I, scale=c("linear","response"),
plot.type=c("image","persp","rgl"), nn=ifelse(plot.type=="persp",49,99),
trans=I, scale=c("linear", "response"),
plot.type=c("image", "persp", "rgl"), nn=ifelse(plot.type=="persp", 49,
99),
cond=list(), print.cond=FALSE, whitespace=0.2, ...)
}
\arguments{
Expand Down Expand Up @@ -106,7 +107,7 @@ cond=list(), print.cond=FALSE, whitespace=0.2, ...)
Patrick Breheny and Woodrow Burchett
}
\seealso{
\code{\url{http://pbreheny.github.io/visreg/surface.html}}
\url{http://pbreheny.github.io/visreg/surface.html}
\code{\link{visreg}}
}
\examples{
Expand Down

0 comments on commit c9132c4

Please sign in to comment.