graph_model | R Documentation |
graph_model
provides an easy way to graph interactions in fitted
models (linear, generalized linear, hierarchical linear, or ANOVA). Selected
variables will be graphed at +/- 1 SD (if continuous) or at each level of the
factor (if categorical).
graph_model(model, ...)
## S3 method for class 'lm'
graph_model(
model,
y,
x,
lines = NULL,
split = NULL,
errorbars = c("CI", "SE", "none"),
ymin = NULL,
ymax = NULL,
labels = NULL,
bargraph = FALSE,
draw.legend = TRUE,
dodge = 0,
exp = FALSE,
...
)
## S3 method for class 'aov'
graph_model(
model,
y,
x,
lines = NULL,
split = NULL,
errorbars = c("CI", "SE", "none"),
ymin = NULL,
ymax = NULL,
labels = NULL,
bargraph = FALSE,
draw.legend = TRUE,
dodge = 0,
exp = FALSE,
...
)
## S3 method for class 'glm'
graph_model(
model,
y,
x,
lines = NULL,
split = NULL,
type = c("link", "response"),
errorbars = c("CI", "SE", "none"),
ymin = NULL,
ymax = NULL,
labels = NULL,
bargraph = FALSE,
draw.legend = TRUE,
dodge = 0,
exp = FALSE,
...
)
## S3 method for class 'lme'
graph_model(
model,
y,
x,
lines = NULL,
split = NULL,
errorbars = c("CI", "SE", "none"),
ymin = NULL,
ymax = NULL,
labels = NULL,
bargraph = FALSE,
draw.legend = TRUE,
dodge = 0,
exp = FALSE,
...
)
## S3 method for class 'merMod'
graph_model(
model,
y,
x,
lines = NULL,
split = NULL,
errorbars = c("CI", "SE", "none"),
ymin = NULL,
ymax = NULL,
labels = NULL,
bargraph = FALSE,
draw.legend = TRUE,
dodge = 0,
exp = FALSE,
...
)
model |
A fitted linear model of type 'lm', 'aov', 'glm', 'lme', or 'merMod'. |
... |
Not currently implemented; used to ensure consistency with S3 generic. |
y |
The variable to be plotted on the y-axis. This variable is required for the graph. |
x |
The variable to be plotted on the x-axis. This variable is required for the graph. |
lines |
The variable to be plotted using separate lines (optional). |
split |
The variable to be split among separate graphs (optional). |
errorbars |
A string indicating what kind of error bars to show. Acceptable values are "CI" (95% confidence intervals), "SE" (+/-1 standard error of the predicted means), or "none". |
ymin |
Number indicating the minimum value for the y-axis scale. Default NULL value will adjust position to the lowest y value. |
ymax |
Number indicating the maximum value for the y-axis scale. Default NULL value will adjust position to the highest y value. |
labels |
A named list with strings for the various plot labels: 'title' will set the graph title, 'y' sets the y-axis label, 'x' sets the x-axis label, 'lines' sets the legend label, and 'split' sets the label for the facet. If any label is not set, the names of the variables will be used. Setting a label explicitly to NA will set a label with an empty string. |
bargraph |
Logical. TRUE will draw a bar graph of the results; FALSE will draw a line graph of the results. |
draw.legend |
Logical. Whether or not to draw legend on the graph. |
dodge |
A numeric value indicating the amount each point on the graph should be shifted left or right, which can help for readability when points are close together. Default value is 0, with .1 or .2 probably sufficient in most cases. |
exp |
Logical. If TRUE, the exponential function |
type |
The type of prediction required. The default 'link' is on the
scale of the linear predictors; the alternative 'response' is on the scale
of the response variable. For more information, see
|
If there are additional covariates in the model other than what is indicated to be graphed by the function, these variables will be plotted at their respective means. In the case of a categorical covariate, the results will be averaged across all its levels.
A ggplot2 graph of the plotted variables in the model.
graph_model(lm)
: Graphing linear models.
graph_model(aov)
: Graphing ANOVA.
graph_model(glm)
: Graphing generalized linear models.
graph_model(lme)
: Graphing hierarchical linear models (nlme).
graph_model(merMod)
: Graphing hierarchical linear models (lme4).
# iris data
model <- lm(Sepal.Width ~ Sepal.Length * Species, data=iris)
graph_model(model, y=Sepal.Width, x=Sepal.Length, lines=Species)
# Orthodont data
if (require(nlme, quietly=TRUE)) {
model <- lme(distance ~ age * Sex, data=Orthodont, random=~1|Subject)
graph_model(model, y=distance, x=age, lines=Sex)
}
# Arabidopsis data
if (require(lme4, quietly=TRUE)) {
model <- lmer(total.fruits ~ nutrient * amd + rack + (1|gen), data=Arabidopsis)
graph_model(model, y=total.fruits, x=nutrient, lines=amd)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.