semPower.genSigma: semPower.genSigma

View source: R/helperFunctions.R

semPower.genSigmaR Documentation

semPower.genSigma

Description

Generate a covariance matrix (and a mean vector) and associated lavaan model strings based on CFA or SEM model matrices.

Usage

semPower.genSigma(
  Lambda = NULL,
  Phi = NULL,
  Beta = NULL,
  Psi = NULL,
  Theta = NULL,
  tau = NULL,
  Alpha = NULL,
  ...
)

Arguments

Lambda

factor loading matrix. A list for multiple group models. Can also be specified using various shortcuts, see genLambda().

Phi

for CFA models, factor correlation (or covariance) matrix or single number giving the correlation between all factors or NULL for uncorrelated factors. A list for multiple group models.

Beta

for SEM models, matrix of regression slopes between latent variables (all-y notation). A list for multiple group models.

Psi

for SEM models, variance-covariance matrix of latent residuals when Beta is specified. If NULL, a diagonal matrix is assumed. A list for multiple group models.

Theta

variance-covariance matrix between manifest residuals. If NULL and Lambda is not a square matrix, Theta is diagonal so that the manifest variances are 1. If NULL and Lambda is square, Theta is 0. A list for multiple group models.

tau

vector of intercepts. If NULL and Alpha is set, these are assumed to be zero. If both Alpha and tau are NULL, no means are returned. A list for multiple group models.

Alpha

vector of factor means. If NULL and tau is set, these are assumed to be zero. If both Alpha and tau are NULL, no means are returned. A list for multiple group models.

...

other

Details

This function generates the variance-covariance matrix of the p observed variables \Sigma and their means \mu via a confirmatory factor (CFA) model or a more general structural equation model.

In the CFA model,

\Sigma = \Lambda \Phi \Lambda' + \Theta

where \Lambda is the p \cdot m loading matrix, \Phi is the variance-covariance matrix of the m factors, and \Theta is the residual variance-covariance matrix of the observed variables. The means are

\mu = \tau + \Lambda \alpha

with the p indicator intercepts \tau and the m factor means \alpha.

In the structural equation model,

\Sigma = \Lambda (I - B)^{-1} \Psi [(I - B)^{-1}]' \Lambda' + \Theta

where B is the m \cdot m matrix containing the regression slopes and \Psi is the (residual) variance-covariance matrix of the m factors. The means are

\mu = \tau + \Lambda (I - B)^{-1} \alpha

In either model, the meanstructure can be omitted, leading to factors with zero means and zero intercepts.

When \Lambda = I, the models above do not contain any factors and reduce to ordinary regression or path models.

If Phi is defined, a CFA model is used, if Beta is defined, a structural equation model. When both Phi and Beta are NULL, a CFA model is used with \Phi = I, i. e., uncorrelated factors. When Phi is a single number, all factor correlations are equal to this number.

When Beta is defined and Psi is NULL, \Psi = I.

When Theta is NULL, \Theta is a diagonal matrix with all elements such that the variances of the observed variables are 1. When there is only a single observed indicator for a factor, the corresponding element in \Theta is set to zero.

Instead of providing the loading matrix \Lambda via Lambda, there are several shortcuts (see genLambda()):

  • loadings: defines the primary loadings for each factor in a list structure, e. g. loadings = list(c(.5, .4, .6), c(.8, .6, .6, .4)) defines a two factor model with three indicators loading on the first factor by .5, , 4., and .6, and four indicators loading in the second factor by .8, .6, .6, and .4.

  • nIndicator: used in conjunction with loadM or loadMinmax, defines the number of indicators by factor, e. g., nIndicator = c(3, 4) defines a two factor model with three and four indicators for the first and second factor, respectively. nIndicator can also be a single number to define the same number of indicators for each factor.

  • loadM: defines the mean loading either for all indicators (if a single number is provided) or separately for each factor (if a vector is provided), e. g. loadM = c(.5, .6) defines the mean loadings of the first factor to equal .5 and those of the second factor do equal .6

  • loadSD: used in conjunction with loadM, defines the standard deviations of the loadings. If omitted or NULL, the standard deviations are zero. Otherwise, the loadings are sampled from a normal distribution with N(loadM, loadSD) for each factor.

  • loadMinMax: defines the minimum and maximum loading either for all factors or separately for each factor (as a list). The loadings are then sampled from a uniform distribution. For example, loadMinMax = list(c(.4, .6), c(.4, .8)) defines the loadings for the first factor lying between .4 and .6, and those for the second factor between .4 and .8.

Value

Returns a list (or list of lists for multiple group models) containing the following components:

Sigma

implied variance-covariance matrix.

mu

implied means

Lambda

loading matrix

Phi

covariance matrix of latent variables

Beta

matrix of regression slopes

Psi

residual covariance matrix of latent variables

Theta

residual covariance matrix of observed variables

tau

intercepts

Alpha

factor means

modelPop

lavaan model string defining the population model

modelTrue

lavaan model string defining the "true" analysis model freely estimating all non-zero parameters.

modelTrueCFA

lavaan model string defining a model similar to modelTrue, but purely CFA based and thus omitting any regression relationships.

Examples

## Not run: 
# single factor model with five indicators each loading by .5
gen <- semPower.genSigma(nIndicator = 5, loadM = .5)
gen$Sigma     # implied covariance matrix
gen$modelTrue # analysis model string
gen$modelPop  # population model string

# orthogonal two factor model with four and five indicators each loading by .5
gen <- semPower.genSigma(nIndicator = c(4, 5), loadM = .5)

# correlated (r = .25) two factor model with 
# four indicators loading by .7 on the first factor 
# and five indicators loading by .6 on the second factor
gen <- semPower.genSigma(Phi = .25, nIndicator = c(4, 5), loadM = c(.7, .6))

# correlated three factor model with variying indicators and loadings, 
# factor correlations according to Phi
Phi <- matrix(c(
  c(1.0, 0.2, 0.5),
  c(0.2, 1.0, 0.3),
  c(0.5, 0.3, 1.0)
), byrow = TRUE, ncol = 3)
gen <- semPower.genSigma(Phi = Phi, nIndicator = c(3, 4, 5), 
                         loadM = c(.7, .6, .5))

# same as above, but using a factor loadings matrix
Lambda <- matrix(c(
  c(0.8, 0.0, 0.0),
  c(0.7, 0.0, 0.0),
  c(0.6, 0.0, 0.0),
  c(0.0, 0.7, 0.0),
  c(0.0, 0.8, 0.0),
  c(0.0, 0.5, 0.0),
  c(0.0, 0.4, 0.0),
  c(0.0, 0.0, 0.5),
  c(0.0, 0.0, 0.4),
  c(0.0, 0.0, 0.6),
  c(0.0, 0.0, 0.4),
  c(0.0, 0.0, 0.5)
), byrow = TRUE, ncol = 3)
gen <- semPower.genSigma(Phi = Phi, Lambda = Lambda)

# same as above, but using a reduced loading matrix, i. e.
# only define the primary loadings for each factor
loadings <- list(
  c(0.8, 0.7, 0.6),
  c(0.7, 0.8, 0.5, 0.4),
  c(0.5, 0.4, 0.6, 0.4, 0.5)
)
gen <- semPower.genSigma(Phi = Phi, loadings = loadings)

# Provide Beta for a three factor model
# with 3, 4, and 5 indicators 
# loading by .6, 5, and .4, respectively.
Beta <- matrix(c(
                c(0.0, 0.0, 0.0),
                c(0.3, 0.0, 0.0),  # f2 = .3*f1
                c(0.2, 0.4, 0.0)   # f3 = .2*f1 + .4*f2
               ), byrow = TRUE, ncol = 3)
gen <- semPower.genSigma(Beta = Beta, nIndicator = c(3, 4, 5), 
                         loadM = c(.6, .5, .4))

# two group example: 
# correlated two factor model (r = .25 and .35 in the first and second group, 
# respectively)
# the first factor is indicated by four indicators loading by .7 in the first 
# and .5 in the second group,
# the second factor is indicated by five indicators loading by .6 in the first 
# and .8 in the second group,
# all item intercepts are zero in both groups, 
# the latent means are zero in the first group
# and .25 and .10 in the second group.
gen <- semPower.genSigma(Phi = list(.25, .35), 
                         nIndicator = list(c(4, 5), c(4, 5)), 
                         loadM = list(c(.7, .6), c(.5, .8)), 
                         tau = list(rep(0, 9), rep(0, 9)), 
                         Alpha = list(c(0, 0), c(.25, .10))
                         )
gen[[1]]$Sigma  # implied covariance matrix group 1 
gen[[2]]$Sigma  # implied covariance matrix group 2
gen[[1]]$mu     # implied means group 1 
gen[[2]]$mu     # implied means group 2

## End(Not run)

semPower documentation built on Nov. 15, 2023, 1:08 a.m.