WebPower (version 0.5)

wp.mc.sem.power.curve: Statistical Power Curve for Structural Equation Modeling / Mediation based on Monte Carlo Simulation

Description

A power curve is useful to graphically display how power changes with sample size (e.g., Zhang & Wang). This function is to generate a power curve for SEM based on Monte Carlo simulation, either using Sobel test or bootstrap method to test the indirect / mediation effects if applicable.

Usage

wp.mc.sem.power.curve(model, indirect = NULL, nobs = 100, type = "basic",
  nrep = 1000, nboot = 1000, alpha = 0.95, skewness = NULL,
  kurtosis = NULL, ovnames = NULL, se = "default",
  estimator = "default", parallel = "no",
  ncore = Sys.getenv("NUMBER_OF_PROCESSORS"), cl = NULL, ...)

Arguments

model

Model specified using lavaan syntax. More about model specification can be found in Rosseel (2012).

indirect

Indirect effect difined using lavaan syntax.

nobs

Sample size. It is 100 by default.

type

The method used to test the indirect effects ('basic' or 'boot'). By default type='basic'. The type 'basic' is to use Sobel test (see also wp.mc.sem.basic), while 'boot' is to use bootstrap method (see also wp.mc.sem.boot).

nrep

Number of replications for the Monte Carlo simulation. It is 1000 by default.

nboot

Number of replications for the bootstrap to test the specified parameter (e.g., mediation). It is 1000 by default.

alpha

significance level chosed for the test. It equals 0.05 by default.

skewness

A sequence of skewnesses of the observed variables. It is not required.

kurtosis

A sequence of kurtosises of the observed variables. It is not required.

ovnames

Names of the observed variables in the model. It is not required.

se

The method for calculatating the standard errors. Its default method "default" is regular standard errors. More about methods specification standard errors calculatationcan be found in Rosseel (2012).

estimator

Estimator. It is Maxmum likelihood estimator by default. More about estimator specification can be found in Rosseel (2012).

parallel

Parallel computing ("no" or "parallel" or "snow"). It is "no" by default, which means it will not use parallel computing. The option "parallel" is to use multiple cores in a computer for parallel computing. It is used with the number of cores (ncore). The option "snow" is to use clusters for parallel computing. It is used with the number of clusters (cl).

ncore

Number of processors used for parallel computing. By default, ncore = Sys.getenv('NUMBER_OF_PROCESSORS').

cl

Number of clusters. It is NULL by default. When it is NULL, the program will detect the number of clusters automatically.

...

Extra arguments. It is not required.

Value

An object of the power analysis. The power for all parameters in the model as well as the indirect effects if specified.

References

Rosseel, Y. (2012). Lavaan: An R package for structural equation modeling and more. Version 0.5<U+2013>12 (BETA). Ghent, Belgium: Ghent University.

Thoemmes, F., MacKinnon, D. P., & Reiser, M. R. (2010). Power analysis for complex mediational designs using Monte Carlo methods. Structural Equation Modeling, 17(3), 510-534.

Zhang, Z., & Yuan, K.-H. (2018). Practical Statistical Power Analysis Using Webpower and R (Eds). Granger, IN: ISDSA Press.

Examples

Run this code
# NOT RUN {
#To specify the model
ex2model ="
		ept ~ start(0.4)*hvltt + b*hvltt + start(0)*age + start(0)*edu + start(2)*R
		hvltt ~ start(-0.35)*age + a*age +c*edu + start(0.5)*edu
		R ~ start(-0.06)*age + start(0.2)*edu
		R =~ 1*ws + start(0.8)*ls + start(0.5)*lt
		age ~~ start(30)*age
		edu ~~ start(8)*edu
		age ~~ start(-2.8)*edu
		hvltt ~~ start(23)*hvltt
		R ~~ start(14)*R
		ws ~~ start(3)*ws
		ls ~~ start(3)*ls
		lt ~~ start(3)*lt
		ept ~~ start(3)*ept
	"
#To specify the indirect effects
indirect = "ind1 := a*b + c*b" 
nobs <- seq(100, 2000, by =200)
#To calculate power curve:
power.curve = wp.mc.sem.power.curve(model=ex2model, indirect=indirect,
                              nobs=nobs, type='boot', parallel="muticore")
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace