# Structural Equation Modeling - Simple Linear Regression RAM Example {#simple-regression-ram-example}
In this example, we show how the Reticular Action Model (RAM) Matrices are specified using the simple linear regression model.
We also demonstrate how to use RAM notation functions in the jeksterslabRsem
package namely
In this hypothetical example, we assume that we have population data and we are interested in the association between wages and education. The regressor variable is years of education. The regressand variable is hourly wage in US dollars. The intercept is the predicted wage of an employee with 0 years of education. The slope is the increase in hourly wage in US dollars for one year increase in education.
The the following vectors represent the parameters of the simple linear regression model.
\[\begin{equation}
\boldsymbol{\theta}_{\text{mean structure}}
=
\begin{bmatrix}
\beta_1 \\
\mu_x
\end{bmatrix}
\end{equation}\]
\[\begin{equation}
\boldsymbol{\theta}_{\text{covariance structure}}
=
\begin{bmatrix}
\beta_2 \\
\sigma_{\varepsilon}^{2} \\
\sigma_{x}^{2}
\end{bmatrix}
\end{equation}\]
\(\boldsymbol{\theta}_{\text{mean structure}}\)
beta1 |
Intercept |
\(\beta_1\) |
-4.107586 |
mux |
Mean of \(x\)
|
\(\mu_x\) |
13.159813 |
\(\boldsymbol{\theta}_{\text{covariance structure}}\)
beta2 |
Slope |
\(\beta_2\) |
1.224860 |
sigma2epsilon |
Variance of \(\varepsilon\)
|
\(\sigma_{\varepsilon}^{2}\) |
47.887638 |
sigma2x |
Variance of \(x\)
|
\(\sigma_{x}^{2}\) |
7.765366 |
Parameterization Including the Error Variance
Variables are ordered as follows
-
\(y\),
-
\(x\), and
- \(\varepsilon\)
M Matrix
varnames <- c("y", "x", "epsilon")
k <- 2
q <- 1
p <- k + q
M <- matrix(
data = c(
beta1,
mux,
0
),
ncol = 1
)
rownames(M) <- varnames
colnames(M) <- "M"
y |
-4.107586 |
x |
13.159813 |
epsilon |
0.000000 |
A Matrix
y |
0 |
1.22486 |
1 |
x |
0 |
0.00000 |
0 |
epsilon |
0 |
0.00000 |
0 |
S Matrix
S <- matrix(
data = c(
0,
0,
0,
0,
sigma2x,
0,
0,
0,
sigma2epsilon
),
nrow = p
)
rownames(S) <- varnames
colnames(S) <- varnames
y |
0 |
0.000000 |
0.00000 |
x |
0 |
7.765366 |
0.00000 |
epsilon |
0 |
0.000000 |
47.88764 |
I Matrix
y |
1 |
0 |
0 |
x |
0 |
1 |
0 |
epsilon |
0 |
0 |
1 |
F Matrix
filter <- matrix(
data = c(
1,
0,
0,
1,
0,
0
),
nrow = 2,
ncol = 3
)
rownames(filter) <- c("y", "x")
colnames(filter) <- varnames
Model-Implied Mean Vector
result01_mutheta <- jeksterslabRsem::rammutheta(
M = M,
A = A,
filter = filter
)
Model-Implied Variance-Covariance Matrix
result01_Sigmatheta <- jeksterslabRsem::ramSigmatheta(
A = A,
S = S,
filter = filter
)
y |
59.537875 |
9.511486 |
x |
9.511486 |
7.765366 |
M Matrix from mutheta and A Matrix
result01_M <- jeksterslabRsem::ramM(
mu = mutheta,
A = A,
filter = filter
)
rownames(result01_M) <- varnames
colnames(result01_M) <- "M"
y |
28.13027 |
x |
13.15981 |
epsilon |
0.00000 |
S Matrix from sigma2 and A Matrix
This should only be used when the off-diagonal elements of the \(\mathbf{S}\) matrix are all zeroes.
result01_S <- jeksterslabRsem::ramsigma2(
sigma2 = c(sigma2y, sigma2x, sigma2epsilon),
A = A,
start = FALSE
)
#> The off-diagonal elements of the S matrix are assumed to be zeroes.
rownames(result01_S) <- varnames
colnames(result01_S) <- varnames
y |
0 |
0.000000 |
0.00000 |
x |
0 |
7.765366 |
0.00000 |
epsilon |
0 |
0.000000 |
47.88764 |
Parameterization Excluding the Error Variance
Variables are ordered as follows
M Matrix
varnames <- c("y", "x")
k <- 2
q <- 0
p <- k + q
M <- matrix(
data = c(
beta1,
mux
),
ncol = 1
)
rownames(M) <- varnames
colnames(M) <- "M"
S Matrix
y |
47.88764 |
0.000000 |
x |
0.00000 |
7.765366 |
Model-Implied Mean Vector
result02_mutheta <- jeksterslabRsem::rammutheta(
M = M,
A = A,
filter = filter
)
Model-Implied Variance-Covariance Matrix
result02_Sigmatheta <- jeksterslabRsem::ramSigmatheta(
A = A,
S = S,
filter = filter
)
y |
59.537875 |
9.511486 |
x |
9.511486 |
7.765366 |
M Matrix from mutheta and A Matrix
result02_M <- jeksterslabRsem::ramM(
mu = mutheta,
A = A,
filter = filter
)
rownames(result02_M) <- varnames
colnames(result02_M) <- "M"
S Matrix from sigma2 and A Matrix
This should only be used when the off-diagonal elements of the \(\mathbf{S}\) matrix are all zeroes.
result02_S <- jeksterslabRsem::ramsigma2(
sigma2 = c(sigma2y, sigma2x),
A = A,
start = FALSE
)
#> The off-diagonal elements of the S matrix are assumed to be zeroes.
rownames(result02_S) <- varnames
colnames(result02_S) <- varnames
y |
47.88764 |
0.000000 |
x |
0.00000 |
7.765366 |
Parameterization Excluding the Error Variance
Variables are ordered as follows
M Matrix
varnames <- c("x", "y")
k <- 2
q <- 0
p <- k + q
M <- matrix(
data = c(
mux,
beta1
),
ncol = 1
)
rownames(M) <- varnames
colnames(M) <- "M"
S Matrix
x |
7.765366 |
0.00000 |
y |
0.000000 |
47.88764 |
Model-Implied Mean Vector
result03_mutheta <- jeksterslabRsem::rammutheta(
M = M,
A = A,
filter = filter
)
Model-Implied Variance-Covariance Matrix
result03_Sigmatheta <- jeksterslabRsem::ramSigmatheta(
A = A,
S = S,
filter = filter
)
x |
7.765366 |
9.511486 |
y |
9.511486 |
59.537875 |
M Matrix from mutheta and A Matrix
result03_M <- jeksterslabRsem::ramM(
mu = mutheta,
A = A,
filter = filter
)
rownames(result03_M) <- varnames
colnames(result03_M) <- "M"
S Matrix from sigma2 and A Matrix
This should only be used when the off-diagonal elements of the \(\mathbf{S}\) matrix are all zeroes.
result03_S <- jeksterslabRsem::ramsigma2(
sigma2 = c(sigma2x, sigma2y),
A = A,
start = TRUE
)
#> The off-diagonal elements of the S matrix are assumed to be zeroes.
rownames(result03_S) <- varnames
colnames(result03_S) <- varnames
x |
7.765366 |
0.00000 |
y |
0.000000 |
47.88764 |