graph_model_q.glm
provides an easy way to graph interactions in
general linear models. Selected variables will be graphed at +/- 1 SD (if
continuous) or at each level of the factor (if categorical).
# S3 method for glm
graph_model_q(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, ...)
A fitted linear model of type 'glm'.
The variable to be plotted on the y-axis. This variable is required for the graph.
The variable to be plotted on the x-axis. This variable is required for the graph.
The variable to be plotted using separate lines (optional).
The variable to be split among separate graphs (optional).
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
predict.glm
.
A string indicating what kind of error bars to show. Acceptable values are "CI" (95 error of the predicted means), or "none".
Number indicating the minimum value for the y-axis scale. Default NULL value will adjust position to the lowest y value.
Number indicating the maximum value for the y-axis scale. Default NULL value will adjust position to the highest y value.
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 an empty label.
Logical. TRUE will draw a bar graph of the results; FALSE will draw a line graph of the results.
Logical. Whether or not to draw legend on the graph.
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.
Logical. If TRUE, the exponential function exp()
will be
used to transform the y-axis (i.e., e to the power of y). Useful for
logistic regressions or for converting log-transformed y-values to their
original units.
Not currently implemented; used to ensure consistency with S3 generic.
A ggplot object of the plotted variables in the model.
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.
Note that in most cases it is easier to use graph_model.glm
and
pass variable names in directly instead of strings of variable names.
graph_model_q.glm
uses standard evaluation in cases where such
evaluation is easier.
# NOT RUN {
# iris data
model <- lm(Sepal.Width ~ Sepal.Length * Species, data=iris)
graph_model_q(model, y='Sepal.Width', x='Sepal.Length', lines='Species')
# }
Run the code above in your browser using DataLab