Attachment | Size |
---|---|
pheno2.csv [6] | 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