# Robust ML estimation in OpenMX

8 posts / 0 new
Offline
Joined: 05/21/2010 - 03:22
Robust ML estimation in OpenMX

Dear all,

I am a new learner of OpenMX and R. I am interested to know if there is alternative estimation (robust ML such as Satorra-Bentler test statisitc, ADF/WLS by Browne) besides normal-theory ML?

Thank you!

Heining Cham

Offline
Joined: 10/08/2009 - 22:37

Dear Heining,

ADF can be implemented quite easily. The results look reasonable. The other approaches may be more challenging.

Cheers,
Mike

library(MASS)

library(OpenMx)

set.seed(100)
n <- 1000

# Population values for 1 factor model

L1 <- matrix(c(1,1.2,1.3,0,0,0,0,0,0,1,1.2,1.3),ncol=2)
P1 <- matrix(c(1,0.3,0.3,1), ncol=2)
E1 <- diag(rep(0.5,6))
Sigma <- L1 %&% P1 + E1 # one factor model
my.df <- data.frame(mvrnorm(n=n, mu=rep(0,6), Sigma=Sigma))

# Sample covariance matrix

cov.sample <- cov(my.df)

# Sample covariance matrix

D <- mxMatrix("Full", ncol=6, nrow=6, values=c(cov.sample), name="D")

L <- mxMatrix("Full", ncol=2, nrow=6, values=c(1,1,1,0,0,0,0,0,0,1,1,1),
free=c(rep(T,3),rep(F,6),rep(T,3)), name="L")

# Factor correlation matrix

P <- mxMatrix("Stand", ncol=2, nrow=2, value=0.5,free=TRUE, name="P")

# Error covariance matrx

E <- mxMatrix("Diag", ncol=6, nrow=6, values=0.2, free=TRUE, name="E")

# Discrepancy between sample covariance matrix and model implied covariance matrix

S <- mxAlgebra( D-(L %&% P + E ), name="S")

# Convert it into a vector of covariance elements

vech_S <- mxAlgebra(vech(S), "vech_S")

# Weight matrix multiplied by n

acov_S <- mxMatrix("Full", ncol=21, nrow=21, values=n*c(solve(acov)), free=FALSE, name="acov_S")

# Objective function

obj <- mxAlgebra( t(vech_S) %&% acov_S , name="obj")
objective <- mxAlgebraObjective('obj')

model <- mxModel("WLS", D, L, P, E, S, vech_S, acov_S, obj, objective, mxCI(c("P")))
fit <- mxRun(model, intervals=TRUE)
summary(fit)

Offline
Joined: 07/31/2009 - 15:24
Very cool. One small comment

Very cool. One small comment is that in OpenMx 0.3.1 confidence intervals for all the cells of the "P" matrix are calculated, including those cells with fixed values. In OpenMx 0.3.2 (coming soon) only cells with free parameters will be calculated. In the meantime, use mxCI(c("P[1,2]", "P[2,1]")).

I used the following steps to install the sem.additions library. I needed the prerequisites sem, mvnormtest, sna, matrixcalc, and igraph on my system. Then I downloaded the source for sem.additions, opened the tarball, and ran "R CMD INSTALL ." They have binaries for Windows and OS X platforms.

Offline
Joined: 07/30/2009 - 14:03
Hi Mike, Very cool! This is

Hi Mike,

Very cool! This is the way we hoped OpenMx would be used. Easy implementation of methods as mxAlgebraObjectives and then later incorporating these into optimized C versions in the computational engine.

I hope this is just the first of many discussions that implement well-known methods.

We also hope that people will use the mxAlgebraObjective to experiment with novel methods. If we have accelerated the pace of your development of new methods, the OpenMx team will feel a real sense of accomplishment in our work.

Offline
Joined: 10/08/2009 - 22:37
Hi Michael Spiegel and

Hi Michael Spiegel and Steve,

Indeed, I have to thank the core team in developing OpenMx and entertaining requests from end users like me. I asked a few questions related to the vech and vechs calculations in OpenMx. Then vech() and vechs() were implemented a few days later!

Mike

Offline
Joined: 07/31/2009 - 15:14

Very nice going! How about the same approach for binary/ordinal data (preferably allowing for missing values)?

Offline
Joined: 05/21/2010 - 03:22
Thank you! I can install

Thank you! I can install sem.additions. I am trying to start from the WLS syntax in Mike's post.

Offline
Joined: 10/08/2009 - 22:37
I am writing a package to

I am writing a package to conduct meta-analysis based on OpenMx. One of the functions is WLS that fits correlation and covariance structure analysis. It also calculates some goodness-of-fit indices. It is available for testing at http://courses.nus.edu.sg/course/psycwlm/internet/metaSEM/index.html When the Jacobian matrix is accessible in a later release of OpenMx, I will implement the robust standard error and robust test statistics.

Thanks for the hard work on OpenMx. It's very flexible and extensible.

Regards,
Mike

library(metaSEM)

# Sample correlation matrix

R1 <- matrix(c(1.00, 0.22, 0.24, 0.18,
0.22, 1.00, 0.30, 0.22,
0.24, 0.30, 1.00, 0.24,
0.18, 0.22, 0.24, 1.00), ncol=4, nrow=4)
n <- 1000

# Calculate the asymptotic covariance matrix of the sample correlation matrix

acovR <- asyCov(R1, n)

# P1: Factor variance

P1 <- mxMatrix("Full", ncol=1, nrow=1, value=1, free=FALSE, name="P1")

L1 <- mxMatrix("Full", ncol=1, nrow=4, value=c(0.3, 0.4, 0.5, 0.4), free=TRUE, name="L1")

# Please note that error variances are not involved in correlation structure analysis

impliedR1 <- mxAlgebra(L1 %&% P1, name="impliedR1")

wls.fit1 <- wls(S=R1, acovS=acovR, n=n, impliedS=impliedR1, matrices=c(P1, L1), cor.analysis=TRUE, intervals=TRUE)
summary(wls.fit1)