Eq2Expectations: Equations to Expectations

Description Usage Arguments Details Value Syntax Operations par.label Line breaks Comments Author(s) References See Also Examples

View source: R/Eq2Expectations.R

Description

Converts equations to expectations. The argument eq is a character string that specifies the associations between the variables. See Syntax, Operations, par.label, Line breaks, and Comments below.

Usage

1
2
3
4
5
6
7
8
Eq2Expectations(
  eq,
  par = FALSE,
  check = TRUE,
  R = FALSE,
  format = "ysym",
  simplify = FALSE
)

Arguments

eq

Character string. Equations. See Details.

par

Logical. If par = TRUE, use par.index as labels. If par = FALSE, use par.label as labels.

check

Logical. If check = TRUE do some preprocessing with input matrices using CheckRAMMatrices().

R

Logical. If R = TRUE, returns symbolic result as an R expression. If R = FALSE, returns symbolic result as "ysym", "str", or "tex" depending of format.

format

Character string. Only used when R = FALSE. If format = "ysym", returns symbolic result as yac_symbol. If format = "str", returns symbolic result as a characetr string. If format = "tex", returns symbolic result as LaTeX math.

simplify

Logical. Simplify symbolic results.

Details

The vector of expected values \mathbf{v} as a function of Reticular Action Model (RAM) matrices is given by

\mathbf{v} = ≤ft( \mathbf{I} - \mathbf{A} \right)^{\mathsf{T}} \mathbf{u} \\ = \mathbf{E} \mathbf{u}

The vector of expected values of observed variables \mathbf{g} as a function of Reticular Action Model (RAM) matrices is given by

\mathbf{g} = \mathbf{F} ≤ft( \mathbf{I} - \mathbf{A} \right)^{\mathsf{T}} \mathbf{u} \\ = \mathbf{F} \mathbf{E} \mathbf{u} \\ = \mathbf{F} \mathbf{v}

The matrix of covariance expectations \mathbf{C} as a function of Reticular Action Model (RAM) matrices is given by

\mathbf{C} = ≤ft( \mathbf{I} - \mathbf{A} \right)^{-1} \mathbf{S} ≤ft[ ≤ft( \mathbf{I} - \mathbf{A} \right)^{-1} \right]^{\mathsf{T}} \\ = \mathbf{E} \mathbf{S} \mathbf{E}^{\mathsf{T}}

The matrix of covariance expectations for given variables \mathbf{M} as a function of Reticular Action Model (RAM) matrices is given by

\mathbf{M} = \mathbf{F} ≤ft( \mathbf{I} - \mathbf{A} \right)^{-1} \mathbf{S} ≤ft[ ≤ft( \mathbf{I} - \mathbf{A} \right)^{-1} \right]^{\mathsf{T}} \mathbf{F}^{\mathsf{T}} \\ = \mathbf{F} \mathbf{E} \mathbf{S} \mathbf{E}^{\mathsf{T}} \mathbf{F}^{\mathsf{T}} \\ = \mathbf{F} \mathbf{C} \mathbf{F}^{\mathsf{T}}

The matrix of scaled/standardized covariance expectations \mathbf{C}_{\mathrm{scaled}} (also known as correlations) is given by

\mathbf{C}_{\mathrm{scaled}} = \mathbf{D}^{-1} \mathbf{C} \mathbf{D}^{-1}

The matrix of scaled/standardized covariance expectations for given variables \mathbf{M}_{\mathrm{scaled}} (also known as correlations) is given by

\mathbf{M}_{\mathrm{scaled}} = \mathbf{F} \mathbf{C}_{\mathrm{scaled}} \mathbf{F}^{\mathsf{T}}

where

Value

Returns a list with the following elements

par.table

Parameter table.

variables

Variable names.

g.variables

Variable names of observed variables.

h.variables

Variable names of latent variables.

A

t by t matrix \mathbf{A}. Asymmetric paths (single-headed arrows), such as regression coefficients and factor loadings.

S

t by t numeric matrix \mathbf{S}. Symmetric paths (double-headed arrows), such as variances and covariances.

u

t by 1 matrix \mathbf{u} of mean structure parameters.

Filter

p by t numeric matrix \mathbf{F}. Filter matrix used to select observed variables.

v

t by 1 matrix \mathbf{v} of expected values.

g

p by 1 matrix \mathbf{g} of expected values of observed variables.

C

t by t matrix \mathbf{C} of expected covariances.

M

p by p matrix \mathbf{M} of expected covariances of observed variables.

Syntax

Each line should follow the syntax below

lhs <space> op <space> rhs <space> par.label <\n> or <;>

lhs

is the variable on the left-hand side,

rhs

is the variable on the right-hand side,

op

is the operation between lhs and rhs,

par.label

is the column of parameter label,

\n or ;

are line breaks. Each line should end with a line break.

Operations

The associations are defined by the following operations

by

left-hand side measured by right-hand side,

on

left-hand side regressed on right-hand side,

with

left-hand side covarying with right-hand side,

on 1

left-hand side regressed on 1 for mean structure.

par.label

Each parameter should be labeled. The par.label should be a number for fixed parameters and a character string for free parameters. Equality contraints can be imposed by using the same par.label.

Line breaks

The characters \n and ; can be used as line breaks. Each line should end with a line break.

Comments

Comments can be written after a hash (#) sign.

Author(s)

Ivan Jacob Agaloos Pesigan

References

McArdle, J. J., & McDonald, R. P. (1984). Some algebraic properties of the Reticular Action Model for moment structures. British Journal of Mathematical and Statistical Psychology, 37 (2), 234–251. https://doi.org/10.1111/j.2044-8317.1984.tb00802.x

See Also

Other eq functions: Eq2RAM(), EqParse()

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# Numerical ---------------------------------------------------------
eq <- "
  # lhs op   rhs par.label
    e   by   y   1
    y   on   x   1
    e   with e   1
    x   with x   0.25
    y   on   1   0
    x   on   1   0.50
"
Eq2Expectations(eq)

# Symbolic ----------------------------------------------------------
eq <- "
  # lhs op   rhs par.label
    e   by   y   1
    y   on   x   beta
    e   with e   sigmae2
    x   with x   sigmax2
    y   on   1   alpha
    x   on   1   mux
"
Eq2Expectations(eq, par = FALSE)
Eq2Expectations(eq, par = TRUE)

# Expressions using `par.label`

beta <- 1
sigmae2 <- 1
sigmax2 <- 0.25
alpha <- 0
mux <- 0.50
Exp <- Eq2Expectations(eq, par = FALSE, R = TRUE)
eval(Exp$M)
eval(Exp$g)

# Expressions using `par.index`

p <- c(beta, sigmae2, sigmax2, alpha, mux)
p1 <- p[1]
p2 <- p[2]
p3 <- p[3]
p4 <- p[4]
p5 <- p[5]
Exp <- Eq2Expectations(eq, par = TRUE, R = TRUE)
eval(Exp$M)
eval(Exp$g)

jeksterslab/ramR documentation built on March 14, 2021, 9:38 a.m.