File: vcov.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 (38 lines) | stat: -rw-r--r-- 1,239 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
33
34
35
36
37
38
library(OpenMx)

omxCheckError(vcov(mxModel("empty")),
	      'This model has not been run yet. Tip: Use
  model = mxRun(model)
to estimate a model.')

data(demoOneFactor)
manifests <- names(demoOneFactor)
latents <- c("G")

oneFactor <- mxModel(
    "oneFactor", type="RAM",
    manifestVars = manifests,
    latentVars = latents,
    mxPath(from=latents, to=manifests, values=rnorm(length(manifests))),
    mxPath(from=manifests, arrows=2, values=rlnorm(length(manifests))),
    mxPath(from=latents, arrows=2, free=FALSE, values=1.0),
    mxPath(from = 'one', to = manifests, values=rnorm(length(manifests))),
    mxData(demoOneFactor, type="raw"))

oneFactor <- mxOption(oneFactor, "Calculate Hessian", "No")

oneFactor <- mxRun(oneFactor)

vc1 <- omxCheckWarning(vcov(oneFactor),
                       "The 'Calculate Hessian' option is disabled. This may result in a poor accuracy vcov matrix.
Turn on with mxOption(model, 'Calculate Hessian', 'Yes')")


oneFactor <- mxOption(oneFactor, "Calculate Hessian", "Yes")

oneFactor <- mxRun(oneFactor)

omxCheckTrue(all(abs(sqrt(diag(vcov(oneFactor))) - oneFactor$output$standardErrors) < 1e-6))

# ensure mxSE works
omxCheckCloseEnough(mxSE(M[1,1] / S[1,1], oneFactor), 0.4934011, .001)