plotmod {stdmod} | R Documentation |
Moderation Effect Plot
Description
Plot the moderation effect in a regression model
Usage
plotmod(
output,
x,
w,
x_label,
w_label,
y_label,
title,
digits = 3,
x_from_mean_in_sd = 1,
w_from_mean_in_sd = 1,
w_method = c("sd", "percentile"),
w_percentiles = c(0.16, 0.84),
x_method = c("sd", "percentile"),
x_percentiles = c(0.16, 0.84),
w_sd_to_percentiles = NA,
x_sd_to_percentiles = NA,
w_values = NULL,
note_standardized = TRUE,
no_title = FALSE,
line_width = 1,
point_size = 5,
graph_type = c("default", "tumble")
)
Arguments
output |
The output
of |
x |
The name of the focal variable (x-axis) in 'output“. It can be the name of the variable, with or without quotes. Currently only numeric variables are supported. |
w |
The name of the moderator in |
x_label |
The label for the X-axis. Default is the value of |
w_label |
The label for the legend for the lines.
Default is the value of |
y_label |
The label for the Y-axis. Default is the name of the response variable in the model. |
title |
The title of the graph. If not supplied, it will be
generated from the variable
names or labels (in |
digits |
Number of decimal places to print. Default is 3. |
x_from_mean_in_sd |
How many SD from mean is used to define "low" and "high" for the focal variable. Default is 1. |
w_from_mean_in_sd |
How many SD from mean is used to define
"low" and
"high" for the moderator. Default is 1.
Ignored if |
w_method |
How to define "high" and "low" for the moderator levels.
Default is in terms of the
standard deviation of the moderator, |
w_percentiles |
If |
x_method |
How to define "high" and "low" for the focal
variable levels.
Default is in terms of the
standard deviation of the focal variable, |
x_percentiles |
If |
w_sd_to_percentiles |
If |
x_sd_to_percentiles |
If |
w_values |
The values of |
note_standardized |
If |
no_title |
If |
line_width |
The width of the lines as used in
|
point_size |
The size of the points as used in |
graph_type |
If |
Details
This function generate a basic ggplot2 graph typically found in psychology manuscripts. It tries to check whether one or more variables are standardized, and report this in the plot if required.
This function only has features for typical plots of moderation effects. It is not intended to be a flexible tool for a fine control on the plots.
Value
A ggplot2 graph. Plotted if not assigned to a name. It can be further modified like a usual ggplot2 graph.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
References
Bodner, T. E. (2016). Tumble graphs: Avoiding misleading end point extrapolation when graphing interactions from a moderated multiple regression analysis. Journal of Educational and Behavioral Statistics, 41(6), 593-604. doi:10.3102/1076998616657080
Examples
# Do a moderated regression by lm
lm_out <- lm(sleep_duration ~ age + gender + emotional_stability*conscientiousness, sleep_emo_con)
plotmod(lm_out,
x = emotional_stability,
w = conscientiousness,
x_label = "Emotional Stability",
w_label = "Conscientiousness",
y_label = "Sleep Duration")
# Standardize all variables except for categorical variables
# Alternative: use to_standardize as a shortcut
# lm_std <- std_selected(lm_out,
# to_standardize = ~ .)
lm_std <- std_selected(lm_out,
to_scale = ~ .,
to_center = ~ .)
plotmod(lm_std,
x = emotional_stability,
w = conscientiousness,
x_label = "Emotional Stability",
w_label = "Conscientiousness",
y_label = "Sleep Duration")
# Tumble Graph
plotmod(lm_std,
x = emotional_stability,
w = conscientiousness,
x_label = "Emotional Stability",
w_label = "Conscientiousness",
y_label = "Sleep Duration",
graph_type = "tumble")