Skip to contents

Calculates Monte Carlo confidence intervals for free and defined parameters.

Usage

MC(
  object,
  R = 20000L,
  alpha = c(0.001, 0.01, 0.05),
  decomposition = "eigen",
  pd = TRUE,
  tol = 1e-06
)

Arguments

object

object of class lavaan.

R

Positive integer. Number of Monte Carlo replications.

alpha

Numeric vector. Significance level \(\alpha\).

decomposition

Character string. Matrix decomposition of the sampling variance-covariance matrix for the data generation. If decomposition = "chol", use Cholesky decomposition. If decomposition = "eigen", use eigenvalue decomposition. If decomposition = "svd", use singular value decomposition.

pd

Logical. If pd = TRUE, check if the sampling variance-covariance matrix is positive definite using tol.

tol

Numeric. Tolerance used for pd.

Value

Returns an object of class semmcci

which is a list with the following elements:

R

Number of Monte Carlo replications.

alpha

Significance level \(\alpha\) specified.

lavaan

lavaan object.

decomposition

Matrix decomposition used to generate multivariate normal random variates.

thetahat

Parameter estimates \(\hat{\theta}\).

thetahatstar

Sampling distribution of parameter estimates \(\hat{\theta}^{\ast}\).

Details

A sampling distribution of parameter estimates is generated from the multivariate normal distribution using the parameter estimates and the sampling variance-covariance matrix. Confidence intervals for free and defined parameters are generated using the simulated sampling distribution. Parameters can be defined using the := operator in the lavaan model syntax.

Author

Ivan Jacob Agaloos Pesigan

Examples

library(semmcci)
library(lavaan)
#> This is lavaan 0.6-14
#> lavaan is FREE software! Please report any bugs.

# Generate Data ------------------------------------------------------------
n <- 1000
a <- 0.50
b <- 0.50
cp <- 0.25
s2_em <- 1 - a^2
s2_ey <- 1 - cp^2 - a^2 * b^2 - b^2 * s2_em - 2 * cp * a * b
em <- rnorm(n = n, mean = 0, sd = sqrt(s2_em))
ey <- rnorm(n = n, mean = 0, sd = sqrt(s2_ey))
X <- rnorm(n = n)
M <- a * X + em
Y <- cp * X + b * M + ey
df <- data.frame(X, M, Y)

# Fit Model in lavaan ------------------------------------------------------
model <- "
  Y ~ cp * X + b * M
  M ~ a * X
  indirect := a * b
  direct := cp
  total := cp + (a * b)
"
fit <- sem(data = df, model = model)

# Monte Carlo --------------------------------------------------------------
MC(
  fit,
  R = 100L, # use a large value e.g., 20000L for actual research
  alpha = c(0.001, 0.01, 0.05)
)
#> Monte Carlo Confidence Intervals
#>             est     se   R  0.05%   0.5%   2.5%  97.5%  99.5% 99.95%
#> cp       0.2789 0.0291 100 0.2054 0.2086 0.2190 0.3279 0.3356 0.3360
#> b        0.4693 0.0271 100 0.3990 0.4009 0.4144 0.5200 0.5326 0.5348
#> a        0.4762 0.0246 100 0.4254 0.4270 0.4323 0.5276 0.5349 0.5400
#> Y~~Y     0.5375 0.0230 100 0.4864 0.4870 0.4927 0.5844 0.5969 0.6013
#> M~~M     0.7338 0.0334 100 0.6444 0.6542 0.6698 0.7860 0.7895 0.7907
#> indirect 0.2235 0.0173 100 0.1879 0.1896 0.1951 0.2601 0.2634 0.2635
#> direct   0.2789 0.0291 100 0.2054 0.2086 0.2190 0.3279 0.3356 0.3360
#> total    0.5024 0.0272 100 0.4378 0.4384 0.4458 0.5590 0.5650 0.5653