You are here

genEpi Helper Functions

4 posts / 0 new
Last post
James Sherlock's picture
Offline
Joined: 06/03/2014 - 01:45
genEpi Helper Functions

I'm trying to pull out estimates in a matrix using genEpi helper functions in a trivariate model with a sibling but I'm running into some trouble with the genEpi_FormatOutputMatrices function.

Error:
Error in print(genEpi_FormatOutputMatrix(matrix = genEpi_EvalQuote(expstring = matricesList[[k]], :
error in evaluating the argument 'x' in selecting a method for function 'print': Error: The following error occurred while evaluating the expression 'iSD %*% a' in model 'CholACE' : requires numeric/complex matrix/vector arguments

Full Script is below

require(OpenMx)
require(psych)
source("myFunctions.R")
source("http://openmxhelpers.googlecode.com/svn/trunk/GenEpiHelperFunctions.R")

# --------------------------------------------------------------------
# PREPARE DATA

# Load Data
data

head(data)
describe(data)

data$twin1age data$twin2age data$sibage data$moral1 data$moral2 data$sibdm data$path1 data$path2 data$sibdp data$sexual1 data$sexual2 data$sibds data$zyg head(data)

# Select Variables for Analysis
Vars nv nsib ntv

selVars 'moral2','path2','sexual2',
'sibdm','sibdp','sibds')

defVars useVars

#Subset data for testing
mzdata dzdata describe(mzdata, skew=F)
describe(dzdata, skew=F)
dim(mzdata)
dim(dzdata)
cov(mzdata,use="complete")
cov(dzdata,use="complete")
cor(mzdata,use="complete")
cor(dzdata,use="complete")

# ------------------------------------------------------------------------------
# Cholesky Decomposition ACE Model
# ------------------------------------------------------------------------------
# Set Starting Values
svMe svPa lbPa

# Matrices declared to store a, c, and e Path Coefficients
pathA values=svPa, labels=labLower("a",nv), lbound=lbPa, name="a" )
pathC values=svPa, labels=labLower("c",nv), lbound=lbPa, name="c" )
pathE values=svPa, labels=labLower("e",nv), lbound=lbPa, name="e" )

# Matrices generated to hold A, C, and E computed Variance Components
covA covC covE

# Algebra to compute total variances and standard deviations (diagonal only)
covP matI inSD

# Algebra for expected Mean and Variance/Covariance Matrices in MZ & DZ twins
# Algebra for expected Mean Matrices in MZ & DZ twins
#MeanG (grand mean) also known as the intercept
#only supplied one label - will be provided to both matrix elements and will supply same value
#Want intercept to be added to beta * age - regression outcome

defAge labels=c('data.twin1age','data.twin2age','data.sibage'),name='Age')

pathB label="b11", name="b")

mean values=svMe, labels=labFull("me",1,nv), name="mean" )

expMean

#Covariance Matricies
covMZ cbind(A+C, V, .5%x%A+C),
cbind(.5%x%A+C, .5%x%A+C, V)),
name="expCovMZ" )

covDZ cbind(.5%x%A+C, V, .5%x%A+C),
cbind(.5%x%A+C, .5%x%A+C, V)),
name="expCovDZ" )

# Data objects for Multiple Groups
dataMZ dataDZ

# Objective objects for Multiple Groups
objMZ objDZ

# Combine Groups
pars modelMZ modelDZ minus2ll obj CholAceModel

# ------------------------------------------------------------------------------
# RUN GENETIC MODEL

# Run Cholesky Decomposition ACE model
CholAceFit CholAceSumm

mxCompare(twinSatFit,CholAceFit)
mxCompare(eqMeVaZygFit,CholAceFit)

#Generate list of parameter estimates and derived quantities using formatOutputMatrices
# ACE standardized Path Coefficients (pre-multiplied by inverse of standard deviations)
CholACEpathMatrices CholACEpathLabels #genEpi_FormatOutputMatrix(matrix,label,vars,digits)
genEpi_FormatOutputMatrices(CholAceFit,CholACEpathMatrices,CholACEpathLabels,Vars,4)

RobK's picture
Offline
Joined: 04/19/2011 - 21:00
The objects you are asking to

The objects you are asking to be multiplied together are not in the fitted supermodel, CholAceFit, but in the submodels. There are a few small changes you could make to get the result you want.

One possibility is to put certain objects from pars back into the supermodel. I think they would be pathA, pathC, pathE, covA, covC, covE, covP, matI, and invSD. Then, your call to genEpi_FormatOutputMatrices() should work as-is.

Another possibility is to replace
CholACEpathMatrices <- c("iSD %*% a","iSD %*% c","iSD %*% e")
with (say)
CholACEpathMatrices <- c("MZ.iSD %*% MZ.a","MZ.iSD %*% MZ.c","MZ.iSD %*% MZ.e")

A third possibility, and probably the easiest, is to change
genEpi_FormatOutputMatrices(CholAceFit,CholACEpathMatrices,CholACEpathLabels,Vars,4)
to (say)
genEpi_FormatOutputMatrices(CholAceFit$MZ,CholACEpathMatrices,CholACEpathLabels,Vars,4)

James Sherlock's picture
Offline
Joined: 06/03/2014 - 01:45
problem solved

Thanks so much for your help Rob!

RobK's picture
Offline
Joined: 04/19/2011 - 21:00
You're welcome

No problem! It's partly my fault you got this error in the first place: I told you to take pars out of the supermodel entirely in that other thread, which was a bit of overkill, since the definition-variables problem could have been solved in any way that kept defAge out of the supermodel.

Log in or register to post comments