MCStd Function Use Case 2: Difference of Standardized Regression Coefficients
Ivan Jacob Agaloos Pesigan
2024-10-22
Source:vignettes/mcstd-2-difference-regression-coefficients.Rmd
mcstd-2-difference-regression-coefficients.Rmd
The MCStd()
function is used to generate Monte Carlo
confidence intervals for differences between standardized regression
coefficients.
Data
In this example, we use data from Kwan & Chan (2011) where child’s reading ability () is regressed on parental occupational status (), parental educational level (), and child’s home possession ()
Note that is the stochastic error term with expected value of zero and finite variance , is the intercept, and , , and are regression coefficients.
#> Y1 X1 X2 X3
#> Y1 6088.8281 271.1429 49.5848 20.0337
#> X1 271.1429 226.2577 29.9232 4.8812
#> X2 49.5848 29.9232 9.0692 1.0312
#> X3 20.0337 4.8812 1.0312 0.8371
covs
#> Y1 X1 X2 X3
#> Y1 6088.8281 271.1429 49.5848 20.0337
#> X1 271.1429 226.2577 29.9232 4.8812
#> X2 49.5848 29.9232 9.0692 1.0312
#> X3 20.0337 4.8812 1.0312 0.8371
nobs
#> [1] 200
Model Specification
We regress Y1
on X1
, X2
, and
X3
. We label the regression coefficients as
gamma1
, gamma2
, and gamma3
. We
then specify the difference between the coefficients using the
:=
operator.
model <- "
Y1 ~ gamma1 * X1 + gamma2 * X2 + gamma3 * X3
gamma12 := gamma1 - gamma2
gamma13 := gamma1 - gamma3
gamma23 := gamma2 - gamma3
"
Model Fitting
We can now fit the model using the sem()
function from
lavaan
with mimic = "eqs"
to ensure
compatibility with results from Kwan & Chan
(2011).
Note: We recommend setting
fixed.x = FALSE
when generating standardized estimates and confidence intervals to model the variances and covariances of the exogenous observed variables if they are assumed to be random. Iffixed.x = TRUE
, which is the default setting inlavaan
,MC()
will fix the variances and the covariances of the exogenous observed variables to the sample values.
fit <- sem(
model = model, mimic = "eqs", fixed.x = FALSE,
sample.cov = covs, sample.nobs = nobs
)
Standardized Monte Carlo Confidence Intervals
Standardized Monte Carlo Confidence intervals can be generated by
passing the result of the MC()
function to the
MCStd()
function.
unstd <- MC(fit, R = 20000L, alpha = 0.05)
MCStd(unstd, alpha = 0.05)
#> Standardized Monte Carlo Confidence Intervals
#> est se R 2.5% 97.5%
#> gamma1 0.1207 0.0900 20000 -0.0586 0.2945
#> gamma2 0.0491 0.0913 20000 -0.1305 0.2278
#> gamma3 0.2194 0.0709 20000 0.0783 0.3565
#> Y1~~Y1 0.9002 0.0405 20000 0.8005 0.9575
#> X1~~X1 1.0000 0.0000 20000 1.0000 1.0000
#> X1~~X2 0.6606 0.0408 20000 0.5730 0.7340
#> X1~~X3 0.3547 0.0627 20000 0.2257 0.4719
#> X2~~X2 1.0000 0.0000 20000 1.0000 1.0000
#> X2~~X3 0.3743 0.0622 20000 0.2470 0.4900
#> X3~~X3 1.0000 0.0000 20000 1.0000 1.0000
#> gamma12 0.0716 0.1631 20000 -0.2471 0.3933
#> gamma13 -0.0987 0.1242 20000 -0.3414 0.1439
#> gamma23 -0.1703 0.1271 20000 -0.4165 0.0830