Description Usage Arguments See Also Examples
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.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | ## S3 method for class '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 class '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 class '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 class '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 class '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 class '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 |
... |
Additional arguments passed to |
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 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 | ## 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")
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.