View source: R/plot_interaction.R
plot_jn | R Documentation |
This function plots the simple slopes of an interaction effect across different values of a moderator variable using the Johnson-Neyman technique. It identifies regions where the effect of the predictor on the outcome is statistically significant.
plot_jn(
x,
z,
y,
xz = NULL,
model,
min_z = -3,
max_z = 3,
sig.level = 0.05,
alpha = 0.2,
detail = 1000,
sd.line = 2,
...
)
x |
The name of the predictor variable (as a character string). |
z |
The name of the moderator variable (as a character string). |
y |
The name of the outcome variable (as a character string). |
xz |
The name of the interaction term. If not specified, it will be created using |
model |
A fitted model object of class |
min_z |
The minimum value of the moderator variable |
max_z |
The maximum value of the moderator variable |
sig.level |
The significance level for the confidence intervals (default is 0.05). |
alpha |
alpha setting used in 'ggplot' (i.e., the opposite of opacity) |
detail |
The number of generated data points to use for the plot (default is 1000). You can increase this value for smoother plots. |
sd.line |
A thick black line showing |
... |
Additional arguments (currently not used). |
The function calculates the simple slopes of the predictor variable x
on the outcome variable y
at different levels of the moderator variable z
. It uses the Johnson-Neyman technique to identify the regions of z
where the effect of x
on y
is statistically significant.
It extracts the necessary coefficients and variance-covariance information from the fitted model object. The function then computes the critical t-value and solves the quadratic equation derived from the t-statistic equation to find the Johnson-Neyman points.
The plot displays:
The estimated simple slopes across the range of z
.
Confidence intervals around the slopes.
Regions where the effect is significant (shaded areas).
Vertical dashed lines indicating the Johnson-Neyman points.
Text annotations providing the exact values of the Johnson-Neyman points.
A ggplot
object showing the interaction plot with regions of significance.
## Not run:
library(modsem)
m1 <- '
visual =~ x1 + x2 + x3
textual =~ x4 + x5 + x6
speed =~ x7 + x8 + x9
visual ~ speed + textual + speed:textual
'
est <- modsem(m1, data = lavaan::HolzingerSwineford1939, method = "ca")
plot_jn(x = "speed", z = "textual", y = "visual", model = est, max_z = 6)
## End(Not run)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.