Learn R Programming

reghelper (version 0.3.3)

graph_model.lm: Graph linear interactions.

Description

graph_model.lm provides an easy way to graph interactions in linear models. Selected variables will be graphed at +/- 1 SD (if continuous) or at each level of the factor (if categorical).

Usage

# S3 method for 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 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, ...)

Arguments

model

A fitted linear model of type 'lm'.

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 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 an empty label.

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 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.

Value

A ggplot2 graph of the plotted variables in the model.

Details

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.

Examples

Run this code
# NOT RUN {
# iris data
model <- lm(Sepal.Width ~ Sepal.Length * Species, data=iris)
graph_model(model, y=Sepal.Width, x=Sepal.Length, lines=Species)
# }

Run the code above in your browser using DataLab