Updated copyright to 2013 for R/ demo/ models/passing and src/ folders, and also...
[openmx:openmx.git] / models / passing / PPML_testFactorModelMatrixRaw.R
1 ## Two Factor Model -- Matrix Specification
2 # One factor model
3 # One latent predicts three manifests.  Regression weights between latents and
4 # manifests are fixed, variances for latents are free, error variances of the
5 # manifest variables are homogeneous.
6 # Written by Daniel Hackett, August 2011
7
8 require(OpenMx)
9 require(MASS)
10 #dataCov <- rbind(c(31,33,44),c(33,62,75),c(44,75,123))
11 dataCov <- rbind(c(4,2,2),c(2,4,2),c(2,2,4))
12 manifests <- c('X','Y','Z')
13 colnames(dataCov) <- manifests
14 rownames(dataCov) <- manifests
15 set.seed(1234)
16 dataTest <- mvrnorm(n=5000, c(1,1,1), dataCov)
17
18 latents <- c('G', 'H')
19 factorModel <- mxModel("Two Factor Matrix",
20       type="RAM",
21           
22           mxMatrix(
23                 type = "Full",
24                 nrow = 5,
25                 ncol = 5,
26                 free = FALSE,
27                 values = c(0, 0, 0, 1, 1,
28                                    0, 0, 0, 2, 1,
29                                    0, 0, 0, 3, 1,
30                                    0, 0, 0, 0, 0,
31                                    0, 0, 0, 0, 0),
32                 byrow = TRUE,
33                 name = "A"),
34           mxMatrix(
35                 type = "Symm",
36                 nrow = 5,
37                 ncol = 5,
38                 free = c(T, F, F, F, F,
39                                  F, T, F, F, F,
40                                  F, F, T, F, F,
41                                  F, F, F, T, T,
42                                  F, F, F, T, T),
43                 values = c(1, 0, 0, 0, 0,
44                                    0, 1, 0, 0, 0,
45                                    0, 0, 1, 0, 0,
46                                    0, 0, 0, 1, 0.1,
47                                    0, 0, 0, 0.1, 1),
48                 labels = c("residual", NA, NA, NA, NA,
49                                         NA, "residual", NA, NA, NA,
50                                         NA, NA, "residual", NA, NA,
51                                         NA, NA, NA, "VarG", "CovGH",
52                                         NA, NA, NA, "CovGH", "VarH"),
53                 byrow = TRUE,
54                 name = "S"),
55           mxMatrix(
56                 type = "Full",
57                 nrow = 3,
58                 ncol = 5,
59                 free = FALSE,
60                 values = c(1, 0, 0, 0, 0,
61                                    0, 1, 0, 0, 0,
62                                    0, 0, 1, 0, 0),
63                 byrow = TRUE,
64                 name="F"),
65           mxMatrix(
66                 type="Full",
67                 nrow=1,
68                 ncol=5,
69                 free=c(F,F,F,T,T),
70                 values=c(0,0,0,0,0),
71                 labels=c(NA,NA,NA,"M_G","M_H"),
72                 name="M"),
73                 
74       mxData(dataTest, type="raw", numObs=300),
75           mxRAMObjective("A","S","F","M",dimnames=c("X", "Y", "Z", "G","H"))
76                         )
77 imxTestPPML(factorModel)