You are here

error msg: typecheck incoming covCols covRows to verifyMvnNames (file MxExpectationNormal.R)

in file MxExpectationNormal.R
verifyMvnNames()
attempts this:

(length(covRows) != length(covCols)) || !all(covRows == covCols))

covRows gets covDimnames[[1]]
covDimnames gets dimnames(covariance)
and covariance is flatModel[[covName]]

so the problem was embedded in an incoming flatModel (exerpted snippet below).

I am guessing that we are letting people set dimnames incorrectly outside the this code...

verifyMvnNames <- function(covName, meansName, type, flatModel, modelname, expectationName) {
    covariance <- flatModel[[covName]]
    if (length(covariance)) {
        covDimnames <- dimnames(covariance)
        covRows <- covDimnames[[1]]
        covCols <- covDimnames[[2]]

But we don't pre-check the incoming types, i.e., that that the dimnames are a character vector.
we should perhaps accept lists (what you get from dimnames of a model's expCov) and unlist them

But good to exit gracefully here, with a clear error message showing what we got versus an example of what we need when something is passed in that can't be used.

current behavior is to say

Error in covRows == covCols : 
comparison of these types is not implemented

which doesn't help unless you don't need any help.

I figured it out - the dimnames were a list (extracted from dimnames of a model's expCov) rather than a character vector. unlist() fixed it. I suggest we test if they are the right type before checking if the rownames and colnames of the expCov are the same, so as to exit gracefully with a clear error message.

Cheers
Mike

From iPad - brief

Michael C. Neale, Ph.D.
Professor, Departments of Psychiatry & Human Genetics
Virginia Commonwealth University VIPBG
Shipping Address: 800 East Leigh St. Suite 1-114, Richmond VA 23219-1534
Mailing Address : Box 980126 MCV Richmond VA 23298-0126
Telephone: (804) 828-3369 Fax: (804) 828-1471 Email: neale@vcu.edu

On Nov 21, 2014, at 4:48 PM, Michael Neale wrote:

Has anyone seen this one:

Running Factor Score Model
Error in covRows == covCols :
comparison of these types is not implemented

I surmise it may be from:
(length(covRows) != length(covCols)) || !all(covRows == covCols))
In MxExpectationNormal.R
And traceback leads to verifyMvnNames()

but weird, eh? Can't provide example generating code v easily as MacBook still sick

Cheers
Mike

Reporter: 
Created: 
Sat, 11/22/2014 - 05:59
Updated: 
Thu, 12/10/2015 - 17:26

Comments

Can anyone provide code that produces this error? Based on reading between the lines, I thought the following example would do it, but this case is caught and handled correctly.

# Create and fit a model using mxMatrix, mxAlgebra,
#  mxExpectationNormal, and mxFitFunctionML
 
library(OpenMx)
 
# Simulate some data
x=rnorm(1000, mean=0, sd=1)
y= 0.5*x + rnorm(1000, mean=0, sd=1)
tmpFrame <- data.frame(x, y)
tmpNames <- dimnames(cov(tmpFrame)) #names(tmpFrame)
 
# Define the matrices
M <- mxMatrix(type = "Full", nrow = 1, ncol = 2, values=c(0,0), 
              free=c(TRUE,TRUE), labels=c("Mx", "My"), name = "M")
S <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(1,0,0,1), 
              free=c(TRUE,FALSE,FALSE,TRUE), labels=c("Vx", NA, NA, "Vy"),
              name = "S")
A <- mxMatrix(type = "Full", nrow = 2, ncol = 2, values=c(0,1,0,0), 
              free=c(FALSE,TRUE,FALSE,FALSE), labels=c(NA, "b", NA, NA),
              name = "A")
I <- mxMatrix(type="Iden", nrow=2, ncol=2, name="I")
 
# Define the expectation
expCov <- mxAlgebra(solve(I-A) %*% S %*% t(solve(I-A)), name="expCov")
expFunction <- mxExpectationNormal(covariance="expCov", means="M",
    dimnames=tmpNames)
## Errors Here ##
 
# Choose a fit function
fitFunction <- mxFitFunctionML()
 
# Define the model
tmpModel <- mxModel(model="exampleModel", M, S, A, I,
                    expCov, expFunction, fitFunction,
                    mxData(observed=tmpFrame, type="raw"))
 
# Fit the model and print a summary
tmpModelOut <- mxRun(tmpModel)
summary(tmpModelOut)

If no one can produce the error, then I'm going to close this.

Can't replicated this. Seems to be fixed now.