stdmod {stdmod} | R Documentation |
Standardized Moderation Effect Given an 'lm' Output
Description
Compute the standardized moderation effect in a moderated regression model.
Usage
stdmod(
lm_out,
x = NULL,
w = NULL,
y = NULL,
x_rescale = TRUE,
w_rescale = TRUE,
y_rescale = TRUE
)
stdmod_boot(
lm_out,
...,
nboot = 100,
conf = 0.95,
boot_args = NULL,
full_output = FALSE
)
Arguments
lm_out |
The output from |
x |
The focal variable, that is, the variable with its effect
being moderated. If supplied, its standard deviation will be
used
for rescaling. Also called the independent variable in some
models. Default is |
w |
The moderator. If supplied, its standard deviation will be
used
for rescaling. Default is |
y |
The outcome variable (dependent variable) . If supplied, its standard deviation will be used for rescaling. Default is NULL. |
x_rescale |
If |
w_rescale |
If |
y_rescale |
If |
... |
Parameters to be passed to |
nboot |
The number of bootstrap samples. Default is 100. |
conf |
The level of confidence for the confidence interval. Default is .95. |
boot_args |
A named list of arguments to be passed to |
full_output |
Whether the full output from |
Details
Two more general functions, std_selected()
and
std_selected_boot()
, have been developed and can do what these functions
do and more. Users are recommended to use them instead of stdmod()
and
stdmod_boot()
. These two functions will not be updated in the near
future.
Nevertheless, if computing the standardized moderation effect and forming its nonparametric bootstrap interval are all required, then these functions can still be used.
stdmod()
computes the standardized moderation effect given an
lm()
output using the formula from Cheung, Cheung, Lau, Hui, and Vong
(2022). Users specify
the moderator, the focal variable (the variable with its effect on
the outcome variable moderated), the outcome variable (dependent variable)
, and the corresponding
standardized moderation
effect. Users can also select which variable(s) will be standardized.
stdmod_boot()
is a wrapper of stdmod()
. It computes the nonparametric
bootstrap confidence interval of the standardized moderation effect, as
suggested by Cheung, Cheung, Lau, Hui, and Vong (2022), given
the output of lm()
Percentile interval from boot::boot.ci()
is returned by this function.
If other types of
confidence intervals are desired, set full_output = TRUE
and use
boot::boot.ci()
on the element boot_out
in the output of this
function.
Value
stdmod()
returns a scalar: The standardized moderation effect.
stdmod_boot()
returns a list with two elements. The element ci
is
a numeric vector of the bootstrap confidence interval. The element boot_out
,
if not NA
, is the output of boot::boot()
, which is used to do the
bootstrapping.
Functions
-
stdmod()
: The base function for computing standardized moderation effect -
stdmod_boot()
: A wrapper ofstdmod()
that computes the nonparametric bootstrap confidence interval of the standardized moderation effect.
Author(s)
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
References
Cheung, S. F., Cheung, S.-H., Lau, E. Y. Y., Hui, C. H., & Vong, W. N. (2022) Improving an old way to measure moderation effect in standardized units. Health Psychology, 41(7), 502-505. doi:10.1037/hea0001188
Examples
# Load a test data of 500 cases
dat <- test_x_1_w_1_v_2_n_500
# Do regression as usual:
lm_raw <- lm(dv ~ iv*mod + v1 + v2, dat)
summary(lm_raw)
# The standard deviations of iv, dv, and mod:
sds <- apply(dat, 2, sd)
sds
# Compute the standardized moderation effect:
stdmod_xyw <- stdmod(lm_raw, x = iv, y = dv, w = mod)
stdmod_xyw
# By default, all three variables will be standardized.
# Check against self-computed standardized moderation effect:
coef(lm_raw)["iv:mod"] * sds["iv"] * sds["mod"] / sds["dv"]
# Standardize only the iv, i.e., do not standardized dv and the moderator:
stdmod_x <- stdmod(lm_raw, x = iv, y = dv, w = mod,
x_rescale = TRUE, y_rescale = FALSE, w_rescale = FALSE)
stdmod_x
# Check against self-computed moderation effect with only iv standardized:
coef(lm_raw)["iv:mod"] * sds["iv"]
dat <- test_x_1_w_1_v_2_n_500
# Do regression as usual:
lm_raw <- lm(dv ~ iv*mod + v1 + v2, dat)
# Compute the standardized moderation effect.
# Form its confidence interval by nonparametric bootstrapping.
set.seed(85740917)
stdmod_xyw_boot <- stdmod_boot(lm_raw, x = iv, w = mod, y = dv, nboot = 100)
# In real analysis, nboot should be at least 2000.
# Print the ci
stdmod_xyw_boot$ci
# Repeat the analysis but keep the results from boot:
set.seed(85740917)
stdmod_xyw_boot <- stdmod_boot(lm_raw, x = iv, w = mod, y = dv,
nboot = 200, full_output = TRUE)
# In real analysis, nboot should be at least 2000.
# Print the 95% percentile confidence interval
stdmod_xyw_boot$ci