File: mplus-ex9.1.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 (35 lines) | stat: -rw-r--r-- 1,281 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
# MPLUS: TWO-LEVEL REGRESSION ANALYSIS FOR A CONTINUOUS DEPENDENT VARIABLE WITH A RANDOM INTERCEPT
# https://www.statmodel.com/usersguide/chapter9.shtml

library(OpenMx)

options(width=120)
ex91 <- suppressWarnings(try(read.table("models/nightly/data/ex9.1a.dat")))
if (is(ex91, "try-error")) ex91 <- read.table("data/ex9.1a.dat")
colnames(ex91) <- c('y', 'x', 'w', 'xm', 'clus')
ex91$clus <- as.integer(ex91$clus)

betweenModel <- mxModel(
    'betweenModel', type='RAM',
    latentVars=c('w', 'xm', 'y'),
    mxData(ex91[!duplicated(ex91$clus),], 'raw', primaryKey='clus'),
    mxPath('y', arrows=2),
    mxPath('one', 'w', free=FALSE, labels='data.w'),
    mxPath('one', 'xm', free=FALSE, labels='data.xm'),
    mxPath(c('w', 'xm'), 'y'))
	
withinModel <- mxModel(
    'withinModel', type='RAM', betweenModel,
    mxData(ex91, 'raw'),
    manifestVars='y', latentVars=c('x'),
    mxPath('one', 'x', free=FALSE, labels='data.x'),
    mxPath('x', 'y'),
    mxPath('one', 'y'),
    mxPath('y', arrows=2, values=1),
    mxPath('betweenModel.y', 'y', free=FALSE, values=1, joinKey='clus'))

withinModel <- mxRun(withinModel)

omxCheckEquals(withinModel$expectation$debug$rampartUsage, 890)

omxCheckCloseEnough(summary(withinModel)$informationCriteria['AIC:','par'], 3063.876, 1e-3)