Program SURVIV User's Manual Version 1.2 -- March 1986
Recent(10/99) modifications by Jim Hines
Patuxent Wildlife Research Center
Laurel, MD 20708
One of the most frequent difficulties in model specification in program SURVIV has been the
limit of the number of characters for the cell probabilities. Although the current limit
seems high, many models, particularly ones involving recursive terms and many time-periods,
exceeded the limit. To solve this problem, I have added the capability to insert FORTRAN
statements into the SURVIV input file which allow users to use statement functions and
temporary variables in the estimation routine (EST.FOR).
To use this new capability, I have added 3 new possible statements to the input file.
The first one inserts an inline declaration statement into the estimation routine and has
the following syntax:
inline declare xxxxxxxxxxx;where xxxxxxxxx is a valid FORTRAN declaration statement. This could be used to declare temporary variables (scalars or arrays), or statement functions. The second one inserts an inline command which will be executed just before any of the cell probabilities are computed and has the following syntax:
inline xxxxxxxxxxxx;This could be used to compute an array of temporary variables. The third way to insert additional instructions into the estimation routine is to enclose any valid FORTRAN statements in braces {} and insert them just after the cell probability definition. These statements will be executed after the computation of the associated cell probability. The syntax of the cell probability is:
NNN: ppppppp { stmt1 | stmt2 | stmt3 ...} ;where NNN is the number of observations for the cell, pppp is the cell probability definition, stmt1, stmt2, stmt3 are FORTRAN statements separated by '|' These statements could be used to compute recursive products which would be used in later cells.
PROC TITLE 'BAND RECOVERY EXAMPLE'; PROC MODEL NPAR=10; COHORT=1000; 100: S(1) /* RECOVERED IN 1ST YEAR AFTER BANDING */; 50: (1-S(1))*S(2) /* RECOVERED IN 2ND YEAR AFTER BANDING */; 25: (1-S(1))*(1-S(2))*S(3) /* RECOVERED IN 3RD YEAR AFTER BANDING */; 12: (1-S(1))*(1-S(2))*(1-S(3))*S(4) /* RECOVERED IN 4TH YEAR */;As you can see, each year after the year of banding, the cell probability definition gets longer. After 4 years the lines are not too long, but after a couple of thousand years, we would exceed the maximum line length. Looking at the cell probabilities, we can see that each cell contains terms which were in the previous cell. So, if we create a temporary variable which contains the product of these terms, each cell probability would be very simple. Here is one way to do it:
PROC TITLE 'BAND RECOVERY EXAMPLE'; PROC MODEL NPAR=10; COHORT=1000; 100: S(1) {PRD=(1-S(1))} /* RECOVERED IN 1ST YEAR AFTER BANDING */; 50: PRD*S(2) {PRD=PRD*(1-S(2))} /* RECOVERED IN 2ND YEAR */; 25: PRD*S(3) {PRD=PRD*(1-S(3))} /* RECOVERED IN 3RD YEAR */; 12:PRD*S(4) /* RECOVERED IN 4TH YEAR */;In the above code, the first cell probability is just S(1) (the same as the original code). After the first cell probability is computed, a temporary variable, PRD, is computed as (1- S(1)). This value is used in the computation of the second cell probability. So, the second cell probability is: PRD*S(2) which would be (1-S(1))*S(2). Then, the temporary variable, PRD is computed as PRD*(1-S(2)) which would be (1-S(1))*(1-S(2)) and this value would go into the computation of the third cell probability. Using this method, the cell probability statements do not increase no matter how many time- periods there are.
PROC TITLE 'BAND RECOVERY EXAMPLE'; PROC MODEL NPAR=10; COHORT=1000; 100: EXP(S(1)+S(2)*1.0)/(1+EXP(S(1)+S(2)*1.0); 50: (1-EXP(S(1)+S(2)*1.0)/(1+EXP(S(1)+S(2)*1.0)))* EXP(S(1)+S(2)*2.0)/(1+EXP(S(1)+S(2)*2.0))}; 25: (1-EXP(S(1)+S(2)*1.0)/(1+EXP(S(1)+S(2)*1.0)))* (1-EXP(S(1)+S(2)*2.0)/(1+EXP(S(1)+S(2)*2.0)))* EXP(S(1)+S(2)*3.0)/(1+EXP(S(1)+S(2)*3.0))}; 12: (1-EXP(S(1)+S(2)*1.0)/(1+EXP(S(1)+S(2)*1.0)))* (1-EXP(S(1)+S(2)*2.0)/(1+EXP(S(1)+S(2)*2.0)))* (1-EXP(S(1)+S(2)*3.0)/(1+EXP(S(1)+S(2)*3.0)))* EXP(S(1)+S(2)*4.0)/(1+EXP(S(1)+S(2)*4.0))};Using temporary variables, we can rewrite this as:
PROC TITLE 'BAND RECOVERY EXAMPLE'; PROC MODEL NPAR=10; INLINE STMP=EXP(S(1)+S(2)*1.0)/(1+EXP(S(1)+S(2)*1.0)); COHORT=1000; 100: STMP {PRD=1-STMP|STMP=EXP(S(1)+S(2)*2.0)/(1+EXP(S(1)+S(2)*2.0))}; 50:PRD*STMP {PRD=1-STMP|STMP=EXP(S(1)+S(2)*3.0)/(1+EXP(S(1)+S(2)*3.0))}; 25:PRD*STMP {PRD=1-STMP|STMP=EXP(S(1)+S(2)*4.0)/(1+EXP(S(1)+S(2)*4.0))}; 12:PRD*STMP;Note that the 'INLINE' statement sets up the first recovery probability before the first cell probability is computed. Then, after each cell probability is computed, the product term (PRD) is updated as well as the term for the recovery probability.
In this example, I will model an "M(i,j)" array of cell probabilities as defined in a Jolly-Seber capture-recapture model. The model parameters are PHI(i), (i=1..K-1), [survival rates] and CP(i), (i=2..K) [capture probabilities].
PROC TITLE 'EXAMPLE 3 - JOLLY-SEBER M-ARRAY EXAMPLE'; PROC MODEL NPAR=6; INLINE DECLARE REAL*8 PHI(3),CP(4); INLINE DECLARE INTEGER NYRS; INLINE NYRS=NCLASS(1); INLINE DO I=1,NYRS-1; INLINE PHI(I)=S(I); INLINE CP(I+1)=S(NYRS+I-1); INLINE END DO; INLINE DO I=1,NYRS-1; INLINE PRD=1; INLINE XSUM=0; INLINE DO J=I+1,NYRS; INLINE P(J-I,I)=PRD*PHI(J-1)*CP(J); INLINE XSUM=XSUM+P(J-I,I); INLINE PRD=PRD*PHI(J-1)*(1.-CP(J)); INLINE END DO; INLINE P(NCLASS(I),I)=1.-XSUM; INLINE END DO; COHORT=100; 50:; 10:; 5:; COHORT=100; 40:; 14:; COHORT=100; 55:; LABELS; S(1)=PHI(1); S(2)=PHI(2); S(3)=PHI(3); S(4)=CP(2); S(5)=CP(3); S(6)=CP(4); PROC ESTIMATE NOVAR MAXFN=32000 NAME=MODL_D; CONSTRAINTS; S(2)=S(1) /* PHI(2)=PHI(1) */; S(3)=S(1) /* PHI(3)=PHI(1) */; S(5)=S(4) /* CP(3)=CP(2) */; S(6)=S(4) /* CP(4)=CP(2) */; PROC STOP;Notes: In COHORT statements, no cell probabilities are specified between the colon (:) and the semi-colon (;).
Important: You must make sure you do not use any variable names which are used in the estimation routine (EST.FOR). (This is why I used "XSUM" instead of SUM, and CP instead of P.)