!
! Joint analysis of twin-register and hospital samples
! MD by DSM-III Broad Symptoms
! First 4 groups are calculation, then 4 data, then 1 constraint
!
Title - calculate additive genetic variance
Data Calculation NGroups=9   ! 4 calc, 4 data, and 1 constraint group
Matrices
A Full 1 1 Free ! This will be parameter a
Compute A*A' /  ! This computes a-squared
End

Title - calculate common environment variance
Data Calculation 
Matrices
C Full 1 1 Free ! This will be parameter c
Compute C*C' /  ! This computes c-squared
End

Title - calculate specific environment variance
Data Calculation 
Matrices
E Full 1 1 Free ! This will be parameter e
Compute E*E' /  ! This computes e-squared
End

Title - calculate dominance genetic variance
Data Calculation 
Matrices
D Full 1 1      ! This will be parameter d
Compute D*D' /  ! This computes d-squared
End

Swedish Sample - MZ Twins ascertained from twin register
Data Ninput=2             ! two variables: liabilities of twin 1 and 2
CTable 2 2                ! read 2x2 contingency table
68 10                     ! observed cell frequencies
 7 12
Matrices                  ! define matrices for thresholds & covariances
A Full 1 1 =%E1           ! additive genetic  *variance* computed in group 1
C Full 1 1 =%E2           ! common envt.      *variance* computed in group 2
E Full 1 1 =%E3           ! specific envt.    *variance* computed in group 3
D Full 1 1 =%E4           ! dominance genetic *variance* computed in group 4
T Full 2 1 Free           ! matrix containing threshold parameters
Thresholds T /            ! supply matrix expression for thresholds
Covariances A+C+E+D | A+C+D
_             A+C+D | A+C+E+D /      ! supply matrix expression for covariance
Specify T                 ! force thresholds to be equal for rows & cols
4 4                       ! i.e. twin 1 & twin 2 in this case
Option RS                 ! print residual, observed & expected frequencies
End                       ! end of first group

MZ Twins Ascertained through Hospital records
Data Ninput=2             ! ninput=2, corresponding to liabilities of T1&T2
CTable 2 2
-1 -1                     ! Cells with twin 1 below threshold *not* ascertained
12 33                     ! Observed frequencies for cells that were asc.
Matrices                  ! define matrices for thresholds & covariances
A Full 1 1 =%E1           ! additive genetic  *variance* computed in group 1
C Full 1 1 =%E2           ! common envt.      *variance* computed in group 2
E Full 1 1 =%E3           ! specific envt.    *variance* computed in group 3
D Full 1 1 =%E4           ! dominance genetic *variance* computed in group 4
T Full 2 1 =T5            ! matrix containing threshold parameters
Thresholds T /            ! supply matrix expression for thresholds
Covariances A+C+E+D | A+C+D
_             A+C+D | A+C+E+D /      ! supply matrix expression for covariance
Option RS
End

DZ Twins Ascertained through register
Data Ninput=2
CTable 2 2
86 34
31 18
Matrices                  ! define matrices for thresholds & covariances
A Full 1 1 =%E1           ! additive genetic  *variance* computed in group 1
C Full 1 1 =%E2           ! common envt.      *variance* computed in group 2
E Full 1 1 =%E3           ! specific envt.    *variance* computed in group 3
D Full 1 1 =%E4           ! dominance genetic *variance* computed in group 4
H Full 1 1                ! half for additive genetic cov of DZ's
Q Full 1 1                ! quarter for dominance genetic cov of DZ's
T Full 2 1 =T5            ! matrix containing threshold parameters
Thresholds T /            ! supply matrix expression for thresholds
Covariances     A+C+E+D | h@A+C+q@D
_             h@A+C+q@D | A+C+E+D /      ! supply matrix expression for covariance
matrix h .5
matrix q .25
Option RS
End

DZ Twins Ascertained through hospital records
Data Ninput=2
CTable 2 2
-1 -1
71 35
Matrices                  ! define matrices for thresholds & covariances
A Full 1 1 =%E1           ! additive genetic  *variance* computed in group 1
C Full 1 1 =%E2           ! common envt.      *variance* computed in group 2
E Full 1 1 =%E3           ! specific envt.    *variance* computed in group 3
D Full 1 1 =%E4           ! dominance genetic *variance* computed in group 4
H Full 1 1 =h7            ! half for additive genetic cov of DZ's
Q Full 1 1 =q7            ! quarter for dominance genetic cov of DZ's
T Full 2 1 =T5            ! matrix containing threshold parameters
Thresholds T /            ! supply matrix expression for thresholds
Covariances     A+C+E+D | h@A+C+q@D
_             h@A+C+q@D | A+C+E+D /      ! supply matrix expression for covariance
Option RS
End

Constraint group to ensure variance = a*a + c*c + e*e + d*d = 1
Data Constraint Ninput=1
Matrices                  ! define matrices for thresholds & covariances
A Full 1 1 =%E1           ! additive genetic  *variance* computed in group 1
C Full 1 1 =%E2           ! common envt.      *variance* computed in group 2
E Full 1 1 =%E3           ! specific envt.    *variance* computed in group 3
D Full 1 1 =%E4           ! dominance genetic *variance* computed in group 4
I Iden 1 1
Covariance I - (A+C+E+D) /
! constraint is satisfied when the above expression evaluates to zero
! i.e. in this case 1 - (a*a + c*c + e*e + d*d) = 0
! Mx will optimize subject to this constraint
Option No_output
End
