File: Rampart0.R

package info (click to toggle)
r-cran-openmx 2.21.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 14,412 kB
  • sloc: cpp: 36,577; ansic: 13,811; fortran: 2,001; sh: 1,440; python: 350; perl: 21; makefile: 5
file content (32 lines) | stat: -rw-r--r-- 950 bytes parent folder | download | duplicates (3)
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
library(OpenMx)

uMod <- mxModel(
	"upper", type="RAM",
	latentVars = c("eta"),
	mxData(type="raw", observed=data.frame(id=1L), primaryKey = 'id'),
	mxPath('eta', arrows=2, values=1))

for (numLower in 2:10) {
	lMod <- mxModel(
		"lower", type="RAM", uMod,
		manifestVars = 'y1',
		mxData(type="raw", observed=data.frame(y1=rnorm(numLower), id=1L)),
		mxPath('one', 'y1'),
		mxPath('y1', arrows=2, values=1),
		mxPath('upper.eta', 'y1', values=.1, joinKey='id'),
		mxComputeSequence(list(
			mxComputeOnce('fitfunction', 'fit'),
			mxComputeReportExpectation())))

	lMod$expectation$.maxDebugGroups <- 10L
	lMod <- mxRun(lMod, silent=TRUE)

	target <- cbind(matrix(1, numLower, 1), contr.helmert(numLower)[numLower:1,(numLower-1):1])
	rot <- -qr.Q(qr(target))

	ed <- lMod$expectation$debug
	
	# Only the sign of the first term matters.
	omxCheckCloseEnough(abs(c(lMod$data$observed$y1 %*% rot)),
			    abs(c(ed$g2$dataVec, ed$g1$dataVec)), 1e-6)
}