Title: | Betas-Select in Structural Equation Models and Linear Models |
---|---|
Description: | It computes betas-select, coefficients after standardization in structural equation models and regression models, standardizing only selected variables. Supports models with moderation, with product terms formed after standardization. It also offers confidence intervals that account for standardization, including bootstrap confidence intervals as proposed by Cheung et al. (2022) <doi:10.1037/hea0001188>. |
Authors: | Shu Fai Cheung [aut, cre] , Rong Wei Sun [aut] , Florbela Chang [aut] , Wendie Yang [aut] , Sing-Hang Cheung [aut] |
Maintainer: | Shu Fai Cheung <[email protected]> |
License: | GPL (>= 3) |
Version: | 0.1.0 |
Built: | 2024-11-12 05:20:12 UTC |
Source: | CRAN |
Return the analysis
of variance tables for
the outputs of
lm_betaselect()
and
glm_betaselect()
.
## S3 method for class 'lm_betaselect' anova(object, ..., type = c("beta", "standardized", "raw", "unstandardized")) ## S3 method for class 'glm_betaselect' anova( object, ..., type = c("beta", "standardized", "raw", "unstandardized"), dispersion = NULL, test = NULL )
## S3 method for class 'lm_betaselect' anova(object, ..., type = c("beta", "standardized", "raw", "unstandardized")) ## S3 method for class 'glm_betaselect' anova( object, ..., type = c("beta", "standardized", "raw", "unstandardized"), dispersion = NULL, test = NULL )
object |
The output of
|
... |
Additional outputs
of |
type |
String. If
|
dispersion |
To be passed to
|
test |
String. The test to be
conducted. Please refer to
|
By default, it calls stats::anova()
on the results with selected variables
standardized. By setting type
to
"raw"
or "unstandardized"
, it
calls stats::anova()
on the results
before standardization.
It returns an object of class
anova
, which is identical to
the output of stats::anova()
in
structure.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = FALSE) anova(lm_beta_x) anova(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv") anova(logistic_beta_x) anova(logistic_beta_x, type = "raw")
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = FALSE) anova(lm_beta_x) anova(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv") anova(logistic_beta_x) anova(logistic_beta_x, type = "raw")
Return the betas-select in a 'lav_betaselect'-class object.
## S3 method for class 'lav_betaselect' coef(object, drop_na = FALSE, ...)
## S3 method for class 'lav_betaselect' coef(object, drop_na = FALSE, ...)
object |
The output of
|
drop_na |
Logical. Whether betas-select
with |
... |
Optional arguments. Not used. |
It just extracts and
returns the column est
from
the object: the betas-select, with
selected variables standardized.
A numeric vector: The betas-select
in the object. The names of parameters
follow the convention in lavaan
.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) coef(fit_beta)
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) coef(fit_beta)
Return the estimates of
coefficients in an
lm_betaselect
-class or
glm_betaselect
-class object.
## S3 method for class 'lm_betaselect' coef( object, complete = FALSE, type = c("beta", "standardized", "raw", "unstandardized"), ... ) ## S3 method for class 'glm_betaselect' coef( object, complete = FALSE, type = c("beta", "standardized", "raw", "unstandardized"), ... )
## S3 method for class 'lm_betaselect' coef( object, complete = FALSE, type = c("beta", "standardized", "raw", "unstandardized"), ... ) ## S3 method for class 'glm_betaselect' coef( object, complete = FALSE, type = c("beta", "standardized", "raw", "unstandardized"), ... )
object |
The output of
|
complete |
If |
type |
String. If |
... |
Other arguments. Ignored. |
By default, it extracts the regression coefficients after the selected variables have been standardized. If requested, it can also return the regression coefficients before standardization.
A numeric vector: The estimate of regression coefficients.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
lm_betaselect()
and
glm_betaselect()
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv") coef(lm_beta_x) coef(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv") coef(logistic_beta_x) coef(logistic_beta_x, type = "raw")
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv") coef(lm_beta_x) coef(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv") coef(logistic_beta_x) coef(logistic_beta_x, type = "raw")
Return the confidence
intervals of betas-select in the
output of lav_betaselect()
.
## S3 method for class 'lav_betaselect' confint(object, parm, level = 0.95, ...)
## S3 method for class 'lav_betaselect' confint(object, parm, level = 0.95, ...)
object |
The output of |
parm |
Ignored due to the complexity in the naming. The confidence intervals of all parameters are always returned. |
level |
The level of confidence.
Ignored because the intervals should be
formed
when calling |
... |
Optional arguments. Ignored. |
The type of
confidence intervals depends
on the call to lav_betaselect()
.
This function does not recompute
the confidence interval.
A two-column matrix of the confidence intervals.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) confint(fit_beta)
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) confint(fit_beta)
Return the confidence
interval of the regression
coefficients in the output of
lm_betaselect()
or
glm_betaselect()
.
## S3 method for class 'lm_betaselect' confint( object, parm, level = 0.95, method = c("boot", "bootstrap", "ls"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, boot_type = c("perc", "bc"), ... ) ## S3 method for class 'glm_betaselect' confint( object, parm, level = 0.95, trace = FALSE, test = c("LRT", "Rao"), method = c("boot", "bootstrap", "default", "ls"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, boot_type = c("perc", "bc"), transform_b = NULL, ... )
## S3 method for class 'lm_betaselect' confint( object, parm, level = 0.95, method = c("boot", "bootstrap", "ls"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, boot_type = c("perc", "bc"), ... ) ## S3 method for class 'glm_betaselect' confint( object, parm, level = 0.95, trace = FALSE, test = c("LRT", "Rao"), method = c("boot", "bootstrap", "default", "ls"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, boot_type = c("perc", "bc"), transform_b = NULL, ... )
object |
The output of
|
parm |
The terms for which the confidence intervals are returned. If missing, the confidence intervals of all terms will be returned. |
level |
The level of confidence, default is .95, returning the 95% confidence interval. |
method |
The method used to
compute the confidence intervals/
If bootstrapping was
requested when calling
|
type |
String. If
|
warn |
Logical. Whether a warning
will be raised is OLS (or WLS)
confidence intervals are
requested for the model with some
variables standardized (i.e., |
boot_type |
The type of
bootstrap confidence intervals.
Currently, it supports |
... |
Optional arguments. Ignored. |
trace |
Logical. Whether profiling
will be traced. See
|
test |
The test used for
profiling. See stats::confint.glm
for details.
ignored if |
transform_b |
The function
to be used to transform the
confidence limits. For example,
if set to |
The type of confidence intervals depends on the object. If bootstrapping was requested, by default it returns the percentile bootstrap confidence intervals. Otherwise, it returns the default confidence intervals.
Support for other type of confidence intervals may be added in the future.
A p by 2 matrix of the confidence intervals, p being the number of coefficients.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
data(data_test_mod_cat) # bootstrap should be set to 2000 or 5000 in real studies lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) confint(lm_beta_x) confint(lm_beta_x, method = "ls") confint(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # bootstrap should be set to 2000 or 5000 in real studies logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) confint(logistic_beta_x, method = "default") confint(logistic_beta_x, type = "raw")
data(data_test_mod_cat) # bootstrap should be set to 2000 or 5000 in real studies lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) confint(lm_beta_x) confint(lm_beta_x, method = "ls") confint(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # bootstrap should be set to 2000 or 5000 in real studies logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) confint(logistic_beta_x, method = "default") confint(logistic_beta_x, type = "raw")
This dataset has one mediator, one moderator, one independent variable, one dependent variable, and two control variables.
data_test_medmod
data_test_medmod
A data frame with 200 rows and five variables:
Dependent variable, continuous
Independent variable, continuous
Moderator, continuous
Mediator, continuous
Control variable, continuous
Control variable, continuous
library(lavaan) mod <- " med ~ iv + mod + iv:mod + cov1 + cov2 dv ~ med + iv + cov1 + cov2 " fit <- sem(mod, data_test_medmod) summary(fit)
library(lavaan) mod <- " med ~ iv + mod + iv:mod + cov1 + cov2 dv ~ med + iv + cov1 + cov2 " fit <- sem(mod, data_test_medmod) summary(fit)
This dataset has one predictor, one moderator, one control variable, one dependent variable, and a categorical variable.
data_test_mod_cat
data_test_mod_cat
A data frame with 500 rows and five variables:
Dependent variable, continuous
Independent variable, continuous
Moderator, continuous
Control variable, continuous
String variable with these values: "gp1", "gp2", and "gp3"
lm_out <- lm(dv ~ iv * mod + cov1 + cat1, data_test_mod_cat) summary(lm_out)
lm_out <- lm(dv ~ iv * mod + cov1 + cat1, data_test_mod_cat) summary(lm_out)
This dataset has one predictor, one moderator, one control variable, one binary dependent variable, and a categorical variable.
data_test_mod_cat_binary
data_test_mod_cat_binary
A data frame with 300 rows and five variables:
Dependent variable, binary: 0, 1
Independent variable, continuous
Moderator, continuous
Control variable, continuous
String variable with these values: "gp1", "gp2", and "gp3"
glm_out <- glm(dv ~ iv * mod + cov1 + cat1, data_test_mod_cat_binary, family = binomial()) summary(glm_out)
glm_out <- glm(dv ~ iv * mod + cov1 + cat1, data_test_mod_cat_binary, family = binomial()) summary(glm_out)
This dataset has one predictor, one moderator, one control variable, one dependent variable, and a categorical variable.
Similar to data_test_mod_cat
but
generated from another population.
data_test_mod_cat2
data_test_mod_cat2
A data frame with 300 rows and five variables:
Dependent variable, continuous
Independent variable, continuous
Moderator, continuous
Control variable, continuous
String variable with these values: "gp1", "gp2", and "gp3"
lm_out <- lm(dv ~ iv * mod + cov1 + cat1, data_test_mod_cat) summary(lm_out)
lm_out <- lm(dv ~ iv * mod + cov1 + cat1, data_test_mod_cat) summary(lm_out)
The getCall
-method
for an lm_betaselect
-class or
glm_betaselectd
-class objects.
## S3 method for class 'lm_betaselect' getCall( x, what = c("lm_betaselect", "beta", "standardized", "raw", "unstandardized"), ... ) ## S3 method for class 'glm_betaselect' getCall( x, what = c("glm_betaselect", "beta", "standardized", "raw", "unstandardized"), ... )
## S3 method for class 'lm_betaselect' getCall( x, what = c("lm_betaselect", "beta", "standardized", "raw", "unstandardized"), ... ) ## S3 method for class 'glm_betaselect' getCall( x, what = c("glm_betaselect", "beta", "standardized", "raw", "unstandardized"), ... )
x |
An |
what |
Which call to extract.
For |
... |
Additional arguments. Ignored. |
This works in the same way
the default getCall
-method does for
the outputs of stats::lm()
and stats::glm()
.
It returns the call requested.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
lm_betaselect()
,
glm_betaselect()
, and stats::getCall()
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1, data = data_test_mod_cat, to_standardize = "iv") getCall(lm_beta_x) getCall(lm_beta_x, what = "beta") getCall(lm_beta_x, what = "raw")
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1, data = data_test_mod_cat, to_standardize = "iv") getCall(lm_beta_x) getCall(lm_beta_x, what = "beta") getCall(lm_beta_x, what = "raw")
Can standardize selected
variables in a lavaan
model without
refitting the models, can handle
product term correctly and skip
categorical predictors in
standardization.
lav_betaselect( object, to_standardize = ".all.", not_to_standardize = NULL, skip_categorical_x = TRUE, output = c("data.frame", "text"), std_se = c("none", "delta", "bootstrap"), std_z = TRUE, std_pvalue = TRUE, std_ci = TRUE, level = 0.95, progress = TRUE, boot_out = NULL, bootstrap = 100L, store_boot_est = TRUE, parallel = c("no", "snow", "multicore"), ncpus = parallel::detectCores(logical = FALSE) - 1, cl = NULL, iseed = NULL, find_product_terms = TRUE, ..., delta_method = c("lavaan", "numDeriv"), vector_form = TRUE )
lav_betaselect( object, to_standardize = ".all.", not_to_standardize = NULL, skip_categorical_x = TRUE, output = c("data.frame", "text"), std_se = c("none", "delta", "bootstrap"), std_z = TRUE, std_pvalue = TRUE, std_ci = TRUE, level = 0.95, progress = TRUE, boot_out = NULL, bootstrap = 100L, store_boot_est = TRUE, parallel = c("no", "snow", "multicore"), ncpus = parallel::detectCores(logical = FALSE) - 1, cl = NULL, iseed = NULL, find_product_terms = TRUE, ..., delta_method = c("lavaan", "numDeriv"), vector_form = TRUE )
object |
The output of
|
to_standardize |
A string vector,
which should be the names of the
variables to be standardized.
Default is |
not_to_standardize |
A string
vector, which should be the names
of the variables that should not be
standardized. This argument is useful
when most variables, except for a few,
are to be standardized. This argument
cannot be ued with |
skip_categorical_x |
Logical.
If |
output |
The format of the
output. Not used because the format
of the printout is now controlled
by the |
std_se |
String. If set to |
std_z |
Logical. If |
std_pvalue |
Logical. If |
std_ci |
Logical. If |
level |
The level of confidence of the confidence intervals. Default is .95. It will be used in the confidence intervals of both the unstandardized and standardized solution. |
progress |
Logical. If |
boot_out |
If |
bootstrap |
If |
store_boot_est |
Logical. If
|
parallel |
If |
ncpus |
If |
cl |
If |
iseed |
If |
find_product_terms |
String.
If it is certain that a model does
not have product terms, setting this
to |
... |
Optional arguments to be
passed to the |
delta_method |
The method used to compute delta-method standard errors. For internal use and should not be changed. |
vector_form |
The internal method used to compute standardized solution. For internal use and should not be changed. |
This function lets users select which variables to be standardized when computing the standardized solution. It has the following features:
It automatically skips predictors which has only two unique values, assuming that they are dummy variables.
It does not standardize product term, which is incorrect. Instead, it computes the product term with its component variables standardized first.
It can be used to generate bootstrap confidence intervals for the standardized solution (Falk, 2018). Bootstrap confidence interval is better than doing standardization before fitting a model because it correctly takes into account the sampling variance of the standard deviations. It is also better than delta-method confidence interval because it takes into account the usually asymmetric distribution of parameters after standardization, such as standardized loadings and correlations.
For comparison, it can also report delta-method standard errors and confidence intervals if requested.
In most SEM programs, users have limited control on which variables to standardize when requesting the standardized solution. The solution may be uninterpretable or misleading in these conditions:
Dummy variables are standardized and their coefficients cannot be interpreted as the difference between two groups on the outcome variables.
Product terms (interaction terms) are standardized and they cannot be interpreted as the changes in the effects of focal variables when the moderators change (Cheung, Cheung, Lau, Hui, & Vong, 2022).
Variables with meaningful units can be more difficult to interpret when they are standardized (e.g., age).
Moreover, the delta method is usually used in standardization, which is suboptimal for standardization unless the sample size is large (Falk, 2018). For example, the covariance with variables standardized is a correlation, and its sampling distribution is skewed unless its population value is zero. However, delta-method confidence interval for the correlation is necessarily symmetric around the point estimate.
It only supports observed variable interaction terms, and only support two-way interactions.
It does not support multilevel models.
It only supports models fitted to raw data.
Intercepts not supported.
A lav_betaselect
-class object,
which is a data frame storing the parameter
estimates, similar in form to the
output of lavaan::parameterEstimates()
.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Asparouhov, A., & Muthén, B. (2021). Bootstrap p-value computation. Retrieved from https://www.statmodel.com/download/FAQ-Bootstrap%20-%20Pvalue.pdf
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
Falk, C. F. (2018). Are robust standard errors the best approach for interval estimation with nonnormal data in structural equation modeling? Structural Equation Modeling: A Multidisciplinary Journal, 25(2) 244-266. doi:10.1080/10705511.2017.1367254
print.lav_betaselect()
for its print method.
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) fit_beta print(fit_beta, standardized_only = FALSE) # In real studies: # - should set bootstrap to at least 5000 # - should set parallel to "snow" or "multicore" fit_beta_boot <- lav_betaselect(fit, to_standardize = c("iv", "dv"), std_se = "bootstrap", std_ci = TRUE, bootstrap = 100, iseed = 1234) fit_beta_boot print(fit_beta_boot, standardized_only = FALSE) # Print full results print(fit_beta_boot, standardized_only = FALSE)
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) fit_beta print(fit_beta, standardized_only = FALSE) # In real studies: # - should set bootstrap to at least 5000 # - should set parallel to "snow" or "multicore" fit_beta_boot <- lav_betaselect(fit, to_standardize = c("iv", "dv"), std_se = "bootstrap", std_ci = TRUE, bootstrap = 100, iseed = 1234) fit_beta_boot print(fit_beta_boot, standardized_only = FALSE) # Print full results print(fit_beta_boot, standardized_only = FALSE)
Can fit a linear regression models with selected variables standardized; handle product terms correctly and skip categorical predictors in standardization.
lm_betaselect( ..., to_standardize = NULL, not_to_standardize = NULL, skip_response = FALSE, do_boot = TRUE, bootstrap = 100L, iseed = NULL, parallel = FALSE, ncpus = parallel::detectCores(logical = FALSE) - 1, progress = TRUE, load_balancing = FALSE, model_call = c("lm", "glm") ) glm_betaselect( ..., to_standardize = NULL, not_to_standardize = NULL, skip_response = FALSE, do_boot = TRUE, bootstrap = 100L, iseed = NULL, parallel = FALSE, ncpus = parallel::detectCores(logical = FALSE) - 1, progress = TRUE, load_balancing = FALSE ) ## S3 method for class 'lm_betaselect' print( x, digits = max(3L, getOption("digits") - 3L), type = c("beta", "standardized", "raw", "unstandardized"), ... ) ## S3 method for class 'glm_betaselect' print( x, digits = max(3L, getOption("digits") - 3L), type = c("beta", "standardized", "raw", "unstandardized"), ... ) raw_output(x)
lm_betaselect( ..., to_standardize = NULL, not_to_standardize = NULL, skip_response = FALSE, do_boot = TRUE, bootstrap = 100L, iseed = NULL, parallel = FALSE, ncpus = parallel::detectCores(logical = FALSE) - 1, progress = TRUE, load_balancing = FALSE, model_call = c("lm", "glm") ) glm_betaselect( ..., to_standardize = NULL, not_to_standardize = NULL, skip_response = FALSE, do_boot = TRUE, bootstrap = 100L, iseed = NULL, parallel = FALSE, ncpus = parallel::detectCores(logical = FALSE) - 1, progress = TRUE, load_balancing = FALSE ) ## S3 method for class 'lm_betaselect' print( x, digits = max(3L, getOption("digits") - 3L), type = c("beta", "standardized", "raw", "unstandardized"), ... ) ## S3 method for class 'glm_betaselect' print( x, digits = max(3L, getOption("digits") - 3L), type = c("beta", "standardized", "raw", "unstandardized"), ... ) raw_output(x)
... |
For |
to_standardize |
A string vector,
which should be the names of the
variables to be standardized.
Default is |
not_to_standardize |
A string
vector, which should be the names
of the variables that should not be
standardized. This argument is useful
when most variables, except for a few,
are to be standardized. This argument
cannot be ued with |
skip_response |
Logical. If
|
do_boot |
Whether bootstrapping
will be conducted. Default is |
bootstrap |
If |
iseed |
If |
parallel |
If |
ncpus |
If |
progress |
Logical. If |
load_balancing |
Logical. If
|
model_call |
The model function
to be called.
If |
x |
An |
digits |
The number of significant digits to be printed for the coefficients. |
type |
The coefficients to be
printed. For |
The functions lm_betaselect()
and glm_betaselect()
let users
select which variables to be
standardized when computing the
standardized solution. They have the
following features:
They automatically skip categorical predictors (i.e., factor or string variables).
They do not standardize a product term, which is incorrect. Instead, they compute the product term with its component variables standardized, if requested.
They standardize the selected
variables before fitting a model.
Therefore, If a model has the term
log(x)
and x
is one of the
selected variables, the model used
the logarithm of the standardized
x
in the model, instead of
standardized log(x)
which is
difficult to interpret.
They can be used to generate nonparametric bootstrap confidence intervals for the standardized solution. Bootstrap confidence interval is better than the default confidence interval ignoring the standardization because it takes into account the sampling variance of the standard deviations. Preliminary support for bootstrap confidence has been found for forming confidence intervals for coefficients involving standardized variables in linear regression (Jones & Waller, 2013).
In some regression programs, users have limited control on which variables to standardize when requesting the so-called "betas". The solution may be uninterpretable or misleading in these conditions:
Dummy variables are standardized and their coefficients cannot be interpreted as the difference between two groups on the outcome variables.
Product terms (interaction terms) are standardized and they cannot be interpreted as the changes in the effects of focal variables when the moderators change (Cheung, Cheung, Lau, Hui, & Vong, 2022).
Variables with meaningful units can be more difficult to interpret when they are standardized (e.g., age).
They standardize the original variables before they are used in the model. Therefore, strictly speaking, they do not standardize the predictors in model, but standardize the input variable (Gelman et al., 2021).
The requested model is then fitted to
the dataset with selected variables
standardized. For the ease of
follow-up analysis, both the results
with selected variables standardized
and the results without
standardization are stored. If
required, the results without
standardization can be retrieved
by raw_output()
.
The output of lm_betaselect()
is
an lm_betaselect
-class object,
and the output of glm_betaselect()
is a glm_betaselect
-class object.
They have the following methods:
A coef
-method for extracting
the coefficients of the model.
(See coef.lm_betaselect()
and coef.glm_betaselect()
for details.)
A vcov
-method for extracting the
variance-covariance matrix of the
estimates of the coefficients.
If bootstrapping is requested, it
can return the matrix based on the
bootstrapping estimates.
(See vcov.lm_betaselect()
and vcov.glm_betaselect()
for details.)
A confint
-method for forming the
confidence intervals of the
estimates of the coefficients.
If bootstrapping is requested, it
can return the bootstrap confidence
intervals.
(See confint.lm_betaselect()
and
confint.glm_betaselect()
for details.)
A summary
-method for printing the
summary of the results, with additional
information such as the number of
bootstrap samples and which variables
have been standardized.
(See summary.lm_betaselect()
and
summary.glm_betaselect()
for details.)
An anova
-method for printing the
ANOVA table. Can also be used to
compare two or more outputs of
lm_betaselect()
or
glm_betaselect()
(See anova.glm_betaselect()
and anova.glm_betaselect()
for details.)
A predict
-method for computing
predicted values. It can be used to
compute the predicted values given
a set of new unstandardized data.
The data will be standardized before
computing the predicted values in
the models with standardization.
(See predict.lm_betaselect()
and
predict.glm_betaselect()
for details.)
The default update
-method for updating
a call also works for an
lm_betaselect
object or
a glm_betaselect()
object. It can
update the model in the same
way it updates a model fitted by
stats::lm()
or stats::glm()
,
and also update
the arguments of lm_betaselect()
or glm_betaselect()
such as the variables to be
standardized.
(See stats::update()
for details.)
Most other methods for the output
of stats::lm()
and stats::glm()
should also work
on an lm_betaselect
-class object
or a glm_betaselect
-class object,
respectively.
Some of them will give the same
results regardless of the variables
standardized. Examples are
rstandard()
and cooks.distance()
.
For some others, they should be used
with cautions if they make use of
the variance-covariance matrix
of the estimates.
To use the methods for lm
objects
or glm
objects
on the results without standardization,
simply use raw_output()
. For example,
to get the fitted values without
standardization, call
fitted(raw_output(x))
, where x
is the output of lm_betaselect()
or glm_betaselect()
.
The function raw_output()
simply extracts
the regression output by stats::lm()
or stats::glm()
on the variables without standardization.
The function lm_betaselect()
returns an object of the class lm_betaselect
,
The function glm_betaselect()
returns an object of the class
glm_betaselect
. They are similar
in structure to the output of
stats::lm()
and stats::glm()
,
with additional information stored.
The function raw_output()
returns
an object of the class lm
or
glm
, which are
the results of fitting the model
to the data by stats::lm()
or stats::glm()
without
standardization.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
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
Craig, C. C. (1936). On the frequency function of xy. The Annals of Mathematical Statistics, 7(1), 1–15. doi:10.1214/aoms/1177732541
Gelman, A., Hill, J., & Vehtari, A. (2021). Regression and other stories. Cambridge University Press. doi:10.1017/9781139161879
Jones, J. A., & Waller, N. G. (2013). Computing confidence intervals for standardized regression coefficients. Psychological Methods, 18(4), 435–453. doi:10.1037/a0033269
print.lm_betaselect()
and
print.glm_betaselect()
for the
print
-methods.
data(data_test_mod_cat) # Standardize only iv lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv") lm_beta_x summary(lm_beta_x) # Manually standardize iv and call lm() data_test_mod_cat$iv_z <- scale(data_test_mod_cat[, "iv"])[, 1] lm_beta_x_manual <- lm(dv ~ iv_z*mod + cov1 + cat1, data = data_test_mod_cat) coef(lm_beta_x) coef(lm_beta_x_manual) # Standardize all numeric variables lm_beta_all <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat) # Note that cat1 is not standardized summary(lm_beta_all) data(data_test_mod_cat) data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # Standardize only iv logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, family = binomial, data = data_test_mod_cat, to_standardize = "iv") summary(logistic_beta_x) logistic_beta_x summary(logistic_beta_x) # Manually standardize iv and call glm() data_test_mod_cat$iv_z <- scale(data_test_mod_cat[, "iv"])[, 1] logistic_beta_x_manual <- glm(p ~ iv_z*mod + cov1 + cat1, family = binomial, data = data_test_mod_cat) coef(logistic_beta_x) coef(logistic_beta_x_manual) # Standardize all numeric predictors logistic_beta_allx <- glm_betaselect(p ~ iv*mod + cov1 + cat1, family = binomial, data = data_test_mod_cat, to_standardize = c("iv", "mod", "cov1")) # Note that cat1 is not standardized summary(logistic_beta_allx) summary(raw_output(lm_beta_x))
data(data_test_mod_cat) # Standardize only iv lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv") lm_beta_x summary(lm_beta_x) # Manually standardize iv and call lm() data_test_mod_cat$iv_z <- scale(data_test_mod_cat[, "iv"])[, 1] lm_beta_x_manual <- lm(dv ~ iv_z*mod + cov1 + cat1, data = data_test_mod_cat) coef(lm_beta_x) coef(lm_beta_x_manual) # Standardize all numeric variables lm_beta_all <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat) # Note that cat1 is not standardized summary(lm_beta_all) data(data_test_mod_cat) data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # Standardize only iv logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, family = binomial, data = data_test_mod_cat, to_standardize = "iv") summary(logistic_beta_x) logistic_beta_x summary(logistic_beta_x) # Manually standardize iv and call glm() data_test_mod_cat$iv_z <- scale(data_test_mod_cat[, "iv"])[, 1] logistic_beta_x_manual <- glm(p ~ iv_z*mod + cov1 + cat1, family = binomial, data = data_test_mod_cat) coef(logistic_beta_x) coef(logistic_beta_x_manual) # Standardize all numeric predictors logistic_beta_allx <- glm_betaselect(p ~ iv*mod + cov1 + cat1, family = binomial, data = data_test_mod_cat, to_standardize = c("iv", "mod", "cov1")) # Note that cat1 is not standardized summary(logistic_beta_allx) summary(raw_output(lm_beta_x))
Compute the predicted
values in a model fitted by
glm_betaselect()
.
## S3 method for class 'glm_betaselect' predict( object, model_type = c("beta", "standardized", "raw", "unstandardized"), newdata, ... )
## S3 method for class 'glm_betaselect' predict( object, model_type = c("beta", "standardized", "raw", "unstandardized"), newdata, ... )
object |
A |
model_type |
The model from which the
the predicted values are computed.
For
|
newdata |
If set to a data
frame, the predicted values are
computed using this data frame.
The data must be unstandardized.
That is, the variables are of the
same units as in the data frame
used in |
... |
Arguments
to be passed to |
It simply passes the model before
or after selected variables
are standardized to the
predict
-method of a glm
object.
Some statistics, such as prediction or confidence interval, which make use of the sampling variances and covariances of coefficient estimates may not be applicable to the models with one or more variables standardized. Therefore, they should only be used for exploratory purpose.
It returns the output of stats::predict.glm()
.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
glm_betaselect()
and stats::predict.glm()
data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv") predict(logistic_beta_x) predict(logistic_beta_x, model_type = "raw")
data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv") predict(logistic_beta_x) predict(logistic_beta_x, model_type = "raw")
Compute the predicted
values in a model fitted by
lm_betaselect()
.
## S3 method for class 'lm_betaselect' predict( object, model_type = c("beta", "standardized", "raw", "unstandardized"), newdata, ... )
## S3 method for class 'lm_betaselect' predict( object, model_type = c("beta", "standardized", "raw", "unstandardized"), newdata, ... )
object |
An |
model_type |
The model from which the
the predicted values are computed.
For
|
newdata |
If set to a data
frame, the predicted values are
computed using this data frame.
The data must be unstandardized.
That is, the variables are of the
same units as in the data frame
used in |
... |
Arguments
to be passed to |
It simply passes the model before
or after selected variables
are standardized to the
predict
-method of an lm
object.
Some statistics, such as prediction or confidence interval, which make use of the sampling variances and covariances of coefficient estimates may not be applicable to the models with one or more variables standardized. Therefore, they should only be used for exploratory purpose.
It returns the output of stats::predict.lm()
.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
lm_betaselect()
and stats::predict.lm()
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv") predict(lm_beta_x) predict(lm_beta_x, model_type = "raw")
data(data_test_mod_cat) lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv") predict(lm_beta_x) predict(lm_beta_x, model_type = "raw")
Print method for a
'lav_betaselect' object, which
is the output of
lav_betaselect()
.
## S3 method for class 'lav_betaselect' print( x, ..., nd = 3, output = c("lavaan.printer", "table"), standardized_only = TRUE, show_Bs.by = FALSE, by_group = TRUE, na_str = " ", sig_stars = TRUE, ci_sig = TRUE )
## S3 method for class 'lav_betaselect' print( x, ..., nd = 3, output = c("lavaan.printer", "table"), standardized_only = TRUE, show_Bs.by = FALSE, by_group = TRUE, na_str = " ", sig_stars = TRUE, ci_sig = TRUE )
x |
A |
... |
Optional arguments to be
passed to |
nd |
The number of digits after the decimal place. Default is 3. |
output |
String. How the results
are printed. Default is |
standardized_only |
Logical.
If |
show_Bs.by |
Logical. If |
by_group |
If |
na_str |
The string to be used
for cells with |
sig_stars |
If |
ci_sig |
If |
The default format of the printout,
"lavaan.printer"
,
is similar to that of the summary()
of a lavaan
object.
Users can also select whether
only the standardized solution is
printed or whether
the standardized solution is appended
to the right of the printout.
If output
is set to "table"' the format is that of [lavaan::parameterEstimates()] with
output = "data.frame"',
which is compact but not easy to
read.
x
is returned invisibly. Called for its side effect.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
lav_betaselect()
. This
function is adapted from
semhelpinghands::print.std_solution_boot()
.
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) fit_beta print(fit_beta) print(fit_beta, show_Bs.by = TRUE) print(fit_beta, output = "table")
library(lavaan) mod <- " med ~ iv + mod + iv:mod dv ~ med + iv " fit <- sem(mod, data_test_medmod, fixed.x = TRUE) summary(fit) fit_beta <- lav_betaselect(fit, to_standardize = c("iv", "dv")) fit_beta print(fit_beta) print(fit_beta, show_Bs.by = TRUE) print(fit_beta, output = "table")
Standardize selected variables in a data frame or similar object.
std_data(data, to_standardize)
std_data(data, to_standardize)
data |
A data frame or similar object. |
to_standardize |
A character vector of the column names of variables to be standardized. |
This is a helper functions
to be used by lm_betaselect()
and glm_betaselect()
. It
assumes that the variables selected
has been checked whether they are
numeric.
A data frame similar to data
,
with selected variables standardized.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
data(data_test_mod_cat) dat <- data_test_mod_cat dat <- std_data(dat, to_standardize = c("iv", "dv")) colMeans(dat[, c("dv", "iv")]) apply(dat[, c("dv", "iv")], 2, sd)
data(data_test_mod_cat) dat <- data_test_mod_cat dat <- std_data(dat, to_standardize = c("iv", "dv")) colMeans(dat[, c("dv", "iv")]) apply(dat[, c("dv", "iv")], 2, sd)
The summary
method
for glm_betaselect
-class objects.
## S3 method for class 'glm_betaselect' summary( object, dispersion = NULL, correlation = FALSE, symbolic.cor = FALSE, trace = FALSE, test = c("LRT", "Rao"), se_method = c("boot", "bootstrap", "z", "glm", "default"), ci = TRUE, level = 0.95, boot_type = c("perc", "bc"), boot_pvalue_type = c("asymmetric", "norm"), type = c("beta", "standardized", "raw", "unstandardized"), print_raw = c("none", "before_ci", "after_ci"), transform_b = NULL, transform_b_name = NULL, ... ) ## S3 method for class 'summary.glm_betaselect' print( x, est_digits = 3, symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), show.residuals = FALSE, z_digits = 3, pvalue_less_than = 0.001, ... )
## S3 method for class 'glm_betaselect' summary( object, dispersion = NULL, correlation = FALSE, symbolic.cor = FALSE, trace = FALSE, test = c("LRT", "Rao"), se_method = c("boot", "bootstrap", "z", "glm", "default"), ci = TRUE, level = 0.95, boot_type = c("perc", "bc"), boot_pvalue_type = c("asymmetric", "norm"), type = c("beta", "standardized", "raw", "unstandardized"), print_raw = c("none", "before_ci", "after_ci"), transform_b = NULL, transform_b_name = NULL, ... ) ## S3 method for class 'summary.glm_betaselect' print( x, est_digits = 3, symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), show.residuals = FALSE, z_digits = 3, pvalue_less_than = 0.001, ... )
object |
The output of
|
dispersion |
The dispersion
parameter. If |
correlation |
If |
symbolic.cor |
If |
trace |
Logical. Whether
profiling will be traced when forming
the confidence interval if
|
test |
The test used for
|
se_method |
The method used to
compute the standard errors and
confidence intervals (if requested).
If bootstrapping was
requested when calling
|
ci |
Logical. Whether
confidence intervals are computed.
Default is |
level |
The level of confidence, default is .95, returning the 95% confidence interval. |
boot_type |
The type of
bootstrap confidence intervals,
if requested.
Currently, it supports |
boot_pvalue_type |
The type
of p-values if |
type |
String. If
|
print_raw |
Control whether
the estimates before selected
standardization are printed when
|
transform_b |
The function
to be used to transform the
confidence limits. For example,
if set to |
transform_b_name |
If
|
... |
Additional arguments passed to other methods. |
x |
The output of
|
est_digits |
The number of
digits after the decimal to be
displayed for the coefficient
estimates, their standard errors, and
confidence intervals (if present).
Note that the values will be rounded
to this number of digits before
printing. If all digits at this
position are zero for all values, the
values may be displayed with fewer
digits. Note that the coefficient
table is printed by
|
signif.stars |
Whether "stars"
(asterisks) are printed to denote
the level of significance achieved
for each coefficient. Default is
|
show.residuals |
If |
z_digits |
The number of digits
after the decimal to be displayed for
the z or similar statistic (in the
column |
pvalue_less_than |
If a
p-value is less than this value, it
will be displayed with |
By default, it returns a
summary.glm_betaselect
-class object
for the results with selected variables
standardized. By setting type
to
"raw"
or "unstandardized"
, it
returns the summary for the results
before standardization.
The print
method of
summary.glm_betaselect
-class objects
is adapted from
stdmod::print.summary.std_selected()
.
It returns an object of class
summary.glm_betaselect
, which is
similar to the output of
stats::summary.glm()
, with additional
information on the standardization
and bootstrapping, if requested.
The print
-method of
summary.glm_betaselect
is called
for its side effect. The object x
is returned invisibly.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Asparouhov, A., & Muthén, B. (2021). Bootstrap p-value computation. Retrieved from https://www.statmodel.com/download/FAQ-Bootstrap%20-%20Pvalue.pdf
data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # bootstrap should be set to 2000 or 5000 in real studies logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) summary(logistic_beta_x)
data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # bootstrap should be set to 2000 or 5000 in real studies logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) summary(logistic_beta_x)
The summary
method
for lm_betaselect
-class objects.
## S3 method for class 'lm_betaselect' summary( object, correlation = FALSE, symbolic.cor = FALSE, se_method = c("boot", "bootstrap", "t", "lm", "ls"), ci = TRUE, level = 0.95, boot_type = c("perc", "bc"), boot_pvalue_type = c("asymmetric", "norm"), type = c("beta", "standardized", "raw", "unstandardized"), print_raw = c("none", "before_ci", "after_ci"), ... ) ## S3 method for class 'summary.lm_betaselect' print( x, est_digits = 3, symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), tz_digits = 3, pvalue_less_than = 0.001, ... )
## S3 method for class 'lm_betaselect' summary( object, correlation = FALSE, symbolic.cor = FALSE, se_method = c("boot", "bootstrap", "t", "lm", "ls"), ci = TRUE, level = 0.95, boot_type = c("perc", "bc"), boot_pvalue_type = c("asymmetric", "norm"), type = c("beta", "standardized", "raw", "unstandardized"), print_raw = c("none", "before_ci", "after_ci"), ... ) ## S3 method for class 'summary.lm_betaselect' print( x, est_digits = 3, symbolic.cor = x$symbolic.cor, signif.stars = getOption("show.signif.stars"), tz_digits = 3, pvalue_less_than = 0.001, ... )
object |
The output of
|
correlation |
If |
symbolic.cor |
If |
se_method |
The method used to
compute the standard errors and
confidence intervals (if requested).
If bootstrapping was
requested when calling
|
ci |
Logical. Whether
confidence intervals are computed.
Default is |
level |
The level of confidence, default is .95, returning the 95% confidence interval. |
boot_type |
The type of
bootstrap confidence intervals,
if requested.
Currently, it supports |
boot_pvalue_type |
The type
of p-values if |
type |
String. If
|
print_raw |
Control whether
the estimates before selected
standardization are printed when
|
... |
Additional arguments passed to other methods. |
x |
The output of
|
est_digits |
The number of
digits after the decimal to be
displayed for the coefficient
estimates, their standard errors, and
confidence intervals (if present).
Note that the values will be rounded
to this number of digits before
printing. If all digits at this
position are zero for all values, the
values may be displayed with fewer
digits. Note that the coefficient
table is printed by
|
signif.stars |
Whether "stars"
(asterisks) are printed to denote
the level of significance achieved
for each coefficient. Default is
|
tz_digits |
The number of digits
after the decimal to be displayed for
the t or similar statistic (in the
column |
pvalue_less_than |
If a
p-value is less than this value, it
will be displayed with |
By default, it returns a
summary.lm_betaselect
-class object
for the results with selected variables
standardized. By setting type
to
"raw"
or "unstandardized"
, it
return the summary for the results
before standardization.
The print
method of
summary.lm_betaselect
-class objects
is adapted from
stdmod::print.summary.std_selected()
.
It returns an object of class
summary.lm_betaselect
, which is
similar to the output of
stats::summary.lm()
, with additional
information on the standardization
and bootstrapping, if requested.
The print
-method of
summary.lm_betaselect
is called
for its side effect. The object x
is returned invisibly.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
Asparouhov, A., & Muthén, B. (2021). Bootstrap p-value computation. Retrieved from https://www.statmodel.com/download/FAQ-Bootstrap%20-%20Pvalue.pdf
data(data_test_mod_cat) # bootstrap should be set to 2000 or 5000 in real studies lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) summary(lm_beta_x) summary(lm_beta_x, ci = TRUE) summary(lm_beta_x, boot_pvalue_type = "norm") summary(lm_beta_x, type = "raw")
data(data_test_mod_cat) # bootstrap should be set to 2000 or 5000 in real studies lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) summary(lm_beta_x) summary(lm_beta_x, ci = TRUE) summary(lm_beta_x, boot_pvalue_type = "norm") summary(lm_beta_x, type = "raw")
glm_betaselect
ObjectsCompute the
variance-covariance matrix of
estimates in the output of
lm_betaselect()
or
glm_betaselect()
.
## S3 method for class 'lm_betaselect' vcov( object, method = c("boot", "bootstrap", "ls", "default"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, ... ) ## S3 method for class 'glm_betaselect' vcov( object, method = c("boot", "bootstrap", "ls", "default"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, ... )
## S3 method for class 'lm_betaselect' vcov( object, method = c("boot", "bootstrap", "ls", "default"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, ... ) ## S3 method for class 'glm_betaselect' vcov( object, method = c("boot", "bootstrap", "ls", "default"), type = c("beta", "standardized", "raw", "unstandardized"), warn = TRUE, ... )
object |
The output of
|
method |
The method used to
compute the variance-covariance
matrix. If bootstrapping was
requested when calling
|
type |
String. If
|
warn |
Logical. WHether a warning
will be raised is OLS (or WLS)
variance-covariance matrix is
requested for the model with some
variables standardized (i.e., |
... |
Other arguments to be
passed to |
The type of variance-covariance matrix depends on the object. If bootstrapping was requested, by default it returns the bootstrap variance-covariance matrix. Otherwise, it returns the default variance-covariance matrix and raises a warning.
Support for other type of variance-covariance matrix will be added.
A matrix of the variances and covariances of the parameter estimates.
Shu Fai Cheung https://orcid.org/0000-0002-9871-9448
lm_betaselect()
and
glm_betaselect()
data(data_test_mod_cat) # bootstrap should be set to 2000 or 5000 in real studies lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) vcov(lm_beta_x) # A warning is expected for the following call vcov(lm_beta_x, method = "ls") vcov(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # bootstrap should be set to 2000 or 5000 in real studies logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) vcov(logistic_beta_x) # A warning is expected for the following call vcov(logistic_beta_x, method = "default") vcov(logistic_beta_x, type = "raw")
data(data_test_mod_cat) # bootstrap should be set to 2000 or 5000 in real studies lm_beta_x <- lm_betaselect(dv ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) vcov(lm_beta_x) # A warning is expected for the following call vcov(lm_beta_x, method = "ls") vcov(lm_beta_x, type = "raw") data_test_mod_cat$p <- scale(data_test_mod_cat$dv)[, 1] data_test_mod_cat$p <- ifelse(data_test_mod_cat$p > 0, yes = 1, no = 0) # bootstrap should be set to 2000 or 5000 in real studies logistic_beta_x <- glm_betaselect(p ~ iv*mod + cov1 + cat1, data = data_test_mod_cat, family = binomial, to_standardize = "iv", do_boot = TRUE, bootstrap = 100, iseed = 1234) vcov(logistic_beta_x) # A warning is expected for the following call vcov(logistic_beta_x, method = "default") vcov(logistic_beta_x, type = "raw")