! The dataset is limited to DZ twin pairs only
!
#define nvar 1
#define nvarx2 2
#ngroups 1

Simulated data, real allele effect
 Data NInput=7                ! 7 input variables
 Rectangular File=set1.rec ! read data from file
 Labels  p1 p2 a1s1 a2s1 a1s2 a2s2 type

 ! aisj is allele i of sibling j
 ! type is coded: 1: AAAA 2: AAAa 3: AAaa
 !                4: AaAA 5: AaAa 6: Aaaa
 !                7: aaAA 8: aaAa 9: aaaa

 Definition_variables a1s1 a2s1 a1s2 a2s2 type ;
 ! only p1 and p2 will be analyzed; other variables define the model

 Begin Matrices
  A Lower nvarx2 nvarx2 Free  	! Additive genetic influences , cholesky

  F Full 2 1 			! A allele count for sib1 (0,1,2)
  H Full 2 1			! A allele count for sib2
  I Full 1 1                    ! To store type

  J Unit 1 1                    ! 1.0
  K Full 1 1                    ! 2.0
  U Unit 1 2                    ! Unit matrix

  B Full 1 1  			! Beta weight for individual allele count
  N Full 1 1  Free		! Overall mean
  W Full 2 1  Free              ! ab and aw parameters
  V Full 9 1                    ! 
  X Full 9 1
 End Matrices

 Matrix A  1 0 1
 Matrix I 1
 Matrix K 2 
 Matrix V  1  .5 0 .5 0 -.5 0 -.5 -1
 Matrix X  0 .5 1 -.5 0 .5 -1 -.5 0

 Specify F a1s1 a2s1
 Specify H a1s2 a2s2 
 Specify I type

 Bound  -5 5 B 1 1 
 Bound -5 5 N 1 1  


 Begin Algebra;
  E = I|J|I|K ;                              ! to select row of V|X
  Z = \part((V|X),E)*W | \part((V|-X),E)*W ; ! selects row of V|X and V|-X
 End Algebra;

 Means (N + (B@U)*F | N + (B@U)*H) + Z;
 Covariance A*A' ;

 Option  nd=4        ! request 4 decimal places in output
 OPtion RS Multiple  ! request residuals, multiple fit
 Option issat        ! this is saturated model for submodel comparison
End

 save set1.mxs
 equate w 1 1 1 w 1 2 1
End
 Drop w 1 1 1
End