Learn R Programming

matrixpls (version 1.0.13)

matrixpls.sim: Monte Carlo simulations with matrixpls

Description

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.

Usage

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
)

Arguments

nRep

Number of replications. If any of the n, pmMCAR, or pmMAR arguments are specified as lists, the number of replications will default to the length of the list(s), and nRep need not be specified.

model

There are two options for this argument: 1. lavaan script or lavaan parameter table, or 2. a list containing three matrices inner, reflective, and formative defining the free regression paths in the model.

n

Sample size(s). In single-group models, either a single integer, or a vector of integers to vary sample size across replications. In multigroup models, either a list of single integers (for constant group sizes across replications) or a list of vectors (to vary group sizes across replications). Any non-integers will be rounded.

...

All other arguments are passed through to sim, matrixpls.boot, or matrixpls.

cilevel

Confidence level. This argument will be forwarded to the boot.ci when calculating the confidence intervals.

citype

Type of confidence interval. This argument will be forwarded to the boot.ci when calculating the confidence intervals.

boot.R

Number of bootstrap replications to use to estimate standard errors or FALSE to disable bootstrapping.

fitIndices

A function that returns a list of fit indices for the model. Setting this argument to NULL disables fit indices.

outfundata

A function to be applied to the matrixpls output and the generated data after each replication. Users can get the characteristics of the generated data and also compare the characteristics with the generated output. The output from this function in each replication will be saved in the simulation output (SimResult), and can be obtained using the getExtraOutput function.

outfun

A function to be applied to the matrixpls output at each replication. Output from this function in each replication will be saved in the simulation output (SimResult), and can be obtained using the getExtraOutput function.

prefun

A function to be applied to the dataset before each replication. The output of this function is passed as arguments to matrixpls

Value

An object of class SimResult-class.

Details

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.

See Also

matrixpls, matrixpls.boot, sim, SimResult-class

Examples

Run this code
# NOT RUN {
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)


}
# }

Run the code above in your browser using DataLab