File: mice.R

package info (click to toggle)
r-cran-openmx 2.18.1-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 15,908 kB
  • sloc: cpp: 35,071; ansic: 13,690; fortran: 2,001; sh: 1,362; python: 350; perl: 21; makefile: 5
file content (35 lines) | stat: -rw-r--r-- 844 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
# library(mice)
# install.packages("Amelia")
library(Amelia)

# 1. make a variable with missingness
demoOneFactor$x = demoOneFactor$x2
demoOneFactor$x[as.logical(rbinom(n=500,1,.2))] = NA

# 2. make and run a model x <- x1
m1 <- mxModel("m1", type="RAM",
	manifestVars = c("x", "x1"),
	# Factor loadings
	mxPath("x1", to = "x"),
	mxPath(c("x1", "x"), arrows = 2), # manifest residuals 
	mxPath("one", to = c("x1", "x")), # manifest means
	mxData(demoOneFactor, type = "raw")
)
m1 = umxRun(m1, setLabels = T, setValues = T)
summary(m1)$parameters

# 3. impute some data and mouse it

# imp = mice(demoOneFactor, m = 5)
imp = amelia(demoOneFactor, m = 5)

for (i in seq) {
	imp$imputations$imp1
}

m2 = with(data= imp, expr = m1)

summary(m2)$parameters
# Error: No glance method for objects of class MxRAMModel

# This error is not desirable :-)