Attachment | Size |
---|---|

pheno2.csv | 1.25 KB |

Hello. I am quite naive with OpenMx & R in general, and I can't find a way to solve this error. I'm trying to create a covariance matrix with my data.. I am aware that my code is probably very messy and has lots of other errors-I really need some help & advice on how to advance with this. Thank you so much in advance. This is my code:

pheno2 <- read.csv("pheno2.csv") library(OpenMx) colnames(pheno2) <- gsub("\\.", "_", colnames(pheno2)) any(is.na(pheno2)) matrix_data <- matrix(as.double(unlist(pheno2)), ncol = 7) rownames(matrix_data) <- 1:nrow(matrix_data) colnames(matrix_data) <- colnames(pheno2) mxDataObject <- mxData(observed = matrix_data, type = "raw") num_variables <- 7 cov_matrix <- mxMatrix(type = "Full", nrow = num_variables, ncol = num_variables, free = TRUE, values = 1, name = "cov_matrix") means <- mxMatrix(type = "Full", nrow = 1, ncol = num_variables, free = TRUE, values = 0, name = "means") variances <- mxMatrix(type = "Diag", nrow = num_variables, ncol = num_variables, free = TRUE, values = 1, name = "variances") expectation <- mxExpectationNormal(covariance = "predicted_cov", means = "means") model <- mxModel("MyModel", cov_matrix, means, variances, mxAlgebra(cov_matrix %*% t(variances) %*% cov_matrix, name = "predicted_cov"), expectation, mxDataObject) model$CovarianceMatrix <- cov_matrix model$fitFunction <- mxFitFunctionML() fit <- mxRun(model)

Error: The expected covariance matrix associated with MxExpectationNormal in model 'MyModel' does not contain dimnames.

The attached file is my dataset - it has 63 entries & 7columns

This is pretty easy to fix. You can just provide the dimnames in your call to

`mxAlgebra()`

. Suppose you were analyzing five variables, with the following five column names: "x1","x2", "x3", "x4", and "x5". You could then do something like,. I notice that you don't have a header row in your dataset. You're going to have to create one, and use

`read.csv()`

with argument`header=TRUE`

, so that OpenMx knows which variables it's going to be analyzing.My mistake.

`dimnames`

is supposed to be a list of length 2; the first element provides row names, and the second provides column names. Try this:Edit: actually, what might be easier is to provide this argument,

, to

`mxExpectationNormal()`

.(I changed the column names to my header)

The below version of the model "works" in the sense that there are no errors. However, the model-implied covariance matrix at the starting values is not a valid covariance matrix.

The first question I have for you is: what do you mean by "I'm trying to create a covariance matrix with my data?"

Second, what are you hoping this algebra will do?

The attached file is the raw data for 7 dimensions of the TCI scale of 63 individuals. I'm trying to do a variance component analysis for 7 dimensions in the end. But for now as a trial I want to set the 1st column in my data (header:NS) as a dependent variable and the other 6 as random effects & calculate their contributions.

(P.S. I am aware that this is quite different from what I was doing with my original code, sorry for the confusion)

So, is your question solved for now?

The problem with my previous script was just that the starting values implied an improper covariance matrix: a 7x7 matrix of all 7s.

Replacing this line

with these lines

fixes the starting values issue.

Are there any other parts I should change?

I really have no idea if there are parts you

shouldchange. It depends to a large extent on how the model you are specifying relates to the model you actually want to fit. I still don't know what model you'd like to fit and how this script relates to it.This warning is generally saying "The optimum solution doesn't really look right (non-convex Hessian); consequently, don't trust your standard errors; your model might not be identified.". In this case, my guess is the model you specified has little to do with the model you want to specify and little to do with any reasonable model for these data. We can't help you with that unless you give us more information.

For the purposes of clarity, we have solved your initial question: you no longer have a problem with dimnames.

If you have further questions relating to a model you'd like to fit, we will all be happy to help you with them. Please start a new thread with whatever that question is. If you do so, please be as specific as you can about the model you are trying to fit and what questions you have.