07 Lecture 05 Swordfish program

07 Lecture 05 Swordfish program -...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: dm'log;clear;output;clear'; ****************************************************************************; *** From: http://fishbull.noaa.gov/1053/demartini.pdf, Age and growth ***: *** of swordfish (Xiphias gladius) caught by the Hawaii-based pelagic ***: *** longline fishery, DeMartini, Edward E., James H. Uchiyama, ***: *** Robert L. Humphreys Jr., Jeffrey D. Sampaga, Happy A. Williams, ***: *** Fish. Bull. 105:356-367 (2007). ***; ****************************************************************************; OPTIONS NOCENTER PS=512 LS=111 NODATE NONUMBER nolabel; ODS HTML style=minimal body='C:\Geaghan\Current\EXST7025\Spring2009\SAS\Swordfish\Swordfish Growth.html' ; ods graphics on; LIBNAME SASDATA 'C:\Geaghan\Current\EXST7025\Spring2009\SAS\Swordfish\'; TITLE1 'Growth Curves fitted to Swordfish'; DATA SASDATA.Swordfish; infile cards missover; input Age NM EFLM Male SDM NF EFLF Female SDF; SEX = 'Female'; EFL = Female; SD = SDF; N = NF; output; SEX = 'Male'; EFL = Male; SD = SDM; N = NM; output; keep age EFL SD N sex; datalines; 0 136 . 82.1 18.4 137 . 82.3 1 145 102 114.3 13.2 114 100.5 115.1 2 97 127.4 137 13.5 109 126.3 138.3 3 69 147.9 155.3 16 64 147.7 155.4 4 41 159.9 164.1 14.2 58 167.1 171.4 5 29 166.3 172.8 18 59 179.6 185.3 6 34 174.7 181 17.6 63 189.7 195 7 15 188.4 189.7 17.2 36 204.7 209.9 8 10 196.7 197.3 19.7 29 208.5 212.3 9 4 202.2 212.5 12.9 20 208 210.3 10 . . . . 12 223.4 228 11 2 197.5 198.5 6.4 9 219.6 222.8 12 . . . . 5 216 218.2 RUN; proc print data=SASDATA.Swordfish; run; 18.8 14.2 15.1 15.5 18.2 18 17.8 12.4 15.4 16.6 15.6 17.6 14.5 PROC SORT DATA=SASDATA.Swordfish; BY sex descending Age; RUN; DATA SASDATA.Swordfish; SET SASDATA.Swordfish; by sex descending age; IF AGE EQ . THEN DELETE; Age1 = Age; AGE2 = Age*Age; AGE3 = Age*Age*Age; LAge = log(Age); LT = EFL; LLT= LOG(EFL); LTP1=LAG1(EFL); DLT = LAG1(EFL) - EFL; if first.sex then do; ltp1=.; dlt=.; end; RUN; proc print data=SASDATA.Swordfish; run; OPTIONS PS=52 LS=132; proc plot data=SASDATA.Swordfish; plot EFL*age=sex; run; proc plot data=SASDATA.Swordfish; plot DLt*age=sex; run; OPTIONS PS=512 LS=111; PROC SORT DATA=SASDATA.Swordfish; BY sex Age; RUN; PROC REG OUTEST=PARMEST DATA=SASDATA.Swordfish; weight n; BY sex; TITLE2 'STEP 1 - LINEAR MODELS'; GULLAND:MODEL DLT = LT; WALFORD:MODEL LTP1 = LT; LINEAR:MODEL LT=AGE1; QUADRATC:MODEL LT=AGE1 AGE2; CUBIC:MODEL LT=AGE1 AGE2 AGE3; POWER:MODEL LLT=LAGE; EXPONENT:MODEL LLT=AGE1; RUN; proc print data=parmest; *var _MODEL_ _TYPE_ _DEPVAR_ run; DATA SUMMARY; LENGTH MODEL MODEL = _MODEL_; IF MODEL EQ 'GULLAND' IF MODEL EQ 'WALFORD' IF MODEL EQ 'LINEAR' IF MODEL EQ 'QUADRATC' IF MODEL EQ 'CUBIC' $ 20; _RMSE_ Intercept LT AGE1 AGE2 AGE3 LAge; SET PARMEST; THEN THEN THEN THEN THEN DO; G=ABS(LT); DO; G=1-LT; DO; G=age1; DO; DO; other1=age2; IF MODEL EQ 'POWER' THEN DO; G=intercept; IF MODEL EQ 'EXPONENT' THEN DO; G=AGE1; proc print data=summary; run; KEEP MODEL G Lo L other1 other2 sex; L =INTERCEPt/G; END; L =INTERCEPt/G; END; Lo=INTERCEPt; END; Lo=INTERCEPt; other1=age2; Lo=INTERCEPt; other2=age3; END; Lo=0; other1=lage; END; Lo=INTERCEPt; END; RUN; DATA PARMEST; SET SUMMARY; IF MODEL EQ 'WALFORD'; PROC PRINT DATA=parmest; RUN; KEEP L sex; RUN; DATA SASDATA.SwordfishB; MERGE SASDATA.Swordfish PARMEST; by sex; IF L EQ . THEN L = OLDL; OLDL = L; if L gt LT then LADJ = LOG((L - LT)/L); else LAdj = .; RETAIN OLDL; KEEP AGE L LT LLT LADJ sex; RUN; PROC PRINT DATA=SASDATA.SwordfishB; RUN; PROC REG DATA=SASDATA.SwordfishB OUTEST=PARMEST; by sex; TITLE2 'Step 2 - Regression on Adjusted Lengths'; STEP2:MODEL LADJ = AGE; RUN; DATA SUMMARY; merge SUMMARY PARMEST; by sex; KEEP SEX MODEL L Lo G XINT YINT other1 other2; IF MODEL EQ 'GULLAND' THEN DO; XINT = -INTERCEPT/AGE; YINT = L*(1-EXP(G*XINT)); END; RUN; PROC PRINT DATA=SUMMARY; var MODEL SEX L Lo G XINT YINT other1 other2; TITLE2 'Summary data set after linear models'; RUN; data SASDATA.onebyone; set SASDATA.Swordfish; if n gt 0 then do i = 1 to N; lt = EFL + rannor(1234567)*sd; if sex eq 'Female' then SF = 1; else SF = 0; if sex eq 'Male' then SM = 1; else SM = 0; output; end; END; run; proc univariate data=SASDATA.onebyone; var lt; run; PROC NLIN DATA=SASDATA.onebyone OUTEST=PARMEST maxiter=200; TITLE2 'TRADITIONAL vBert'; PARAMETERS LIF = 243 KF = 0.181 T0F = -2.691 LIM = 214 KM = 0.222 T0M = -1.405; MODEL LT = SF*LIF*(1 - EXP(-KF*(Age - T0F))) + SM*LIM*(1 - EXP(-KM*(Age - T0M))); RUN; PROC NLIN DATA=SASDATA.onebyone maxiter=200; TITLE2 'vBert with intercept'; PARAMETERS LIF = 243 KF = 0.181 L0F=93.3 LIM = 214 KM = 0.222 L0M=57.2; MODEL LT = SF*(LIF-(LiF-L0F)*EXP(-KF*Age)) + SM*(LIM-(LIM-L0M)*EXP(-KM*Age)); RUN; PROC NLIN DATA=SASDATA.onebyone OUTEST=PARMEST maxiter=200; TITLE2 'GOMPERTZ WITH t0'; PARAMETERS LIF = 243 KF = 0.181 T0F = -2.691 LIM = 214 KM = 0.222 T0M = -1.405; MODEL LT = SF*LIF*EXP(-EXP(-KF*(Age-T0F))) + SM*LIM*EXP(-EXP(-KM*(Age-T0M))); RUN; PROC NLIN DATA=SASDATA.onebyone maxiter=200; TITLE2 'GOMPERTZ WITH INTERCEPT'; *Note: Female LINF=log(242.582/93.3175) = 0.95533214; *Note: Male LINF=log(213.823/57.2472) = 1.317769837; PARAMETERS LIF = 0.955 KF = 0.181 L0F=93.3 LIM = 1.31 KM = 0.222 L0M=57.2; MODEL LT = SF*L0F*EXP(LIF*(1-EXP(-KF*Age))) + SM*L0M*EXP(LIM*(1-EXP(-KM*Age))); RUN; PROC NLIN DATA=SASDATA.onebyone OUTEST=PARMEST maxiter=200; TITLE2 'Logistic Growth Curve with t0'; PARAMETERS LIF = 243 KF = 0.181 T0F = -2.691 LIM = 214 KM = 0.222 T0M = -1.405; MODEL LT = SF*(LIF / (1 + EXP(-KF*(Age - T0F)))) + SM*(LIM / (1 + EXP(-KM*(Age - T0M)))); RUN; PROC NLIN DATA=SASDATA.onebyone maxiter=200; TITLE2 'Logistic Growth Curve with L0'; PARAMETERS LIF = 243 KF = 0.181 L0F=93.3 LIM = 214 KM = 0.222 L0M=57.2; MODEL LT = SF*(LIF / (1 + ((LIF-L0F)/L0F)*EXP(-KF*Age))) + SM*(LIM / (1 + ((LIM-L0M)/L0M)*EXP(-KM*Age))); RUN; PROC NLIN DATA=SASDATA.onebyone OUTEST=PARMEST maxiter=10000; TITLE2 'Generalized von Bertalanffy - T0'; PARAMETERS LIF = 243 KF = 0.0.181 T0F = -2.691 PF = 1 LIM = 214 KM = 0.222 T0M = 1.405 PM = 1; MODEL LT = SF*(LIF * (1 - EXP(-KF*(Age-t0F)))**PF) + SM*(LIM * (1 - EXP(-KM*(Age-t0M)))**PM); RUN; PROC NLIN DATA=SASDATA.onebyone OUTEST=PARMEST maxiter=200; TITLE2 'Generalized von Bertalanffy - L0'; PARAMETERS LIF = 243 KF = 0.181 L0F=93.3 PF = 1 LIM = 214 KM = 0.222 L0M=57.2 PM=1; MODEL LT = SF*(LIF-(LiF-L0F)*EXP(-KF*Age))**PF + SM*(LIM-(LIM-L0M)*EXP(KM*Age))**PM; RUN; ods html close; run; quit; ...
View Full Document

Ask a homework question - tutors are online