File: xxm-2.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 (36 lines) | stat: -rw-r--r-- 1,108 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
# stuff to dye for
# http://xxm.times.uh.edu/learn-xxm/lme4-example-dyestuff/

libraries <- rownames(installed.packages())
if (!("lme4" %in% libraries)) stop("SKIP")

library(lme4)
library(OpenMx)

batch <- mxModel(
    'batch', type="RAM",
    latentVars = c('batch'),
    mxData(data.frame(batch=unique(Dyestuff$Batch)), 'raw', primaryKey='batch'),
    mxPath('batch', arrows=2, values=100, ubound=10000))

yield <- mxModel(
    'yield', type='RAM', batch,
    manifestVars = c('Yield'),
    mxData(Dyestuff, 'raw'),
    mxPath('one', 'Yield'),
    mxPath('Yield', arrows=2, values=100, ubound=10000),
    mxPath('batch.batch', 'Yield', free=FALSE, values=1, joinKey="Batch"))

yield <- mxRun(yield)

omxCheckCloseEnough(yield$output$fit, 327.3271, 1e-2)

(fm01 <- lmer(Yield ~ 1 + (1 | Batch), REML = FALSE, Dyestuff))
omxCheckCloseEnough(logLik(fm01), logLik(yield), 5e-3)

# Check free parameter estimates
lVars <- as.data.frame(VarCorr(fm01))[, 'vcov']
lEst <- c(lVars[2], fixef(fm01), lVars[1])
oEst <- coef(yield)
rms <- function(x, y){sqrt(mean((x-y)^2))}
omxCheckCloseEnough(rms(oEst, lEst), 0, 3)