| jn_plot_func | R Documentation |
Generates a Johnson-Neyman Plot using a function to produce the conditional effect
jn_plot_func(func, xrange, ci = 0.95, ...)
func |
a |
xrange |
a |
ci |
a value between 0 and 1 specifying the credible interval size |
... |
values passed to internal boundary search algorithm. See Details below. |
To change colors use ggplot2's scale system. Both fill and color are used. See
ggplot2::aes_colour_fill_alpha for more information about setting a manual set of colors.
For ..., the arguments are passed to the internal boundary search algorithm.
This algorithm uses an initial grid search to locate boundaries based on the range
and then a binary search to refine the estimates.
The following arguments are available:
Number of points in the initial coarse grid search used to locate approximate boundary positions. Higher values improve detection of closely-spaced boundaries but increase computation time. Default is 1000.
Tolerance for binary search refinement. The algorithm refines each boundary until the interval width is smaller than this value. Smaller values give higher precision but require more function evaluations. Default is 1e-12.
Maximum number of iterations for binary search refinement per boundary. Prevents infinite loops if tolerance cannot be achieved. Default is 100.
Logical indicating whether to perform additional refinement in regions where boundaries are detected to be closely spaced. When TRUE, uses a finer grid to resolve boundaries that may be missed by the initial coarse grid. Default is TRUE.
a ggplot2::ggplot plot. The bounding values are saved in the attribute 'bounds'.
compute_condeff()
# Generate Data
mydata <- rblimp_sim(
c(
'x1 ~ normal(0, 1)',
'x2 ~ normal(0, 1)',
'm ~ normal(0, 1)',
'y ~ normal(10 + 0.5*x1 + 0.5*x2 + m + 0.2*x1*x2 + 0.3*x2*m + 0.1*x1*m + 0.7*x1*x2*m, 1)'
),
n = 100,
seed = 981273
)
# Run Rblimp
m1 <- rblimp(
'y ~ x1 x2 m x1*x2 x1*m x2*m x1*x2*m',
mydata,
center = ~ m,
seed = 10972,
burn = 1000,
iter = 1000
)
# Get parameter values
params <- m1 |> as.matrix()
# Generate Plot
(
jn_plot_func(
compute_condeff(params[,6], params[,9]),
xrange = c(-3, 3)
)
+ ggplot2::labs(
title = 'Johnson-Neyman Plot for `x1` * `x2` Moderated by `x2`',
subtitle = 'Red area represents 0 within 95% interval',
y = 'y ~ x1 * x2',
x = 'm'
)
+ ggplot2::theme_minimal()
)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.