!
! Ascertainment correction, estimating pi
!
G1: Model parameters
 Data Calc NGroups=4
 Begin Matrices;
  X Lower 1 1 Free
  Y Lower 1 1 Free
  Z Lower 1 1 Free
  W Lower 1 1 
  O Zero 1 1
  P full 1 1 Free ! ascertainment probability p
  U unit 1 1
 End Matrices;
 ! parameters are fixed by default, unless declared free 
 Matrix P .6
 Begin Algebra;
  A= X*X'; 
  C= Y*Y';
  E= Z*Z';
  D= W*W';
  S= ((P+P)*(U-P)) _ ((P+P)*(U-P)) _ (P*P) ; ! Vector of ascertainment probabilities
 End Algebra:
End

G2: MZ twin pairs
 Data Ninput=4
 Labels T1 T2 Asc Freq
 Ordinal File=mzpi.frq
 Definition Asc Freq ;
 Begin Matrices= Group 1
  T full 2 1 
  F full 1 1 ! Frequency
  G full 1 4 ! to select ascertainment prob
 End Matrices;
 Matrix T 1.282 1.282
 Specify F Freq
 Matrix G 1 1 1 1
 Specify G asc 0 asc 0
 Covariances A+C+D+E | A+C+D _
             A+C+D   | A+C+D+E ;
 Thresholds T ;
 Frequency F ;
 Weight \part(S,G);!%\sum(P_S) ;
 Options RSidual
End 

G3: DZ twin pairs
 Data Ninput=4
 Labels T1 T2 Asc Freq
 Ordinal File=dzpi.frq
 Definition Asc Freq ;

 Begin Matrices= Group 1
  H Full 1 1
  Q Full 1 1
  T Full 2 1 =T2
  F full 1 1 = F2 ! Frequency
  G full 1 4 = G2 ! To select ascertainment probability
 End Matrices;
 Matrix H .5
 Matrix Q .25
 Start .6 All
 Covariances A+C+D+E   | H@A+C+Q@D _
             H@A+C+Q@D | A+C+D+E /
 Thresholds T ;
 Frequency F ;
 Weight \part(S,G);!%\sum(P_S) ;
 Options RSidual NDecimals=4
End

Group 4: constrain variance to 1
 Constraint NI=1
 Begin Matrices = Group 1 ;
  I unit 1 1
 End Matrices;

 Constraint I = A+C+E+D ;
 Option Multiple issat
End
 Drop @.5 P 1 1 1
End
