Last active
August 29, 2015 14:02
-
-
Save tbates/d2261e8c5daf426e1c8e to your computer and use it in GitHub Desktop.
Why is this independence model not getting the means and variance in the data?
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(OpenMx) | |
manifests = c("mpg", "disp", "gear") | |
# ============================= | |
# = simple independence model = | |
# ============================= | |
m1 <- mxModel("ind", type = "RAM", | |
manifestVars = manifests, | |
mxPath(from = manifests, arrows = 2), | |
mxPath(from = "one", to = manifests), | |
mxData(mtcars[,manifests], type="raw") | |
) | |
m1 = mxRun(m1) | |
# =========================== | |
# = Our parameter estiamtes = | |
# =========================== | |
s = summary(m1)$parameters; s$Estimate = round(s$Estimate,2); s[,3:5] | |
row col Estimate | |
1 mpg mpg 695524.97 | |
2 disp disp 108907330.80 | |
3 gear gear 18792.08 | |
4 1 mpg 20.02 | |
5 1 disp 130.76 | |
6 1 gear 3.69 | |
# =================================== | |
# = Means and variances in the data = | |
# =================================== | |
round(diag(cov(mtcars[,manifests])),2) | |
mpg disp gear | |
36.32 15360.80 0.54 | |
colMeans(mtcars[,manifests]) | |
mpg disp gear | |
20.09 230.72 3.69 | |
# switch optimiser | |
m1 = mxOption(m1, "Default optimizer", "NPSOL") | |
# set start values | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment