bind: Specify matrices for Monte Carlo simulation of structural...

Description Usage Arguments Details Value Author(s) See Also Examples

View source: R/bind.R

Description

Create SimMatrix or SimVector object that specifies

  1. Pattern of fixed/freed parameters for analysis

  2. Population parameter values for data generation

  3. Any model misspecification (true population parameter is different than the one specified) for these parameters.

Each matrix in the Lisrel-style notation is specified in this way (e.g. LY, PS, and TE) and is used to create a model analysis template and a data generation template for simulation through the model function.

Usage

1
2
bind(free = NULL, popParam = NULL, misspec = NULL, symmetric = FALSE)
binds(free = NULL, popParam = NULL, misspec = NULL, symmetric = TRUE)

Arguments

free

Required matrix or vector where each element represents a fixed or freed parameter used for analysis with structural equation models. Parameters can be freed by setting the corresponding element in the matrix to NA, and can be fixed by setting the value of the element to any number (e.g. 0). Parameters can be labeled using any character string. Any labeled parameter is considered to be free, and parameters with identical labels will be constrained to equality for analysis.

popParam

Optional matrix or vector of identical dimension to the free matrix whose elements contain population parameter values for data generation in simulation. For simlutation, each free parameter requires a population parameter value, which is a quoted numeric value. Parameters that don't have population values are left as empty strings. Population parameters can also be drawn from a distribution. This is done by wrapping a call to create 1 value from an existing random generation function in quotes: e.g "runif(1,0,1)","rnorm(1,0,.01)" Every replication in the simulation will draw a parameter value from this distribution. The function checks that what is quoted is valid R.

If a random population parameter is constrained to equality in the free matrix, each drawn population parameter value will be the same. More details on data generation is available in ?generate, ?createData, and ?draw.

To simplify the most common case, popParam can take 1 value or distribution and create a matrix or vector that assigns that population parameter or distribution to all freed parameters. These population values are used as starting values for analysis by default.

misspec

Optional matrix or vector of identical dimension to the free matrix whose elements contain population parameter values for specifying misspecification. Elements of the misspec matrix contain population parameters that are added to parameters that are fixed or have an existing population value. These parameters are also quoted numeric strings, and can optionally be drawn from distributions as described above. To simplify the most common case, misspec can take 1 value or distribution and create a matrix or vector that assigns that value or distribution to all previously specified fixed parameters. Details about misspecification are included the data generation functions.

symmetric

Set as TRUE if the matrix created is symmetric (RPS/PS, RTE/TE). The function binds can also be used, which defaults to symmetric = TRUE

Details

Bind is the first step in the bind -> model -> sim workflow of simsem, and this document outlines the user interface or language used to describe these simulations. This interface, while complex, enables a wide array of simulation specifications for structural equation models by building on LISREL-style parameter specifications.

In simulations supported by simsem, a given parameter may be either fixed or freed for analysis, but may optionally also have a population value or distribution for data generation, or a value or distribution of misspecification. The purpose of bind is to stack these multiple meanings of a parameter into an object recognized by simsem, a SimMatrix. Each matrix in the Lisrel notation (e.g. LY, PS, TE, BE) becomes a SimMatrix, and is passed to the function model, which builds the data generation template and an analysis template (a lavaan parameter table), collectively forming a SimSem object, which can be passed to the function sim for simulation.

Note that any (dim)names attributes will be set to NULL for any vectors or matrices passed to free, popParam, or misspec in order to prevent errors elsewhere in the workflow. To set custom variable names, please use any of the indLab, facLab, covLab, or groupLab arguments to model().

Value

SimMatrix or SimVector object that used for model specification for analysis and data generation in simsem.

Author(s)

Patrick Miller (University of Notre Dame; pmille13@nd.edu), Sunthud Pornprasertmanit (psunthud@gmail.com)

See Also

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
loading <- matrix(0, 6, 2)
loading[1:3, 1] <- NA
loading[4:6, 2] <- NA
loadingValues <- matrix(0, 6, 2)
loadingValues[1:3, 1] <- 0.7
loadingValues[4:6, 2] <- 0.7
LY <- bind(loading, loadingValues)
summary(LY)

# Set both factor correlations to .05
latent.cor <- matrix(NA, 2, 2)
diag(latent.cor) <- 1
RPS <- binds(latent.cor, 0.5)

# Misspecify all error covarainces
error.cor <- matrix(0, 6, 6)
diag(error.cor) <- NA
RTE <- binds(error.cor,1,"runif(1,-.05,.05)")

Example output

Loading required package: lavaan
This is lavaan 0.5-23.1097
lavaan is BETA software! Please report any bugs.
 
###############################################################################################
This is simsem 0.5-13
simsem is BETA software! Please report any bugs.
simsem was developed at the University of Kansas Center for Research Methods and Data Analysis.
###############################################################################################
[1] "Random Full Matrix Object."
[1] "Free/Fixed Parameters:"
     [,1] [,2]
[1,]   NA    0
[2,]   NA    0
[3,]   NA    0
[4,]    0   NA
[5,]    0   NA
[6,]    0   NA
[1] "Population Parameters/Starting Values:"
     [,1]  [,2] 
[1,] "0.7" ""   
[2,] "0.7" ""   
[3,] "0.7" ""   
[4,] ""    "0.7"
[5,] ""    "0.7"
[6,] ""    "0.7"
[1] "Model misspecification"
     [,1]
[1,]  NaN
[1] "Symmetric: FALSE"

simsem documentation built on March 29, 2021, 1:07 a.m.

Related to bind in simsem...