View source: R/matrixpls.sim.R
matrixpls.sim | R Documentation |
Performs Monte Carlo simulations of matrixpls
with the sim
function of the simsem
package.
The standard errors and confidence intervals are estimated with the boot
and boot.ci
functions
of the boot
package.
matrixpls.sim(
nRep = NULL,
model = NULL,
n = NULL,
...,
cilevel = 0.95,
citype = c("norm", "basic", "stud", "perc", "bca"),
boot.R = 500,
fitIndices = fitSummary,
outfundata = NULL,
outfun = NULL,
prefun = NULL
)
nRep |
Number of replications. If any of the |
model |
There are two options for this argument: 1. lavaan script or lavaan parameter
table, or 2. a list containing three matrices
|
n |
Sample size(s). In single-group models, either a single |
... |
All other arguments are passed through to |
cilevel |
Confidence level. This argument will be forwarded to the |
citype |
Type of confidence interval. This argument will be forwarded to the |
boot.R |
Number of bootstrap replications to use to estimate standard errors or |
fitIndices |
A function that returns a list of fit indices for the model. Setting this argument to |
outfundata |
A function to be applied to the |
outfun |
A function to be applied to the |
prefun |
A function to be applied to the dataset before each replication. The output of this
function is passed as arguments to |
This function calls the sim
function from the simsem
package to perform Monte
Carlo simulations with matrixpls. The function parses the model parameters and replaces it with
a function call that estimates the model and bootstrapped standard errors and confidence
intervals with matrixpls.boot.
If the generate
or rawdata
arguments are not specified in the sim
arguments
then the model
argument will be used for data generation and must be specified in lavaan format.
An object of class SimResult-class
.
matrixpls
, matrixpls.boot
, sim
, SimResult-class
if(!require(simsem)){
print("This example requires the simsem package")
} else{
#
# Runs the second model from
#
# Aguirre-Urreta, M., & Marakas, G. (2013). Partial Least Squares and Models with Formatively
# Specified Endogenous Constructs: A Cautionary Note. Information Systems Research.
# doi:10.1287/isre.2013.0493
library(MASS)
X <- diag(15)
X[upper.tri(X, diag=TRUE)] <- c(
1.000,
0.640, 1.000,
0.640, 0.640, 1.000,
0.640, 0.640, 0.640, 1.000,
0.096, 0.096, 0.096, 0.096, 1.000,
0.096, 0.096, 0.096, 0.096, 0.640, 1.000,
0.096, 0.096, 0.096, 0.096, 0.640, 0.640, 1.000,
0.096, 0.096, 0.096, 0.096, 0.640, 0.640, 0.640, 1.000,
0.115, 0.115, 0.115, 0.115, 0.192, 0.192, 0.192, 0.192, 1.000,
0.115, 0.115, 0.115, 0.115, 0.192, 0.192, 0.192, 0.192, 0.640, 1.000,
0.115, 0.115, 0.115, 0.115, 0.192, 0.192, 0.192, 0.192, 0.640, 0.640,
1.000,
0.115, 0.115, 0.115, 0.115, 0.192, 0.192, 0.192, 0.192, 0.640, 0.640,
0.640, 1.000,
0.000, 0.000, 0.000, 0.000, 0.271, 0.271, 0.271, 0.271, 0.325, 0.325,
0.325, 0.325, 1.000,
0.000, 0.000, 0.000, 0.000, 0.271, 0.271, 0.271, 0.271, 0.325, 0.325,
0.325, 0.325, 0.300, 1.000,
0.000, 0.000, 0.000, 0.000, 0.271, 0.271, 0.271, 0.271, 0.325, 0.325,
0.325, 0.325, 0.300, 0.300, 1.000
)
X <- X + t(X) - diag(diag(X))
colnames(X) <- rownames(X) <- c(paste("Y",1:12,sep=""),paste("X",1:3,sep=""))
# Print the population covariance matrix X to see that it is correct
X
# The estimated model in Lavaan syntax
analyzeModel <- "
ksi =~ Y1 + Y2 + Y3 + Y4
eta1 <~ X1 + X2 + X3
eta2 =~ Y5 + Y6 + Y7 + Y8
eta3 =~ Y9 + Y10 + Y11 + Y12
eta1 ~ ksi
eta2 ~ eta1
eta3 ~ eta1
"
# Only run 100 replications without bootstrap replications each so that the
# example runs faster. Generate the data outside simsem because simsem
# does not support drawing samples from population matrix
dataSets <- lapply(1:100, function(x){
mvrnorm(300, # Sample size
rep(0,15), # Means
X) # Population covarancematrix
})
Output <- matrixpls.sim(model = analyzeModel, rawData = dataSets, boot.R=FALSE,
multicore = FALSE, stopOnError = TRUE)
summary(Output)
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.