pplot: Plot Regression Terms using ggplot2

pplotR Documentation

Plot Regression Terms using ggplot2

Description

Plots regression terms against their predictors. Generates ggplots based on library visreg

Usage

pplot=function (model, xvar, by = NULL, breaks = NULL, partial = FALSE,
          type = c("conditional", "contrast"), scale = c("linear",
        "response"), leg.name = NULL, leg.labs = NULL, cols = c("red",
        "blue", "green", "purple"), linesize = 1.5, transp = 0.5,
          rsize = 2, rcolor = "red", rshade = FALSE, rshapes = TRUE)

Arguments

model

A fitted model.

xvar

Against which predictor to plot.

by

Used for interactions. Plot are shown for levels of by. Continuous variables are changed to factors

breaks

If a single number, number of levels. If 2 or more numbers, discrete values/levels of by.

partial

Logical. Should residuals been shown?

type

Use 'contrast' for models with random factors

scale

Linear or response. If scale='response' for a glm, the inverse link function will be applied so that the model is plotted on the scale of the original response.

leg.name

Optional. Name of legend.

leg.labs

Optional. Legend labels.

cols

Colors of confidence bands.

linesize

Number. Set thickness of regression line?

transp

Transparency of cols (0-1).

rsize

Size of symbols for residuals.

rcolor

Color of residuals.

rshade

Logical. Should residuals been shown in different shades of gray per level of by?

rshapes

Logical. Should residuals been shown in different shapeas per level of by?

Details

Wrapper for essentials of visreg. See ?visreg for more.

Author(s)

T. Ruf

References

Breheny P and Burchett W (2017). Visualization of Regression Models Using visreg. The R Journal, 9: 56-71.

Examples


require(visreg)
require(ggplot2)
devAskNewPage(ask =TRUE)

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

theme_set(theme_rufus(base_size=20))

pplot(fit,xvar="Wind",by="Temp", breaks=c(60,90),partial=TRUE,
      leg.name="Temperature",leg.labs=c("cool","warm"))

pplot(fit,xvar="Wind",by="Temp", breaks=c(3),partial=TRUE,
      leg.name="Temperature",leg.labs=c("cool","average","warm"),
      cols=c("yellow","orange","red"),rsize=3,rshapes=TRUE)

pplot(fit,xvar="Wind",by="Temp", breaks=c(3),partial=FALSE,
      leg.name="Temperature",leg.labs=c("cool","average","warm"),
      cols=c("yellow","orange","red"),rsize=3)+
      theme(legend.position = c(0.8, 0.8))

require(mgcv)
require (nlme)

mod.lme=lme(distance~age*Sex, random=~1|Subject, data=Orthodont)
pplot(mod.lme,xvar="age",by="Sex",partial=TRUE,leg.name="Gender",type='contrast')


mod.bam=bam(distance~age*Sex+s(Subject, bs = 're'), data=Orthodont)
pplot(mod.bam,xvar="age",by="Sex",type='contrast')
pplot(mod.bam,xvar="age",by="Sex",partial=TRUE,leg.name="Gender",type='contrast')
# bam can be used to compute LINEAR mixed effects and generates confidence intervals.
# Coefficients, t and p-values are virtually identical to lme and lmer.

# pplot handles simple gams too.
fit <- gam(Ozone ~ s(Solar.R) + s(Wind) + s(Temp), data=airquality)
pplot(fit,xvar="Wind",partial=TRUE)


thomaspruf/fiwidat documentation built on Aug. 28, 2023, 11:12 p.m.