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.)

`visreg`

provides a number of plotting functions for visualizing fitted regression models: regression functions, confidence bands, partial residuals, interactions, and more. `visreg`

is compatible with virtually all formula-based models in R that provide a `predict`

method: `lm`

, `glm`

, `gam`

, `rlm`

, `nlme`

, `lmer`

, `coxph`

, `svm`

, `randomForest`

and many more.

The basic usage is that you fit a model, for example:

`fit <- lm(Ozone ~ Solar.R + Wind + Temp, data=airquality)`

and then you pass it to `visreg`

:

`visreg(fit, "Wind")`

A more complex example, using the `mgcv`

package:

`airquality$Heat <- cut(airquality$Temp, 3, labels=c("Cool", "Mild", "Hot"))fit <- gam(Ozone ~ s(Wind, by=Heat, sp=0.1), data=airquality)visreg(fit, "Wind", "Heat", gg=TRUE, ylab="Ozone")`

For details on `visreg`

syntax and how to use it, see:

- The online documentation at http://pbreheny.github.io/visreg contains many examples of visreg plots and the code to create them.
- Breheny P and Burchett W. (2013). Visualizing regression models using visreg.

The website focuses more on syntax, options, and user interface, while the paper goes into more depth regarding the statistical details.

If you have a question or feature request, please submit an issue.

To install:

- the latest released version:
`install.packages("visreg")`

- the latest version (requires
`devtools`

):`install_github("pbreheny/visreg")`

2.4-1 (2017-06-23)

- New: Can now specify reference level for contrast plots by including x variable in 'cond' list (thank you [email protected] 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
- Fixed: bug in coxph models with type='contrast'

2.3-0 (2016-07-30)

- New: Added support for multi-response models such multinom, with accompanying visregList() function and collapse option for further control/options
- New: Added option to use ggplot2 instead of lattice to produce multi-panel plots
- New: Support for glmmADMB models.
- Documentation: Added quick-start vignette
- Fixed: Bug in which user options were not being passed to axis() when the horizontal axis was a factor
- Fixed: Bug in rounding for legend in overlay plots with numeric by variable
- Changed: Partial residuals are now on top of lines so that they cannot be hidden by them
- Internal: Reorganized and greatly expanded suite of tests
- Fixed: Now handles mlm objects with no y names
- Fixed: Now handles gamm4 models
- Fixed: Some issues with svm models (package: e1071)

2.2-2 (2016-02-06)

- Fixed: bug involving an incompatibility between formulas with a . and formulas with an s() in them (2.2-1 extended visreg to formulas with a ., but this broke compatibility with formulas with s() and similar terms)

2.2-1 (2016-01-05)

- New: Improved support for packages that do not provide a residuals() generic
- Changed: Deviance residuals now used for 'coxph' (survival) models instead of martingale residuals
- Internal: Changes to NAMESPACE for compatibility with development versions of R
- Fixed: Now compatible with 'quantreg' and 'betareg' packages

2.2-0 (2015-04-22)

- New: Added support for random forests from the 'randomForest' package
- New: Added support for models from the 'rms' package

2.1-1 (2015-02-25)

- New: plot.visreg can now return trellis objects so that you can arrange multiple trellis plots to your liking.
- Fixed: Contrast plots now work for lme4 models
- Fixed: Survival examples no longer depend on splines

2.1-0 (2014-11-27)

- New: visreg now returns simple, structured objects that a user can modify and inspect prior to plotting
- Internal: Major overhaul to visreg's internal structure
- Internal: visreg() now separated from plot.visreg()
- Fixed: Improved formula parsing so that it now works properly for te() and ti() models (mgcv), pspline models (survival), more complex formulas from lme4, and more (thank you to Andrew Vitale for giving me a good, complex model formula to test against)
- Fixed: strip.names now works for factors and shingles for both overlay and lattice plots (thank you to Dan Silver for pointing this out).

2.0-6 (2015-08-26)

- Changed: Rugs are now plotted by default instead of partial residuals when a transformation has been applied
- Fixed: Issue with S4 models not being compatible with as.formula(); visreg now refrains from calling as.formula (thank you to Nick Livingston for bringing this issue to my attention)

2.0-5 (2014-05-30)

- Fixed: Bug arising when passing plot options such as 'xlim' when used in conjunction with lme4 models; thank you to Vincent Maire for pointing this bug out

2.0-4 (2013-10-29)

- New: Added compatibility with models from the 'lme4' package; tThank you to Jack Hogg for pointing out this incompatibility (same limitations regarding error bands as 'lme' models)

2.0-3 (2013-09-27)

- New: Added compatibility with 'lme' models; conditional models still cannot include error bands due to lack of this feature in predict.lme, but the package will produce reasonable plots of means and partial residuals (Thank you to Jason Rohr for pointing out this incompatibility and the bugs below)
- New: Pption to manually relabel panel strips
- Fixed: Bug in passing 'scales' to latticePlot
- Fixed: Bug when trying to panel by every unique value of 'by' variable

2.0-2 (2013-08-28)

- New: Compatible with output from the 'survey' package; thank you to Marco Pomati for pointing this incompatibility out
- Internal: Fixed calling of generics to be compatible with changes in R version 3.1
- Fixed: Bug for mlm models in which users received an incorrect warning about residuals
- Fixed: Improved generalizability of fillFrame with factors; was incompatible with some instances of predict()

2.0-1 (2013-08-10)

- Fixed: Bug for spline models of variables with '.' in their names
- Fixed: Bug for survival models in which the Surv object is created outside the call to visreg
- Fixed: Levels of a factor no longer dropped from the model; thank you to Johannes Kutsam for pointing this out
- Fixed: Scoping issue resolved -- can now call visreg, visreg2d from a function without fit or data present in the global environment; thank you to Johannes Kutsam for pointing this out

2.0-0 (2013-05-23)

- New: Added 'overlay' option
- New: Extrapolation now allowed
- New: print.cond option, with warning when user tries to plot a main effect in the presence of interactions
- New: 'rug' option
- New: 'band' option to suppress confidence bands
- New: 'ask' option to turn off prompting when starting a new page of plots
- Changed: Changed how 'breaks' are handled for continuous 'by' variables, both in setup and appearance, with option to directly specify where breaks should occur
- Fixed: Bug for models which were called with 'subset' option
- Fixed: Minor bug in passing lattice options
- Internal: Substantial internal refactoring to separate calculations / model manipulations from plotting
- Internal: Expanded suite of tests

1.2-1 (2013-02-21)

- Fixed: Bug in calculation of confidence bands for quasilikelihood models; thank you to Ariel Muldoon for pointing this out
- Fixed: Side-effect which caused trellis settings to be changed when visreg changed them internally

1.2-0 (2013-01-20)

- New: Support for models from the 'gam' package
- New: Improved support for 'coxph' models from 'survival' package
- Fixed: Bug in 'removeFormulaFormatting' to allow further compatibility for splines with use of 'cond'
- Fixed: Bug in use of ns/bs with type='effect'

1.1-1 (2012-11-14)

- Fixed: Bug in 'removeFormulaFormatting'; now compatible with ns() and bs() from the 'splines' package

1.1-0 (2012-09-28)

- New: Finer control of plots with line.par, fill.par, points.par
- New: Support for multiple response (class 'mlm') models
- Fixed: Bug in 'ask' behavior when multiple plots created
- Fixed: Bug with formatting names for locfit objects
- Fixed: Bug with visregFactorPanel when partial=FALSE
- Changed: Default for ylabels now las=1 (always horizontal); thank you to Doug Bates for this advice

1.0-0 (2012-05-31)

- New: Now on CRAN!
- New: Improved support for contrast plots:
- Extensive revision to implementation
- 'x' can now be categorical
- interactions/conditioning allowed

- New: Improved support for visreg2d
- Interface/options consistent with visreg
- Internal refactoring to share code between visreg and visreg2d
- Works now with glm/rlm/gam/etc.

- New: Option to display panel strip names T/F
- New: Improved support for gam/locfit models
- Changed: Default (contrast/conditional) for coxph models and
- Changed: Default 'ylim' now depends on 'partial' argument
- Changed: Added some padding to xlim/ylim for lattice plots
- Changed: Default for 'ylab': Delta added for effect plot
- Deprecated: 'fill' option; always median fill from now on
- Fixed: Bug in 'ask' behavior when multple plots created
- Fixed: Bug in coxph contrast plots
- Fixed: Patched 'get_all_vars' bug when variables are in environment rather than data frame

0.4-0 (2012-02-18)

- Internal: New 'setupCond' function to handle setting up of cond when 'by' variables are present
- Internal: New functions 'visregPlot' and 'visregLatticePlot' to separate work done by the two types of plots ('by' present or absent)
- Internal: New function getXY for shared code
- Changed: Handling of whitespace when 'x' is a factor
- Changed: Default for 'ylab' changed to always be name of response variable; virtually impossible in the presense of transformations, link functions, etc., to automatically choose an appropriate name
- Fixed: Plotting options now pass to lattice correctly
- Fixed: ylim for lattice plots
- Fixed: xtrans for lattice
- Changed: Manner in which cross-sections are taken when 'by' is numeric; number of observations in each cross-section is now more even

0.3-0 (2011-12-03)

- New: Added 'jitter' option
- New: Improved handling of trellis parameters
- Internal: Reorganized frame construction again, using 'get_all_vars'; now works with missing data and various other strange situations where f(x) is in the model but x isn't

0.2-0 (2011-08-23)

- New: Added 'by' argument to support interactions
- New: visreg() now returns 'x' and 'y' invisibly
- New: Added 'scale' option for GLMs
- Internal: Reorganized frame construction, using 'extract.frame'
- Changed: Default behavior of CI widths to make compatible with coxph models
- Changed: Resolved type/type2 conflict in visreg2d with 'plot.type' option
- Documentation: Added documentation

0.1-0 (2011-07-22)

- New: Added glm suport
- New: Added factor support in 1d version
- New: Added "terms" option for 2d plots
- New: Added 'cond' option for setting specific predictor variables
- New: 'partial' and 'xtrans' options
- Changed: The most common instance of each factor is now chosen by default if the model includes factors
- Fixed: Bug for transformations for 2d plots
- Fixed: Bug that occurs when model is fit without supplying a data frame (i.e., when all variables are in the global environment)
- Fixed: Bug that occurs when a variable is class 'logical'

0.0-3 (2011-07-02)

- New: 'trans' option for transforming response variable
- Intenal: Changed internal data frame evaluation, allowing the ability to lookup variables in the original data frame when constructing derived variables

0.0-2 (2011-06-24)

- New: fill='median' option

0.0-1 (2011-06-09)

- New: 'type' option to visreg, allowing both conditional and contrast plots
- New: fill='zero' option
- Changed: Default y label in visreg

0.0-0 (2011-05-12)

- New: Package infrastructure established
- New: visreg.R, visreg2d.R: Polynomial terms handled correctly