twin analysis 103
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/1.jpg)
1
Twin Analysis 103October 2010
![Page 2: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/2.jpg)
2
Specifications Continuous
mxMatrix mxAlgebra
CholMZ T1 T2 expCovMZ T1 T2
T1 #1 0 T1 var1 cov
T2 #2 #3 T2 cov var2
T1 T2
expMeanMZ
#4 #5
mzData selVars
fam bmi1 bmi2
1457 20 NA
1782 25 24
mxObjective
covariance=expCovMZ
means=expMeanMZ
dimnames=selVars
mxData observed=
mzData
type=raw
![Page 3: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/3.jpg)
3
MZ & DZ Twins Reared Together
MZ twins DZ twins
4 parameters
![Page 4: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/4.jpg)
4
-2LL df Chi2* df p AIC Chi2# df p
Sat 4055.9176
7
ADE 4063.4177
37.52 6 0.28
517.4
AE 4067.6177
311.73 7 0.11
519.6
1
ACE 4067.6177
311.73 6 0.07
521.6
CE 4220.3177
4164.3
77 0
672.3
152.6 1 0
E 4591.7177
5535.8
68 0
1041.7
524.1 2 0
Goodness-of-Fit
Chi2*: likelihood ratio test compared to saturated model
Chi2#: likelihood ratio test compared to ADE or ACE model
![Page 5: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/5.jpg)
5
a c e d a2 c2 e2 d2
Sat
ADE 0.57 0.41 0.54 0.32 0.17 0.29
AE 0.79 0.42 0.62 0.17
ACE 0.79 0 0.42 0.62 0 0.17
CE 0.68 0.56 0.46 0.32
E 0.88 0.78
Parameter Estimates
a2 , c2 etc. should be unstandardized variance components
![Page 6: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/6.jpg)
6
Specifications Binary
mxMatrix mxAlgebra
expCorMZ T1 T2
T1 1 0
T2 #2 1
T1 T2
expMeanMZ
0 0
expThreMZ
#4 #5mzDataBi
nselVars
fam ob1 ob2
1457 0 NA
1782 1 1mxObjective
covariance=expCorMZ
means=expMeanMZ
dimnames=selVars
thresholds=expThreMZ
mxData observed=
mzDataBin
type=raw
![Page 7: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/7.jpg)
7
Changes to OpenMx Code
mzDataBin[,1:2] <- mxFactor(mzDataBin[,1:2], levels = c(0:1))
# Constraint on variance of ordinal variablesmxConstraint( V== I, name="Var1"),
# Matrix & Algebra for expected means vectormxMatrix( "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" )
![Page 8: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/8.jpg)
8
-2LL df Chi2* df p AIC Chi2# df p
Sat
ADE 3
AE 4 1
ACE 3
CE 4 1
E 5 2
Goodness-of-Fit
Chi2*: likelihood ratio test compared to saturated model
Chi2#: likelihood ratio test compared to ADE or ACE model
![Page 9: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/9.jpg)
9
a c e d a2 c2 e2 d2
Sat
ADE
AE
ACE
CE
E
Parameter Estimates
a2 , c2 etc. should be unstandardized variance components
![Page 10: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/10.jpg)
10
Specifications Ordinal
mxMatrix mxAlgebra
expCorMZ T1 T2expThreM
Zth1t1 th1t2
T1 1 0 th2t1 th2t2
T2 #2 1 th3t1 th3t2
T1 T2 Inc 1 0 0
expMeanMZ
0 0 1 1 0
Thre #4 #5 1 1 1
#6 #7
#8 #9
mzDataOrd
selVars
fam ob1 ob2
1457 0 NA
1782 1 1mxObjective
covariance=expCorMZ
means=expMeanMZ
dimnames=selVars
thresholds=expThreMZ
mxData observed=
mzDataOrd
type=raw
![Page 11: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/11.jpg)
11
Heterogeneity
![Page 12: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/12.jpg)
12
•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 I
![Page 13: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/13.jpg)
13
•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 Questions II
![Page 14: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/14.jpg)
14
ComparisonConcordant for
group membershipDiscordant for
group membership
genderMZ & DZ:
MM & FF pairsDZ:
opposite sex pairs
ageMZ & DZ:
young & old pairs
nationalityMZ & DZ:
OZ & US pairs
environmentMZ & DZ:
urban & rural pairsMZ & DZ:
urban/ rural pairs
Groups
![Page 15: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/15.jpg)
15
Heterogeneity Modelsame sex pairs
![Page 16: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/16.jpg)
16
Homogeneity Modelsame sex pairs
![Page 17: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/17.jpg)
17
OS G1 G2 EP
Heterogeneity 12 a1 c1 e1 a2 c2 e2 6
Homogeneity 12 a1 c1 e1 a1 c1 e1 3
Models for Concordant Pairs
![Page 18: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/18.jpg)
18
Heterogeneity Twin Analysis
HetTwinQnMaRawCon.R
# Prepare Data and Print Summary Statistics# -----------------------------------------------------------------------data(twinData)summary(twinData)Vars <- 'bmi'nv <- 1selVars <- paste(Vars,c(rep(1,nv),rep(2,nv)),sep="") ntv <- nv*2mzfData <- 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")....
![Page 19: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/19.jpg)
19
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 componentsmxAlgebra( 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" ),
![Page 20: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/20.jpg)
20
inverse Standard Deviations
HetTwinQnMaRawCon.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"),
![Page 21: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/21.jpg)
21
5 expected Cov MatricesHetTwinQnMaRawCon.R
# Matrix & Algebra for expected means vectormxMatrix( "Full", 1, nv, free=TRUE, values= 20, label="mean", name="M" ),mxAlgebra( cbind(M,M), name="expMean"),
# Algebra for expected variance/covariance matrix in MZmxAlgebra( 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" )
),
![Page 22: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/22.jpg)
22
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"))
![Page 23: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/23.jpg)
23
Estimates male|female
HetTwinQnMaRawCon.R
univHetACEFit <- mxRun(univHetACEModel)univHetACESumm <- summary(univHetACEFit)
# Generate Heterogeneity ACE Output# -----------------------------------------------------------------------parameterSpecifications(univHetACEFit)expectedMeansCovariances(univHetACEFit)tableFitStatistics(univHetACEFit)
# Generate Table of Parameter Estimates using mxEvalpathEstimatesACE <- 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
![Page 24: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/24.jpg)
24
Automated OutputHetTwinQnMaRawCon.R
# Generate List of Parameter Estimates and Derived Quantities using formatOutputMatricesACEpathMatricesM <- 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)
![Page 25: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/25.jpg)
25
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)2
5
![Page 26: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/26.jpg)
26
Homogeneity Twin Analysis
HetTwinQnMaRawCon.R
# Generate Table of Parameter Estimates using mxEvalpathEstimatesACE <- 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')
pathEstimatesACEvarComponentsACE
# Generate List of Parameter Estimates and Derived Quantities using formatOutputMatricesformatOutputMatrices(univHomACEFit,ACEpathMatricesM,ACEpathLabelsM,4)formatOutputMatrices(univHomACEFit,ACEcovMatricesM,ACEcovLabelsM,4)
# Print Comparative Fit Statistics# -----------------------------------------------------------------------tableFitStatistics(univHetACEFit, univHomACEFit)
![Page 27: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/27.jpg)
27
General Modelsame & opposite sex pairs
27
![Page 28: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/28.jpg)
28
OS G1 G2 EP
Heterogeneity 15 a1 c1 e1 a2 c2 e2 6
Homogeneity 15 a1 c1 e1 a1 c1 e1 3
General I II
1515
a1 c1 e1
a1 c1 e1
a2 c2 e2 rg
a2 c2 e2 rc
77
Models for Concordant and Discordant Pairs
![Page 29: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/29.jpg)
29
•Homogeneity Model:
• no quantitative, no qualitative differences
•Heterogeneity Model:
• quantitative but no qualitative differences
•General Model:
• quantitative and qualitative differences
Summary of Models
![Page 30: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/30.jpg)
30
Moderated Model
![Page 31: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/31.jpg)
31
Moderated Twin AnalysisModTwinMaRawCon.R
# Prepare Data# -----------------------------------------------------------------------data(twinData)summary(twinData)oneVars <- 'bmi'nv <- 1selVars <- paste(Vars,c(rep(1,nv),rep(2,nv)),sep="") ntv <- nv*2twinData[,'age'] <- twinData[,'age']/100mzData <- 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")
![Page 32: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/32.jpg)
32
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 coefficientsmxMatrix( "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 vectormxMatrix( "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" ),
![Page 33: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/33.jpg)
33
Moderated VarComponents
ModTwinMaRawCon.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 agemxMatrix( "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" ) ),
![Page 34: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/34.jpg)
34
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 MZmxAlgebra( 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 & ObjectivemxData( observed=mzData, "raw" ),mxFIMLObjective( "expCovMZ", "expMean", selVars )
),
![Page 35: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/35.jpg)
35
Definition VariableModTwinMaRawCon.R
mxModel("DZ", mxMatrix( "Full", 1, 1, free=FALSE, labels=c("data.age"), name="Age"),
# Matrices A, C, and E compute variance componentsmxAlgebra( (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 DZmxAlgebra( 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 & ObjectivemxData( observed=dzData, "raw" ),mxFIMLObjective( "expCovDZ", "expMean", selVars )
),mxAlgebra( MZ.objective + DZ.objective, name="minus2sumloglikelihood" ),mxAlgebraObjective("-2sumll"))
![Page 36: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/36.jpg)
36
Estimated ace|moderated
ModTwinMaRawCon.R
univModMeanslqACEFit <- mxRun(univModMeanslqACEModel)univModMeanslqACESumm <- summary(univModMeanslqACEFit)
# Generate Moderated ACE Output# -----------------------------------------------------------------------parameterSpecifications(univModMeanslqACEFit)expectedMeansCovariances(univModMeanslqACEFit)tableFitStatistics(univModMeanslqACEFit)
# Generate Table of Parameter Estimates using mxEvalpathEstimatesACE <- 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
![Page 37: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/37.jpg)
37
AutomatedModTwinMaRawCon.R
# Generate List of Parameter Estimates and Derived Quantities using formatOutputMatricesACEpathMatrices <- 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)
![Page 38: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/38.jpg)
38
Quantities by AgeModTwinMaRawCon.R
# Generate Quantities by AgeestByAge <- 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)
![Page 39: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/39.jpg)
39
LinearQuadratic Regression
ModTwinMaRawCon.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)
![Page 40: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/40.jpg)
40
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)
![Page 41: Twin Analysis 103](https://reader030.vdocuments.net/reader030/viewer/2022033022/56812b40550346895d8f57b5/html5/thumbnails/41.jpg)
41
Fit StatisticsModTwinMaRawCon.R
# Generate Table of Parameter Estimates using mxEvalpathEstimatesACE <- 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')pathEstimatesACEvarComponentsACE
# Print Comparative Fit Statistics# -----------------------------------------------------------------------univModACENested <- c(univModMeanslACEFit,univModACEFit,univUnModACEFit)tableFitStatistics(univModMeanslqACEFit,univModACENested)tableFitStatistics(univModACEFit, univUnModACEFit)