410 likes | 554 Views
Twin Analysis 103. October 2010. Specifications Continuous. MZ & DZ Twins Reared Together. MZ twins DZ twins. 4 parameters. Goodness-of-Fit. Chi 2*: likelihood ratio test compared to saturated model Chi 2#: likelihood ratio test compared to ADE or ACE model.
E N D
Twin Analysis 103 • October 2010
MZ & DZ Twins Reared Together • MZ twins DZ twins 4 parameters
Goodness-of-Fit Chi2*: likelihood ratio test compared to saturated model Chi2#: likelihood ratio test compared to ADE or ACE model
Parameter Estimates a2 , c2 etc. should be unstandardized variance components
Changes to OpenMx Code • mzDataBin[,1:2] <- mxFactor(mzDataBin[,1:2], levels = c(0:1)) • # Constraint on variance of ordinal variables • mxConstraint( V== I, name="Var1"), • # Matrix & Algebra for expected means vector • mxMatrix( "Zero", 1, ntv, name="expMeanMZ" ), • # Matrix & Algebra for expected thresholds • # Binary • mxMatrix( "Full", 1, nv, free=TRUE, values=.8, label="thre", name="Thre" ), • mxAlgebra( cbind(Th,Th), dimnames=list('th1',selVars), name="expThre" ), • # Ordinal • mxMatrix( "Full", nth, ntv, free=T, values=thValues, lbound=thLBound, name="Thre"), • mxMatrix( "Lower", nth, nth, free=FALSE, values=1, name="Inc" ), • mxAlgebra( expression= Inc %*% Thre, name="ThreInc"), • mxAlgebra( cbind(ThreInc,ThreInc),dimnames=list(thRows,selVars),name="expThreMZ" ), • # Objective • mxFIMLObjective( "ACE.expCovMZ", "ACE.expMean", selVars, thresholds="ACE.expThre" )
Goodness-of-Fit Chi2*: likelihood ratio test compared to saturated model Chi2#: likelihood ratio test compared to ADE or ACE model
Parameter Estimates a2 , c2 etc. should be unstandardized variance components
Heterogeneity Questions I • Univariate Analysis: What are the contributions of additive genetic, dominance/shared environmental and unique environmental factors to the variance? • Are the contributions of genetic and environmental factors equal for different groups, such as sex, race, ethnicity, SES, environmental exposure, etc.?
Heterogeneity Questions II • Are these differences due to differences in the magnitude of the effects (quantitative)? • e.g. Is the contribution of genetic/environmental factors greater/smaller in males than in females? • Are the differences due to differences in the nature of the effects (qualitative)? • e.g. Are there different genetic/environmental factors influencing the trait in males and females?
Heterogeneity Twin AnalysisHetTwinQnMaRawCon.R • # Prepare Data and Print Summary Statistics • # ----------------------------------------------------------------------- • data(twinData) • summary(twinData) • Vars <- 'bmi' • nv <- 1 • selVars <- paste(Vars,c(rep(1,nv),rep(2,nv)),sep="") • ntv <- nv*2 • mzfData <- subset(twinData, zyg==1, selVars) • dzfData <- subset(twinData, zyg==3, selVars) • mzmData <- subset(twinData, zyg==2, selVars) • dzmData <- subset(twinData, zyg==4, selVars) • colMeans(mzfData,na.rm=TRUE) • .... • cov(mzfData,use="complete") • ....
ACE males/ femalesHetTwinQnMaRawCon.R • # Fit Heterogeneity ACE Model with RawData and Matrices Input • # ----------------------------------------------------------------------- • univHetACEModel <- mxModel("univHetACE", • mxModel("ACE", • # Matrices a, c, and e to store a, c, and e path coefficients • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="am11", name="am" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="cm11", name="cm" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="em11", name="em" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="af11", name="af" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="cf11", name="cf" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="ef11", name="ef" ), • # Matrices A, C, and E compute variance components • mxAlgebra( am %*% t(am), name="Am" ), • mxAlgebra( cm %*% t(cm), name="Cm" ), • mxAlgebra( em %*% t(em), name="Em" ), • mxAlgebra( am %*% t(am), name="Af" ), • mxAlgebra( cm %*% t(cm), name="Cf" ), • mxAlgebra( em %*% t(em), name="Ef" ),
inverse Standard DeviationsHetTwinQnMaRawCon.R • # Algebra to compute total variances and standard deviations (diagonal only) • mxAlgebra( Am+Cm+Em, name="Vm" ), • mxAlgebra( Af+Cf+Ef, name="Vf" ), • mxMatrix( "Iden", nv, nv, name="I"), • mxAlgebra( solve(sqrt(I*Vm)), name="isdm"), • mxAlgebra( solve(sqrt(I*Vf)), name="isdf"),
5 expected Cov MatricesHetTwinQnMaRawCon.R • # Matrix & Algebra for expected means vector • mxMatrix( "Full", 1, nv, free=TRUE, values= 20, label="mean", name="M" ), • mxAlgebra( cbind(M,M), name="expMean"), • # Algebra for expected variance/covariance matrix in MZ • mxAlgebra( rbind ( cbind(Am+Cm+Em , Am+Cm), • cbind(Am+Cm , Am+Cm+Em)), name="expCovMZm" ), • mxAlgebra( rbind ( cbind(Af+Cf+Ef , Af+Cf), • cbind(Af+Cf , Af+Cf+Ef)), name="expCovMZf" ), • # Algebra for expected variance/covariance matrix in DZ; 0.5, converted to 1*1 matrix • mxAlgebra( rbind ( cbind(Am+Cm+Em , 0.5%x%Am+Cm), • cbind(0.5%x%Am+Cm , Am+Cm+Em)), name="expCovDZm" ), • mxAlgebra( rbind ( cbind(Af+Cf+Ef , 0.5%x%Af+Cf), • cbind(0.5%x%Af+Cf , Af+Cf+Ef)), name="expCovDZf" ) • ),
5 Data GroupsHetTwinQnMaRawCon.R • mxModel("MZm", • mxData( observed=mzmData, "raw" ), • mxFIMLObjective( ="ACE.expCovMZm", "ACE.expMean", selVars )), • mxModel("DZm", • mxData( observed=dzmData, "raw" ), • mxFIMLObjective( "ACE.expCovDZm", "ACE.expMean", selVars )), • mxModel("MZf", • mxData( observed=mzfData, "raw" ), • mxFIMLObjective( "ACE.expCovMZf", "ACE.expMean", selVars )), • mxModel("DZf", • mxData( observed=dzfData, "raw" ), • mxFIMLObjective( "ACE.expCovDZf", "ACE.expMean", selVars )), • mxAlgebra( MZm.objective + DZm.objective + MZf.objective + DZf.objective, • name="-2sumll" ), • mxAlgebraObjective("-2sumll"))
Estimates male|femaleHetTwinQnMaRawCon.R • univHetACEFit <- mxRun(univHetACEModel) • univHetACESumm <- summary(univHetACEFit) • # Generate Heterogeneity ACE Output • # ----------------------------------------------------------------------- • parameterSpecifications(univHetACEFit) • expectedMeansCovariances(univHetACEFit) • tableFitStatistics(univHetACEFit) • # Generate Table of Parameter Estimates using mxEval • pathEstimatesACE <- • round(mxEval(cbind(ACE.am,ACE.cm,ACE.em,ACE.af,ACE.cf,ACE.ef), univHetACEFit),4) • varComponentsACE <- round(mxEval(cbind(ACE.Am/ACE.Vm,ACE.Cm/ACE.Vm, • ACE.Em/ACE.Vm,ACE.Af/ACE.Vf,ACE.Cf/ACE.Vf,ACE.Ef/ACE.Vf), univHetACEFit),4) • rownames(pathEstimatesACE) <- 'pathEstimates' • colnames(pathEstimatesACE) <- c('am','cm','em','af','cf','ef') • rownames(varComponentsACE) <- 'varComponents' • colnames(varComponentsACE) <- c('am^2','cm^2','em^2','af^2','cf^2','ef^2') • pathEstimatesACE; varComponentsACE
Automated OutputHetTwinQnMaRawCon.R • # Generate List of Parameter Estimates and Derived Quantities using formatOutputMatrices • ACEpathMatricesM <- c("ACE.am","ACE.cm","ACE.em", • "ACE.isdm","ACE.isdm %*% ACE.am","ACE.isdm %*% ACE.cm","ACE.isdm %*% ACE.em") • ACEpathLabelsM <- c("pathEst_am","pathEst_cm","pathEst_em", • "sdm","stPathEst_am","stPathEst_cm","stPathEst_em") • ACEpathMatricesF <- c("ACE.af",....) • ACEpathLabelsF <- c("pathEst_af",....) • formatOutputMatrices(univHetACEFit,ACEpathMatricesM,ACEpathLabelsM,4) • formatOutputMatrices(univHetACEFit,ACEpathMatricesF,ACEpathLabelsF,4) • ACEcovMatricesM <- c("ACE.Am","ACE.Cm","ACE.Em", • "ACE.Vm","ACE.Am/ACE.Vm","ACE.Cm/ACE.Vm","ACE.Em/ACE.Vm") • ACEcovLabelsM <- c("covComp_Am","covComp_Cm","covComp_Em", • "Varm","stCovComp_Am","stCovComp_Cm","stCovComp_Em") • ACEcovMatricesF <- c("ACE.Af",....) • ACEcovLabelsF <- c("covComp_Af",....) • formatOutputMatrices(univHetACEFit,ACEcovMatricesM,ACEcovLabelsM,4) • formatOutputMatrices(univHetACEFit,ACEcovMatricesF,ACEcovLabelsF,4)
Equate Labels 2 constrainHetTwinQnMaRawCon.R • # Fit Homogeneity ACE Model with RawData and Matrices Input • # ----------------------------------------------------------------------- • univHomACEModel <- mxModel(univHetACEFit, name="univHomACE", • mxModel(univHetACEFit$ACE, • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="a11", name="am" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="c11", name="cm" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="e11", name="em" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="a11", name="af" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="c11", name="cf" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="e11", name="ef" ) ) • ) • univHomACEFit <- mxRun(univHomACEModel) • univHomACESumm <- summary(univHomACEFit) • # Generate Homogeneity ACE Output • # ----------------------------------------------------------------------- • parameterSpecifications(univHomACEFit) • expectedMeansCovariances(univHomACEFit) • tableFitStatistics(univHomACEFit) 25
Homogeneity Twin AnalysisHetTwinQnMaRawCon.R • # Generate Table of Parameter Estimates using mxEval • pathEstimatesACE <- round(mxEval(cbind(ACE.am,ACE.cm,ACE.em), univHomACEFit),4) • varComponentsACE <- round(mxEval(cbind(ACE.Am/ACE.Vm,ACE.Cm/ACE.Vm, • ACE.Em/ACE.Vm), univHomACEFit),4) • rownames(pathEstimatesACE) <- 'pathEstimates' • colnames(pathEstimatesACE) <- c('a','c','e') • rownames(varComponentsACE) <- 'varComponents' • colnames(varComponentsACE) <- c('a^2','c^2','e^2') • pathEstimatesACE • varComponentsACE • # Generate List of Parameter Estimates and Derived Quantities using formatOutputMatrices • formatOutputMatrices(univHomACEFit,ACEpathMatricesM,ACEpathLabelsM,4) • formatOutputMatrices(univHomACEFit,ACEcovMatricesM,ACEcovLabelsM,4) • # Print Comparative Fit Statistics • # ----------------------------------------------------------------------- • tableFitStatistics(univHetACEFit, univHomACEFit)
Summary of Models • Homogeneity Model: • no quantitative, no qualitative differences • Heterogeneity Model: • quantitative but no qualitative differences • General Model: • quantitative and qualitative differences
Moderated Twin AnalysisModTwinMaRawCon.R • # Prepare Data • # ----------------------------------------------------------------------- • data(twinData) • summary(twinData) • oneVars <- 'bmi' • nv <- 1 • selVars <- paste(Vars,c(rep(1,nv),rep(2,nv)),sep="") • ntv <- nv*2 • twinData[,'age'] <- twinData[,'age']/100 • mzData <- as.data.frame(subset(twinData, zyg==7, c(bmi1,bmi2,age))) • dzData <- as.data.frame(subset(twinData, zyg==9, c(bmi1,bmi2,age))) • colMeans(mzData,na.rm=TRUE) • colMeans(dzData,na.rm=TRUE) • cov(mzData,use="complete") • cov(dzData,use="complete")
Moderated Means - bModTwinMaRawCon.R • # Fit Moderated ACE Model + Linear & Quadratic Moderated Means • # ----------------------------------------------------------------------- • univModMeanslqACEModel <- mxModel("univModMeanslqACE", • mxModel("ACE", • # Matrices a, c, and e to store a, c, and e path coefficients • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="a11", name="a" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="c11", name="c" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="e11", name="e" ), • # Matrices a, c, and e to store moderated a, c, and e path coefficients • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="aI11", name="aI" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="cI11", name="cI" ), • mxMatrix( "Full", nv, nv, free=TRUE, values=.6, label="eI11", name="eI" ), • # Matrix & Algebra for expected means vector • mxMatrix( "Full", 1, nv, free=TRUE, values= 20, label="mean", name="M" ), • mxMatrix( "Full", 1, 2, free=TRUE, values=.01, label=c("l11","q11"), name="b" ),
Moderated VarComponentsModTwinMaRawCon.R • # Matrices A, C, and E compute non-moderated variance components • mxAlgebra( a %*% t(a), name="A" ), • mxAlgebra( c %*% t(c), name="C" ), • mxAlgebra( e %*% t(e), name="E" ), • # Algebra to compute total variances and inverse of standard deviations (diagonal only) • mxAlgebra( A+C+E, name="V" ), • mxMatrix( "Iden", nv, nv, name="I"), • mxAlgebra( solve(sqrt(I*V)), name="isd"), • # Matrices & Algebra to plot means by age • mxMatrix( "Full", 5, 1, values=c(.3,.4,.5,.6,.7), name="Ages"), • mxMatrix( "Full", 2, 5, values=c(.3,.09,.4,.16,.5,.25,.6,.36,.7,.49), name="Agelq"), • mxMatrix( "Unit", 5, 1, name="u"), • mxAlgebra( unit%x%M+ t(b%*%Agelq), name="MI"), • mxAlgebra( diag2vec((u%x%a+ Ages%x%aI) %*% t(u%x%a+ Ages%x%aI)), name="AI" ), • mxAlgebra( diag2vec((u%x%c+ Ages%x%cI) %*% t(u%x%c+ Ages%*%cI)), name="CI" ), • mxAlgebra( diag2vec((u%x%e+ Ages%x%eI) %*% t(u%x%e+ Ages%*%eI)), name="EI" ), • mxAlgebra( AI+CI+EI, name="VI" ), • mxAlgebra( cbind(MI,AI,CI,EI,VI), name="estByAge" ), • mxAlgebra( cbind(MI,AI/VI,CI/VI,EI/VI,VI), name="stEstByAge" )),
Algebra in MZ modelModTwinMaRawCon.R • mxModel("MZ", • # Matrix for moderating/interacting variable • mxMatrix( "Full", 1, 1, free=FALSE, labels=c("data.age"), name="Age"), • # Matrices A, C, and E compute variance components • mxAlgebra( (ACE.a+ Age%*%ACE.aI) %*% t(ACE.a+ Age%*%ACE.aI), name="A" ), • mxAlgebra( (ACE.c+ Age%*%ACE.cI) %*% t(ACE.c+ Age%*%ACE.cI), name="C" ), • mxAlgebra( (ACE.e+ Age%*%ACE.eI) %*% t(ACE.e+ Age%*%ACE.eI), name="E" ), • # Algebra for expected variance/covariance matrix and expected mean vector in MZ • mxAlgebra( rbind ( cbind(A+C+E , A+C), • cbind(A+C , A+C+E)), name="expCovMZ" ), • mxAlgebra( ACE.b%*%rbind(Age,Age^2), name="AgeR"), • mxAlgebra( cbind((ACE.M + AgeR),(ACE.M + AgeR)), name="expMean"), • # Data & Objective • mxData( observed=mzData, "raw" ), • mxFIMLObjective( "expCovMZ", "expMean", selVars ) • ),
Definition VariableModTwinMaRawCon.R • mxModel("DZ", • mxMatrix( "Full", 1, 1, free=FALSE, labels=c("data.age"), name="Age"), • # Matrices A, C, and E compute variance components • mxAlgebra( (ACE.a+Age%*%ACE.aI) %*% t(ACE.a+Age%*%ACE.aI), name="A" ), • mxAlgebra( (ACE.c+Age%*%ACE.cI) %*% t(ACE.c+Age%*%ACE.cI), name="C" ), • mxAlgebra( (ACE.e+Age%*%ACE.eI) %*% t(ACE.e+Age%*%ACE.eI), name="E" ), • # Algebra for expected variance/covariance matrix in DZ • mxAlgebra( rbind ( cbind(A+C+E , 0.5%x%A+C), • cbind(0.5%x%A+C , A+C+E)), name="expCovDZ" ), • mxAlgebra( ACE.b%*%rbind(Age,Age^2), name="AgeR"), • mxAlgebra( cbind((ACE.M + AgeR),(ACE.M + AgeR)), name="expMean"), • # Data & Objective • mxData( observed=dzData, "raw" ), • mxFIMLObjective( "expCovDZ", "expMean", selVars ) • ), • mxAlgebra( MZ.objective + DZ.objective, name="minus2sumloglikelihood" ), • mxAlgebraObjective("-2sumll"))
Estimated ace|moderatedModTwinMaRawCon.R • univModMeanslqACEFit <- mxRun(univModMeanslqACEModel) • univModMeanslqACESumm <- summary(univModMeanslqACEFit) • # Generate Moderated ACE Output • # ----------------------------------------------------------------------- • parameterSpecifications(univModMeanslqACEFit) • expectedMeansCovariances(univModMeanslqACEFit) • tableFitStatistics(univModMeanslqACEFit) • # Generate Table of Parameter Estimates using mxEval • pathEstimatesACE <- round( • mxEval(cbind(ACE.a,ACE.c,ACE.e,ACE.aI,ACE.cI,ACE.eI), univModMeanslqACEFit),4) • varComponentsACE <- round( • mxEval(cbind(ACE.A/ACE.V,ACE.C/ACE.V,ACE.E/ACE.V), univModMeanslqACEFit),4) • rownames(pathEstimatesACE) <- 'pathEstimates' • colnames(pathEstimatesACE) <- c('a','c','e','aI','cI','eI') • rownames(varComponentsACE) <- 'varComponents' • colnames(varComponentsACE) <- c('a^2','c^2','e^2') • pathEstimatesACE; varComponentsACE 36
AutomatedModTwinMaRawCon.R • # Generate List of Parameter Estimates and Derived Quantities using formatOutputMatrices • ACEpathMatrices <- c("ACE.a","ACE.c","ACE.e", • "ACE.isd","ACE.isd %*% ACE.a","ACE.isd %*% ACE.c","ACE.isd %*% ACE.e") • ACEpathLabels <- c("pathEst_a","pathEst_c","pathEst_e", • "sd","stParEst_a","stPathEst_c","stPathEst_e") • formatOutputMatrices(univModMeanslqACEFit,ACEpathMatrices,ACEpathLabels,4) • ACEpathMatricesI <- c("ACE.aI","ACE.cI","ACE.eI","ACE.isdI") • ACEpathLabelsI <- c("pathEst_aI","pathEst_cI","pathEst_eI") • formatOutputMatrices(univModMeanslqACEFit,ACEpathMatricesI,ACEpathLabelsI,4) • ACEcovMatrices <- c("ACE.A","ACE.C","ACE.E", • "ACE.V","ACE.A/ACE.V","ACE.C/ACE.V","ACE.E/ACE.V") • ACEcovLabels <- c("covComp_A","covComp_C","covComp_E", • "Var","stCovComp_A","stCovComp_C","stCovComp_E") • formatOutputMatrices(univModMeanslqACEFit,ACEcovMatrices,ACEcovLabels,4)
Quantities by AgeModTwinMaRawCon.R • # Generate Quantities by Age • estByAge <- mxEval(ACE.estByAge,univModMeanslqACEFit) • stEstByAge <- mxEval(ACE.stEstByAge,univModMeanslqACEFit) • rowsEstByAge <- c("Age30","Age40","Age50","Age60","Age70") • colsEstByAge <- c("MI","AI","CI","EI","VI") • formatMatrix(estByAge,list(rowsEstByAge,colsEstByAge),4) • formatMatrix(stEstByAge,list(rowsEstByAge,colsEstByAge),4)
LinearQuadratic RegressionModTwinMaRawCon.R • # Fit Moderated ACE model + Linear Moderated Means • # ----------------------------------------------------------------------- • univModMeanslACEModel <- mxModel(univModMeanslqACEFit, name="univModMeanslACE", • mxModel(univModMeanslqACEFit$ACE, • mxMatrix( "Full", 1, 2, free=c(T,F), values=c(.01,0), label=c("l11","q11"), name="b" ) • ) • ) • univModMeanslACEFit <- mxRun(univModMeanslACEModel) • # Fit Moderated ACE model + no Moderated Means • # ----------------------------------------------------------------------- • univModACEModel <- mxModel(univModMeanslACEFit, name="univModACE", • mxModel(univModMeanslACEFit$ACE, • mxMatrix( "Full", 1, 2, free=F, values=0, label=c("l11","q11"), name="b" ) • ) • ) • univModACEFit <- mxRun(univModACEModel)
UnModeratedModTwinMaRawCon.R • # Fit non-Moderated ACE model • # ----------------------------------------------------------------------- • univUnModACEModel <- mxModel(univModACEFit, name="univUnModACE", • mxModel(univModACEFit$ACE, • mxMatrix( "Full", 1, 1, free=F, values=0, label="aI11", name="aI" ), • mxMatrix( "Full", 1, 1, free=F, values=0, label="cI11", name="cI" ), • mxMatrix( "Full", 1, 1, free=F, values=0, label="eI11", name="eI" ) • ) • ) • univUnModACEFit <- mxRun(univUnModACEModel) • univUnModACESumm <- summary(univUnModACEFit) • # Generate UnModerated ACE Output • # ----------------------------------------------------------------------- • parameterSpecifications(univUnModACEFit) • expectedMeansCovariances(univUnModACEFit)
Fit StatisticsModTwinMaRawCon.R • # Generate Table of Parameter Estimates using mxEval • pathEstimatesACE <- round( • mxEval(cbind(ACE.a,ACE.c,ACE.e,ACE.aI,ACE.cI,ACE.eI), univUnModACEFit),4) • varComponentsACE <- round( • mxEval(cbind(ACE.A/ACE.V,ACE.C/ACE.V,ACE.E/ACE.V), univUnModACEFit),4) • rownames(pathEstimatesACE) <- 'pathEstimates' • colnames(pathEstimatesACE) <- c('a','c','e','aI','cI','eI') • rownames(varComponentsACE) <- 'varComponents' • colnames(varComponentsACE) <- c('a^2','c^2','e^2','aI^2','cI^2','eI^2') • pathEstimatesACE • varComponentsACE • # Print Comparative Fit Statistics • # ----------------------------------------------------------------------- • univModACENested <- c(univModMeanslACEFit,univModACEFit,univUnModACEFit) • tableFitStatistics(univModMeanslqACEFit,univModACENested) • tableFitStatistics(univModACEFit, univUnModACEFit)