R/image.R
, R/image_glm.R
, R/image_loess.R
, and 4 more
persp.Rd
Draw one or more perspectives plots reflecting predictions or marginal effects from a model, or the same using a flat heatmap or “filled contour” (image
) representation. Currently methods exist for “lm”, “glm”, and “loess” models.
# S3 method for lm image(x, xvar = attributes(terms(x))[["term.labels"]][1], yvar = attributes(terms(x))[["term.labels"]][2], dx = xvar, what = c("prediction", "effect"), type = c("response", "link"), vcov = stats::vcov(x), nx = 25L, ny = nx, nz = 20, xlab = xvar, ylab = yvar, xaxs = "i", yaxs = xaxs, bty = "o", col = gray(seq(0.05, 0.95, length.out = nz), alpha = 0.75), contour = TRUE, contour.labels = NULL, contour.drawlabels = TRUE, contour.cex = 0.6, contour.col = "black", contour.lty = 1, contour.lwd = 1, ...) # S3 method for glm image(x, xvar = attributes(terms(x))[["term.labels"]][1], yvar = attributes(terms(x))[["term.labels"]][2], dx = xvar, what = c("prediction", "effect"), type = c("response", "link"), vcov = stats::vcov(x), nx = 25L, ny = nx, nz = 20, xlab = xvar, ylab = yvar, xaxs = "i", yaxs = xaxs, bty = "o", col = gray(seq(0.05, 0.95, length.out = nz), alpha = 0.75), contour = TRUE, contour.labels = NULL, contour.drawlabels = TRUE, contour.cex = 0.6, contour.col = "black", contour.lty = 1, contour.lwd = 1, ...) # S3 method for loess image(x, xvar = attributes(terms(x))[["term.labels"]][1], yvar = attributes(terms(x))[["term.labels"]][2], dx = xvar, what = c("prediction", "effect"), type = c("response", "link"), vcov = stats::vcov(x), nx = 25L, ny = nx, nz = 20, xlab = xvar, ylab = yvar, xaxs = "i", yaxs = xaxs, bty = "o", col = gray(seq(0.05, 0.95, length.out = nz), alpha = 0.75), contour = TRUE, contour.labels = NULL, contour.drawlabels = TRUE, contour.cex = 0.6, contour.col = "black", contour.lty = 1, contour.lwd = 1, ...) # S3 method for lm persp(x, xvar = attributes(terms(x))[["term.labels"]][1], yvar = attributes(terms(x))[["term.labels"]][2], dx = xvar, what = c("prediction", "effect"), type = c("response", "link"), vcov = stats::vcov(x), nx = 25L, ny = nx, theta = 45, phi = 10, shade = 0.75, xlab = xvar, ylab = yvar, zlab = if (match.arg(what) == "prediction") "Predicted value" else paste0("Marginal effect of ", dx), ticktype = c("detailed", "simple"), ...) # S3 method for glm persp(x, xvar = attributes(terms(x))[["term.labels"]][1], yvar = attributes(terms(x))[["term.labels"]][2], dx = xvar, what = c("prediction", "effect"), type = c("response", "link"), vcov = stats::vcov(x), nx = 25L, ny = nx, theta = 45, phi = 10, shade = 0.75, xlab = xvar, ylab = yvar, zlab = if (match.arg(what) == "prediction") "Predicted value" else paste0("Marginal effect of ", dx), ticktype = c("detailed", "simple"), ...) # S3 method for loess persp(x, xvar = attributes(terms(x))[["term.labels"]][1], yvar = attributes(terms(x))[["term.labels"]][2], dx = xvar, what = c("prediction", "effect"), type = c("response", "link"), vcov = stats::vcov(x), nx = 25L, ny = nx, theta = 45, phi = 10, shade = 0.75, xlab = xvar, ylab = yvar, zlab = if (match.arg(what) == "prediction") "Predicted value" else paste0("Marginal effect of ", dx), ticktype = c("detailed", "simple"), ...)
x | A model object. |
---|---|
xvar | A character string specifying the name of variable to use as the x dimension in the plot. See |
yvar | A character string specifying the name of variable to use as the y dimension in the plot. See |
dx | A character string specifying the name of the variable for which the conditional average marginal effect is desired when |
what | A character string specifying whether to draw “prediction” (fitted values from the model, calculated using |
type | A character string specifying whether to calculate predictions on the response scale (default) or link (only relevant for non-linear models). |
vcov | A matrix containing the variance-covariance matrix for estimated model coefficients, or a function to perform the estimation with |
nx | An integer specifying the number of points across |
ny | An integer specifying the number of points across |
nz | An integer specifying, for |
xlab | A character string specifying the value of |
ylab | A character string specifying the value of |
xaxs | A character string specifying the x-axis type (see |
yaxs | A character string specifying the y-axis type (see |
bty | A character string specifying the box type (see |
col | A character vector specifying colors to use when coloring the contour plot. |
contour | For |
contour.labels | For |
contour.drawlabels | For |
contour.cex | For |
contour.col | For |
contour.lty | For |
contour.lwd | For |
… | |
theta | For |
phi | For |
shade | For |
zlab | A character string specifying the value of |
ticktype | A character string specifying one of: “detailed” (the default) or “simple”. See |
# NOT RUN { require('datasets') # prediction from several angles m <- lm(mpg ~ wt*drat, data = mtcars) persp(m, theta = c(45, 135, 225, 315)) # flat/heatmap representation image(m) # marginal effect of 'drat' across drat and wt m <- lm(mpg ~ wt*drat*I(drat^2), data = mtcars) persp(m, xvar = "drat", yvar = "wt", what = "effect", nx = 10, ny = 10, ticktype = "detailed") # a non-linear model m <- glm(am ~ wt*drat, data = mtcars, family = binomial) persp(m, theta = c(30, 60)) # prediction # flat/heatmap representation image(m) # effects on linear predictor and outcome persp(m, xvar = "drat", yvar = "wt", what = "effect", type = "link") persp(m, xvar = "drat", yvar = "wt", what = "effect", type = "response") # }