You are here

Error when summary() applied to already-run mxModel using mxRObjective()

2 posts / 0 new
Last post
RobK's picture
Offline
Joined: 04/19/2011 - 21:00
Error when summary() applied to already-run mxModel using mxRObjective()

FYI, whenever I run an mxModel that includes mxRObjective() for its objective function, and then try to get its summary output, it throws this error:
Error in match(x, table, nomatch = 0L) :
no slot of name "dims" for this object of class "MxRObjective"

--Rob K.

mhunter's picture
Offline
Joined: 07/31/2009 - 15:26
Fixed in trunk

This works for me in the trunk. I think it got fixed with the shift to expectation-fit.

The Hessian comes back weird and different from the same model as a row objective.

#------------------------------------------------
set.seed(135)
nobs <- 13
adat <- data.frame(x=rnorm(nobs))
 
dmod <- mxModel(
    name='I will run fast on OpenMx',
    mxMatrix(name='A', nrow=nobs, ncol=1, free=T, values=0.1),
    mxMatrix(name='X', nrow=nobs, ncol=1, free=F, values=as.matrix(adat)),
    mxAlgebra((X-A) %^% 2, name='Row'),
    mxAlgebra(sum(Row), name='Red'),
    mxFitFunctionAlgebra('Red')
)
 
dmodRun <- mxRun(dmod) # runs super fast := 0.07 sec
omxCheckCloseEnough(mxEval(A, dmodRun), as.matrix(adat), epsilon=10^(-5))
 
 
#------------------------------------------------
robj1 <- function(model, state) {
    a <- model$A$values
    x <- model$X$values
    return(sum((x - a) ^ 2))
}
 
emod <- mxModel(
    name='I will run slow on OpenMx',
    mxMatrix(name='A', nrow=nobs, ncol=1, free=T, values=0.1),
    mxMatrix(name='X', nrow=nobs, ncol=1, free=F, values=as.matrix(adat)),
    mxFitFunctionR(robj1)
)
 
emodRun <- mxRun(emod) # runs super slow := 10.5 sec
omxCheckCloseEnough(mxEval(A, emodRun), as.matrix(adat), epsilon=10^(-5))
 
summary(emodRun)
free parameters:
                                name matrix row col    Estimate Std.Error
1   I will run slow on OpenMx.A[1,1]      A   1   1 -0.44507074        NA
2   I will run slow on OpenMx.A[2,1]      A   2   1 -0.46596519        NA
3   I will run slow on OpenMx.A[3,1]      A   3   1 -0.10446305        NA
4   I will run slow on OpenMx.A[4,1]      A   4   1  1.40833517        NA
5   I will run slow on OpenMx.A[5,1]      A   5   1 -1.31608659        NA
6   I will run slow on OpenMx.A[6,1]      A   6   1  0.24520877        NA
7   I will run slow on OpenMx.A[7,1]      A   7   1  1.20474301        NA
8   I will run slow on OpenMx.A[8,1]      A   8   1 -0.44070022        NA
9   I will run slow on OpenMx.A[9,1]      A   9   1  0.42282637        NA
10 I will run slow on OpenMx.A[10,1]      A  10   1  0.96486349        NA
11 I will run slow on OpenMx.A[11,1]      A  11   1  1.00777299        NA
12 I will run slow on OpenMx.A[12,1]      A  12   1  0.05038159        NA
13 I will run slow on OpenMx.A[13,1]      A  13   1  0.61003287        NA
 
# R fit function Hessian is all zero
all(emodRun$output$calculatedHessian == matrix(0, 13, 13))
[1] TRUE
all(emodRun$output$hessian == matrix(0, 13, 13))
[1] TRUE
 
# Row fit function Hessian is diagonal: 2*I
omxCheckCloseEnough(dmodRun$output$calculatedHessian, diag(2, 13), 1e-10)
dmodRun$output$calculatedHessian and diag(2, 13) are equal to within 1e-10.