Processing math: 100%

This function makes it easy to write the Mplus syntax for various residual covariance structure.

mplusRcov(
  x,
  type = c("homogenous", "heterogenous", "cs", "toeplitz", "ar", "un"),
  r = "rho",
  e = "e",
  collapse = FALSE
)

Arguments

x

input character vector of variable names, ordered by time

type

A character string indicating the type of residual covariance structure to be used. Defaults to ‘homogenous’. Current options include ‘homogenous’, ‘heterogenous’, ‘cs’ for compound symmetric, ‘toeplitz’ for banded toeplitz, ‘ar’ for autoregressive, and ‘un’ for unstructured.

r

a character vector of the base label to name covariance parameters. Defaults to ‘rho’.

e

a character vector of the error variance of the variable. Used to create constraints on the covariance parameters. Defaults to ‘e’.

collapse

whether to collapse the covariance code using ‘PWITH’. Note that at the time of writing, Mplus does not allow more than 80 characters per row. Defaults to FALSE.

Value

A named character vector of class ‘MplusRstructure’ with four elements:

all

A character string collapsing all other sections.

Variances

A character string containing all of the variances.

Covariances

A character string containing all of the covariances, properly labelled to allow constraints and the autoregressive residual covariance structure.

Constraints

A character string containing the ‘MODEL CONSTRAINT’ section and code needed to parameterize the residual covariance structure as autoregressive.

Details

The homogenous residual covariance structure estimates one parameter: the residual variance, σ2e. The residual variance is assumed to be identical for all variables and all covariances are assumed to be zero. The structure is represented in this table.

t1t2t3...tn
t1σ2e...
t20σ2e...
t300σ2e...
..................
tn000...σ2e

The heterogenous residual covariance structure estimates n parameters, where n is the number of variables. A unique residual variance is estimated for every variable. All covariances are assumed to be zero. The structure is represented in this table.

t1t2t3...tn
t1σ2e1...
t20σ2e2...
t300σ2e3...
..................
tn000...σ2en

The compound symmetric residual covariance structure estimates two parameters: one for the residual variance , σ2e, and one for the covariance. The residual variance is assumed to be identical for all variables and all covariances are assumed to be identical. The structure is represented in this table.

t1t2t3...tn
t1σ2e...
t2ρσ2e...
t3ρρσ2e...
..................
tnρρρ...σ2e

The toeplitz residual covariance structure estimates n parameters, one for every band of the matrix. The residual variance , σ2e, is assumed to be identical for all variables. The covariances one step removed are all assumed identical. Likewise for all further bands. The structure is represented in this table.

t1t2t3...tn
t1σ2e...
t2ρσ2e...
t3ρ2ρσ2e...
..................
tnρnρn1ρn2...σ2e

The autoregressive residual covariance structure has two parameters: the residual variance, σ2e and the correlation between adjacent time points, ρ. The variances are constrained to be equal for all time points. A single correlation parameter is estimated. The ρ is the correlation between adjacent time points such as 1 and 2 or 2 and 3. More distant relationships are assumed to have smaller correlations, decreasing exponentially. Thus between 1 and 3, the estimate is ρ2. The structure is represented in this table.

t1t2t3...tn
t1σ2e...
t2ρσ2e...
t3ρ2ρσ2e...
..................
tnρn1ρn2ρn3...σ2e

Because structural equation models generally model covariance structures, the autoregressive residual structure must be parameterized in terms of covariances. This is done in two parts. First, the function returns syntax to estimate all the pairwise covariances, labelling the parameters ρ, ρ2, etc. so that they are constrained to be equal. Next, it returns the syntax for the necessary model constraints to constrain the different covariances, to decrease exponentially in their correlations. This is done via: ρ2=(ρσ2e)2σ2e and likewise for all later time points.

The unstructured residual covariance structure estimates n(n+1)2 parameters. It is unstructured in that every variance and covariance is freely estimated with no constraints. However, in most cases, this results in an overparameterized model and is unestimable. The structure is represented in this table.

t1t2t3...tn
t1σ2e1...
t2ρ1σ2e2...
t3ρ2ρ3σ2e3...
..................
tnρ5ρ6ρ7...σ2en

Author

Joshua F. Wiley <jwiley.psych@gmail.com>

Examples

# all five structures collapsing mplusRcov(letters[1:4], "homogenous", "rho", "e", TRUE)
#> a b c d (e); #> a WITH b@0 c@0 d@0; #> b WITH c@0 d@0; #> c WITH d@0; #>
mplusRcov(letters[1:4], "heterogenous", "rho", "e", TRUE)
#> a b c d; #> a WITH b@0 c@0 d@0; #> b WITH c@0 d@0; #> c WITH d@0; #>
mplusRcov(letters[1:4], "cs", "rho", "e", TRUE)
#> a b c d (e); #> a b c PWITH b c d (rho); #> a b PWITH c d (rho); #> a PWITH d (rho); #>
mplusRcov(letters[1:4], "toeplitz", "rho", "e", TRUE)
#> a b c d (e); #> a b c PWITH b c d (rho); #> a b PWITH c d (rho2); #> a PWITH d (rho3); #>
mplusRcov(letters[1:4], "ar", "rho", "e", TRUE)
#> a b c d (e); #> a b c PWITH b c d (rho); #> a b PWITH c d (rho2); #> a PWITH d (rho3); #> MODEL CONSTRAINT: #> rho2 = ((rho/e)^2) * e; #> rho3 = ((rho/e)^3) * e; #>
mplusRcov(letters[1:4], "un", "rho", "e", TRUE)
#> a b c d; #> a WITH b c d; #> b WITH c d; #> c WITH d; #>
# all five structures without collapsing # useful for long names or many variables # where a line may cross 80 characters mplusRcov(letters[1:4], "homogenous", "rho", "e", FALSE)
#> a b c d (e); #> a WITH b@0; #> a WITH c@0; #> a WITH d@0; #> b WITH c@0; #> b WITH d@0; #> c WITH d@0; #>
mplusRcov(letters[1:4], "heterogenous", "rho", "e", FALSE)
#> a b c d; #> a WITH b@0; #> a WITH c@0; #> a WITH d@0; #> b WITH c@0; #> b WITH d@0; #> c WITH d@0; #>
mplusRcov(letters[1:4], "cs", "rho", "e", FALSE)
#> a b c d (e); #> a WITH b (rho); #> b WITH c (rho); #> c WITH d (rho); #> a WITH c (rho); #> b WITH d (rho); #> a WITH d (rho); #>
mplusRcov(letters[1:4], "toeplitz", "rho", "e", FALSE)
#> a b c d (e); #> a WITH b (rho); #> b WITH c (rho); #> c WITH d (rho); #> a WITH c (rho2); #> b WITH d (rho2); #> a WITH d (rho3); #>
mplusRcov(letters[1:4], "ar", "rho", "e", FALSE)
#> a b c d (e); #> a WITH b (rho); #> b WITH c (rho); #> c WITH d (rho); #> a WITH c (rho2); #> b WITH d (rho2); #> a WITH d (rho3); #> MODEL CONSTRAINT: #> rho2 = ((rho/e)^2) * e; #> rho3 = ((rho/e)^3) * e; #>
mplusRcov(letters[1:4], "un", "rho", "e", FALSE)
#> a b c d; #> a WITH b; #> a WITH c; #> a WITH d; #> b WITH c; #> b WITH d; #> c WITH d; #>