All tests are now passing. Huzzah.
[openmx:openmx.git] / demo / TwoFactorModel_PathRaw.R
1 require(OpenMx)\r
2 \r
3 data(myFADataRaw)\r
4 \r
5 twoFactorRaw <- myFADataRaw[,c("x1","x2","x3","y1","y2","y3")]\r
6 \r
7 twoFactorModel <- mxModel("Two Factor Model - Path", \r
8     type="RAM",\r
9     mxData(\r
10         observed=twoFactorRaw, \r
11         type="raw",\r
12         ),\r
13     manifestVars=c("x1", "x2", "x3", "y1", "y2", "y3"),\r
14     latentVars=c("F1","F2"),\r
15     # residual variances\r
16     mxPath(from=c("x1", "x2", "x3", "y1", "y2", "y3"),\r
17         arrows=2,\r
18         free=TRUE,\r
19         values=c(1,1,1,1,1,1),\r
20         labels=c("e1","e2","e3","e4","e5","e6")\r
21     ),\r
22     # latent variances and covaraince\r
23     mxPath(from=c("F1","F2"),\r
24         arrows=2,\r
25         all=2,\r
26         free=TRUE,\r
27         values=c(1, .5,\r
28                 .5, 1),\r
29         labels=c("varF1", "cov", "cov", "varF2")\r
30     ), \r
31     # factor loadings for x variables\r
32     mxPath(from="F1",\r
33         to=c("x1","x2","x3"),\r
34         arrows=1,\r
35         free=c(FALSE,TRUE,TRUE),\r
36         values=c(1,1,1),\r
37         labels=c("l1","l2","l3")\r
38     ),\r
39     # factor loadings for y variables\r
40     mxPath(from="F2",\r
41         to=c("y1","y2","y3"),\r
42         arrows=1,\r
43         free=c(FALSE,TRUE,TRUE),\r
44         values=c(1,1,1),\r
45         labels=c("l4","l5","l6")\r
46     ),\r
47     # means\r
48     mxPath(from="one",\r
49         to=c("x1","x2","x3","y1","y2","y3","F1","F2"),\r
50         arrows=1,\r
51         free=c(T ,T, T, T, T, T, F, F),\r
52         values=c(1,1,1,1,1,1,0,0),\r
53         labels=c("meanx1","meanx2","meanx3",\r
54                  "meany1","meany2","meany3",\r
55                   NA,NA)\r
56     ) # means\r
57 ) # close model\r
58       \r
59 twoFactorFit <- mxRun(twoFactorModel)\r
60 \r
61 # Old Mx Values\r
62 omxCheckCloseEnough(twoFactorFit@output$estimate[["l2"]], 0.9723, 0.01)\r
63 omxCheckCloseEnough(twoFactorFit@output$estimate[["l3"]], 0.9313, 0.01)\r
64 omxCheckCloseEnough(twoFactorFit@output$estimate[["l5"]], 1.0498, 0.01)\r
65 omxCheckCloseEnough(twoFactorFit@output$estimate[["l6"]], 1.0531, 0.01)\r
66 omxCheckCloseEnough(twoFactorFit@output$estimate[["varF1"]], 0.6604, 0.01)\r
67 omxCheckCloseEnough(twoFactorFit@output$estimate[["varF2"]], 0.4505, 0.01)\r
68 omxCheckCloseEnough(twoFactorFit@output$estimate[["cov"]], 0.2952, 0.01)\r
69 omxCheckCloseEnough(twoFactorFit@output$estimate[["e1"]], 0.3349, 0.01)\r
70 omxCheckCloseEnough(twoFactorFit@output$estimate[["e2"]], 0.3985, 0.01)\r
71 omxCheckCloseEnough(twoFactorFit@output$estimate[["e3"]], 0.4091, 0.01)\r
72 omxCheckCloseEnough(twoFactorFit@output$estimate[["e4"]], 0.5404, 0.01)\r
73 omxCheckCloseEnough(twoFactorFit@output$estimate[["e5"]], 0.4809, 0.01)\r
74 omxCheckCloseEnough(twoFactorFit@output$estimate[["e6"]], 0.5571, 0.01)\r
75 omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx1"]], 2.988, 0.01)\r
76 omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx2"]], 3.0113, 0.01)\r
77 omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx3"]], 2.9861, 0.01)\r
78 omxCheckCloseEnough(twoFactorFit@output$estimate[["meany1"]], 2.9554, 0.01)\r
79 omxCheckCloseEnough(twoFactorFit@output$estimate[["meany2"]], 2.9562, 0.01)\r
80 omxCheckCloseEnough(twoFactorFit@output$estimate[["meany3"]], 2.9673, 0.01)\r
81 \r
82 # omxCheckCloseEnough(twoFactorFit@output$estimate[["l2"]], 0.999, 0.01)\r
83 # omxCheckCloseEnough(twoFactorFit@output$estimate[["l3"]], 0.959, 0.01)\r
84 # omxCheckCloseEnough(twoFactorFit@output$estimate[["l4"]], 1.028, 0.01)\r
85 # omxCheckCloseEnough(twoFactorFit@output$estimate[["l5"]], 1.008, 0.01)\r
86 # omxCheckCloseEnough(twoFactorFit@output$estimate[["l6"]], 1.021, 0.01)\r
87 # omxCheckCloseEnough(twoFactorFit@output$estimate[["varF1"]], 0.645, 0.01)\r
88 # omxCheckCloseEnough(twoFactorFit@output$estimate[["e1"]], 0.350, 0.01)\r
89 # omxCheckCloseEnough(twoFactorFit@output$estimate[["e2"]], 0.379, 0.01)\r
90 # omxCheckCloseEnough(twoFactorFit@output$estimate[["e3"]], 0.389, 0.01)\r
91 # omxCheckCloseEnough(twoFactorFit@output$estimate[["e4"]], 0.320, 0.01)\r
92 # omxCheckCloseEnough(twoFactorFit@output$estimate[["e5"]], 0.370, 0.01)\r
93 # omxCheckCloseEnough(twoFactorFit@output$estimate[["e6"]], 0.346, 0.01)\r
94 # omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx1"]], 2.988, 0.01)\r
95 # omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx2"]], 3.011, 0.01)\r
96 # omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx3"]], 2.986, 0.01)\r
97 # omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx4"]], 3.053, 0.01)\r
98 # omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx5"]], 3.016, 0.01)\r
99 # omxCheckCloseEnough(twoFactorFit@output$estimate[["meanx6"]], 3.010, 0.01)\r