Hi,
I couldn't find any existing OpenMx codes to conduct bivariate genetic modelling for ordinal variables with covariates, so I've adapted Hermine Mae's twoACEvo.R code (bivariate ACE model for ordinal variables) by adding covariates to the code. I thought it was quite straightforward, but when I ran the code I got the following error:
Error in as.vector(data) : no method for coercing this S4 class to a vector
If it helps, I have included a segment of my code with how I incorporated the covariates below. Any advice or comments will be greatly appreciated (or perhaps point me to some other relevant codes to adapt)! Thanks!
# Matrix for moderating/interacting variable defSex <- mxMatrix( type="Full", nrow=1, ncol=2, free=FALSE, labels=c("data.Sex1","data.Sex2"), name="Sex") # Matrices declared to store linear Coefficients for covariate B_Sex <- mxMatrix( type="Full", nrow=nth, ncol=2, free=c(F,T), values= c(0,.1), label=c('bSexV1','bSexV2'), name="bSex", byrow = TRUE) meanSex <- mxAlgebra( bSex%x%Sex, name="SexR") #age defAge <- mxMatrix( type="Full", nrow=1, ncol=2, free=FALSE, labels=c("data.Age1","data.Age2"), name="Age") # Matrices declared to store linear Coefficients for covariate B_Age <- mxMatrix( type="Full", nrow=nth, ncol=2, free=c(T,F), values= c(.01,0), label=c('bAgeV1','bAgeV2'), name="bAge", byrow = TRUE) meanAge <- mxAlgebra( bAge%x%Age, name="AgeR") #YrsEd defYEd <- mxMatrix( type="Full", nrow=1, ncol=2, free=FALSE, labels=c("data.yrsEd1","data.yrsEd2"), name="YEd") # Matrices declared to store linear Coefficients for covariate B_YEd <- mxMatrix( type="Full", nrow=nth, ncol=2, free=c(T,F), values= c(.01,0), labels=c('bYEdV1','bYEdV2'), name="bYEd", byrow = TRUE) meanYEd <- mxAlgebra( bYEd%x%YEd, name="YEdR") #Age-related hearing condition defHearing <- mxMatrix( type="Full", nrow=1, ncol=2, free=FALSE, labels=c("data.AHearing1","data.AHearing2"), name="Hearing") # Matrices declared to store linear Coefficients for covariate B_Hearing <- mxMatrix( type="Full", nrow=nth, ncol=2, free=TRUE, values= .01, labels=c('bAHearV1','bAHearV2'), name="bHearing", byrow = TRUE) meanHearing <- mxAlgebra( bHearing%x%Hearing, name="HearingR") #*************************************************************** defs <- list( defSex, B_Sex, meanSex, defAge, B_Age, meanAge, defYEd, B_YEd, meanYEd, defHearing, B_Hearing, meanHearing) #setting up the regression # Matrix & Algebra for expected means vector and expected thresholds meanG <- mxMatrix( type="Zero", nrow=1, ncol=ntv, name="expMean" ) threG <- mxMatrix( type="Full", nrow=nth, ncol=ntv, free=TRUE, values=svTh, lbound=lbTh, labels=labThZ, name="Thre" ) inc <- mxMatrix( type="Lower", nrow=nth, ncol=nth, free=FALSE, values=1, name="Inc" ) threT <- mxAlgebra( expression = Inc %*% Thre, name="expThre" ) threC <- mxAlgebra( expression = expThre + AgeR + SexR + YEdR + HearingR, name = "expThreC") #with covariates
# Create Expectation Objects for Multiple Groups expMZ <- mxExpectationNormal( covariance="expCovMZ", means="expMean", dimnames=c('Vars1','PVars1','Vars2','PVars2'), thresholds="expThreC" ) expDZ <- mxExpectationNormal( covariance="expCovDZ", means="expMean", dimnames=c('Vars1','PVars1','Vars2','PVars2'), thresholds="expThreC" ) funML <- mxFitFunctionML()