" Exercise 12.2
Statistical Methods in Biology: Design and Analysis of Experiments and Regression
by S.J. Welham, S.A. Gezan, S.J. Clark & A. Mead (2014)
Chapman & Hall/CRC Press, Boca Raton, Florida. ISBN: 978-1-4398-0878-8
Data from R. Harrington & C. Shortall, Rothamsted Research
Version 1, 14/08/2015 "
" Set working directory - change to location of your data file "
\SET [WORKINGDIRECTORY='d:/stats4biol/data/']
" Read data from working directory "
FILEREAD [NAME='HEREFORD.DAT'; IMETHOD=read] FGROUPS=no
" Transform the data to logs with offset of 0.5 "
CALCULATE logWt=LOG10(WetWeight+0.5)
" Plot data "
DGRAPH Y=logWt; X=Year
" Fit SLR "
MODEL Y=logWt
FIT [FPROBABILITY=yes; TPROBABILITY=yes] Year
" Save fitted values and standardized residuals "
RKEEP FITTEDVALUES=fval; RESIDUALS=res
" Residual plots based on standardized residuals "
DRESIDUALS [RESIDUALS=res; FITTEDVALUES=fval] METHOD=fittedvalues,normal,histogram,absresidual
" Plot fitted model "
RGRAPH [CIPLOT=yes]
" Predict for 2010 and save prediction with SE "
PREDICT [PREDICTIONS=pred; SE=SEpred] CLASSIFY=Year; LEVELS=2010
" Save residual df "
RKEEP DF=resdf
" Obtain critical value from t-distribution "
CALCULATE tcrit=EDT(0.975;resdf)
" Calculate 95% CI for prediction "
CALCULATE lower=pred-tcrit*SEpred
CALCULATE upper=pred+tcrit*SEpred
PRINT STRUCTURE=lower,pred,upper
" Print prediction and 95% CI on back-transformed scale "
PRINT STRUCTURE=10**(lower,pred,upper)-0.5
" Check residuals for temporal correlation - data is in year order "
" Plot residual against that from previous year "
DGRAPH res; shift(res;-1)
" Correlation between residual and that from previous year "
FCORR [PRINT=corr,test] shift(res;0,1)
" Plot residuals in year order "
PEN 1; METHOD=line
DGRAPH res; Year
" End of File "