figure2_5.cor0 <- matrix(c(1,.50,.10,.20,.50, 1, .10, .30, .10, .10, 1, .20, .20, .30, .20,1), nrow=4,
ncol=4, dimnames=list(c("X1", "X2", "X3", "X4"), c("X1", "X2", "X3", "X4")))
#1.00 .50 .10 .20
#.50 1.00 .10 .30
#.10 .10 1.00 .20
#.20 .30 .20 1.00
figure2_5.cor <- mxData(observed=figure2_5.cor0, type="cov", numObs=100)
figure2_5.matrF <- mxMatrix(type="Full", nrow=4, ncol=6, free=FALSE, name="F",byrow=TRUE,
values = c( 1,0,0,0,0,0,
0,1,0,0,0,0,
0,0,1,0,0,0,
0,0,0,1,0,0))
figure2_5.matrA <- mxMatrix(type="Full", nrow=6, ncol=6, name="A", byrow=TRUE,
free = c(FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,
FALSE,FALSE,FALSE,FALSE,TRUE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,
FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,FALSE),
values = c(0,0,0,0,1,0,
0,0,0,0,1,0,
0,0,0,0,0,1,
0,0,0,0,0,1,
0,0,0,0,0,0,
0,0,0,0,0,0))
figure2_5.matrS <- mxMatrix(type="Symm", nrow=6, ncol=6, name="S",byrow=TRUE,
free = c(TRUE,FALSE,FALSE,FALSE,FALSE,FALSE,
FALSE,TRUE,FALSE,FALSE,FALSE,FALSE,
FALSE,FALSE,TRUE,FALSE,FALSE,FALSE,
FALSE,FALSE,FALSE,TRUE,FALSE,FALSE,
FALSE,FALSE,FALSE,FALSE,FALSE,TRUE,
FALSE,FALSE,FALSE,FALSE,TRUE,FALSE),
values = c(1,0,0,0,0,0,
0,1,0,0,0,0,
0,0,1,0,0,0,
0,0,0,1,0,0,
0,0,0,0,1,1,
0,0,0,0,1,1))
figure2_5.exp <- mxExpectationRAM(F="F",A="A",S="S", dimnames=c("X1","X2","X3","X4","F1","F2"))
figure2_5.funML <- mxFitFunctionML()
##fit model in OpenMx
figure2_5.model <- mxModel("Figure 2_5",figure2_5.cor, figure2_5.matrF, figure2_5.matrA,
figure2_5.matrS, figure2_5.exp, figure2_5.funML)
figure2_5.fit <- mxRun(figure2_5.model)
## Running Figure 2_5 with 9 parameters
summary(figure2_5.fit)
## Summary of Figure 2_5
##
## free parameters:
## name matrix row col Estimate Std.Error A
## 1 Figure 2_5.A[1,5] A 1 5 0.5821915 0.1501764
## 2 Figure 2_5.A[2,5] A 2 5 0.8502357 0.1920645
## 3 Figure 2_5.A[3,6] A 3 6 0.2668436 0.1538883
## 4 Figure 2_5.A[4,6] A 4 6 0.7420083 0.3413062
## 5 Figure 2_5.S[1,1] S 1 1 0.6510531 0.1671266
## 6 Figure 2_5.S[2,2] S 2 2 0.2670990 0.2998619
## 7 Figure 2_5.S[3,3] S 3 3 0.9187944 0.1446087
## 8 Figure 2_5.S[4,4] S 4 4 0.4394237 0.4946350
## 9 Figure 2_5.S[5,6] S 5 6 0.4687644 0.2436230
##
## Model Statistics:
## | Parameters | Degrees of Freedom | Fit (-2lnL units)
## Model: 9 1 353.0621
## Saturated: 10 0 352.9371
## Independence: 4 6 396.0000
## Number of observations/statistics: 100/10
##
## chi-square: χ² ( df=1 ) = 0.1249912, p = 0.7236829
## Information Criteria:
## | df Penalty | Parameters Penalty | Sample-Size Adjusted
## AIC: -1.875009 18.12499 20.12499
## BIC: -4.480179 41.57152 13.14726
## CFI: 1.023609
## TLI: 1.141652 (also known as NNFI)
## RMSEA: 0 *(Non-centrality parameter is negative) [95% CI (0, 0.2237515)]
## Prob(RMSEA <= 0.05): 0.7549002
## timestamp: 2023-04-18 10:46:30
## Wall clock time: 0.04167604 secs
## optimizer: SLSQP
## OpenMx version number: 2.21.8
## Need help? See help(mxSummary)
##Plot using umx – an SEM package that leverages OpenMx– and semPlot
# set up basics
manifests <- c("X1", "X2", "X3", "X4")
F1Vars <- c("X1", "X2")
F2Vars <- c("X3", "X4")
dataO = mxData(figure2_5.cor0, type= 'cov', numObs= 100)
manifests <- c("X1", "X2", "X3", "X4")
m1 = umxRAM("Two Factor", data = dataO,
umxPath("F1", to = F1Vars),
umxPath("F2", to = F2Vars),
umxPath(var = manifests),
umxPath(var = c("F1","F2"), fixedAt = 1),
umxPath("F1", with = "F2")
)
## 2 latent variables were created:F1, F2.
## Running Two Factor with 9 parameters
## ?umxSummary std=T|F', digits, report= 'html', filter= 'NS' & more
##
##
## Table: Parameter loadings for model 'Two Factor'
##
## | |name | Estimate|SE |type |
## |:--|:----------|--------:|:-----|:---------------|
## |10 |F1_with_F2 | 0.469|0.244 |Factor Cov |
## |1 |F1_to_X1 | 0.582|0.15 |Factor loading |
## |2 |F1_to_X2 | 0.850|0.192 |Factor loading |
## |3 |F2_to_X3 | 0.267|0.154 |Factor loading |
## |4 |F2_to_X4 | 0.742|0.341 |Factor loading |
## |9 |F1_with_F1 | 1.000|0 |Factor Variance |
## |11 |F2_with_F2 | 1.000|0 |Factor Variance |
## |5 |X1_with_X1 | 0.651|0.167 |Residual |
## |6 |X2_with_X2 | 0.267|0.3 |Residual |
## |7 |X3_with_X3 | 0.919|0.145 |Residual |
## |8 |X4_with_X4 | 0.439|0.494 |Residual |
##
## Model Fit: χ²(1) = 0.12, p = 0.724; CFI = 1.024; TLI = 1.142; RMSEA = 0
#umx plot
plot(m1)
##
## ?plot.MxModel options: std, means, digits, strip_zero, file, splines=T/F/ortho,..., min=, max =, same = , fixed, resid= 'circle|line|none'
plot(m1, std = FALSE, digits = 3, strip_zero = FALSE)
##
## ?plot.MxModel options: std, means, digits, strip_zero, file, splines=T/F/ortho,..., min=, max =, same = , fixed, resid= 'circle|line|none'
#semPlot: conceptual model first in selected color, second plots estimates
semPaths(m1, color = list(lat = rgb(245, 253, 118, maxColorValue = 255),
man = rgb(155, 253, 175, maxColorValue = 255)), mar = c(10, 5, 10, 5))
semPaths(m1, what="est")
#5th image the lighter line say it is not statistically
significantly