-
Notifications
You must be signed in to change notification settings - Fork 197
/
Copy pathbaci-fish.sas
331 lines (248 loc) · 9.56 KB
/
baci-fish.sas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
/* BACI design with multiple years before/after ; 2 factor; interaction; */
/= This is the example that appears in Smith (2002, Table 6).
Samples of fish were taken for a period
of 12 months before and 13 months after a nuclear
power plant began operations.
The power plant is cooled by water that is drawn from a river.
When the water exits the plant, its temperature is
elevated.
The concern is that the warmed water will adversely affect the abundance
and composition of fish below the plant.
[It wasn't clear from Smith (2002) what the response measure is,
so I'll arbitrarily assume that it is counts.]
*/
/* Lines starting with *---partxxxe and *---parxxxb are used in my Latex file and
should be ignored */
/* The tagsets.tablesonlylatex again is used by the Latex Program course notes */
dm 'output' clear;
dm 'log' clear
proc datasets kill;
/* the noovp options to get the output to print properly on some printers */
options nodate noovp orientation=landscape;
ods pdf file='baci-fish-SAS.pdf';
goptions device=pdf colors=(black) rotate=landscape;
title 'BACI - Shore crab count near power plan - multiple sites, one year before/after ';
*---part001b;
data fish;
infile 'baci-fish.csv' dlm=',' dsd missover firstobs=2;
length SiteClass Site Period trt $20;
input SampleTime Year Period SiteClass Site Count;
trt = compress(SiteClass || "." || put(year,2.0) || "." || Period);
run;
*---part001e;
proc print data=fish;
title2 'raw data';
run;
ods document name=timeplot(write);
*---part010b;
proc sgplot data=fish;
title2 'Profile Plot over time';
yaxis label='Count' offsetmin=.05 offsetmax=.05;
xaxis label='Month' offsetmin=.05 offsetmax=.05;
series x=SampleTime y=count / markerattrs=(symbol=circlefilled) group=Site;
refline 12.5 / axis=x;
run;
*---part010e;
ods document close;
/*------------------------- */
/* Simple summary statistics are not very useful here*/
/* A simple profile plot is not very useful here as well */
/* ------------------------------------------------------------------------- */
/* Analysis of the differences
/* transpose to get before/after on the same record */
*---part101b;
proc sort data=fish;
by SampleTime Period;
run;
proc transpose data=fish out=Transfish;
by SampleTime Period;
var Count;
id SiteClass;
run;
data Transfish;
set Transfish;
diff = Impact - Control;
run;
proc print data=Transfish;
run;
*---part101e;
ods document name=timeplotdiff(write);
*---part102b;
proc sgplot data=Transfish;
title2 'Plot of the difference (Impact-Control) over time';
yaxis label='Difference in Count' offsetmin=.05 offsetmax=.05;
xaxis label='Month' offsetmin=.05 offsetmax=.05;
series x=SampleTime y=diff / markerattrs=(symbol=circlefilled);
refline 12.5 / axis=x;
run;
*---part102e;
ods document close;
/* Now for a t-test on the differences */
ods document name=TTestDiff(write);
*---part105b;
ods graphics on;
proc ttest data=Transfish plot=all dist=normal;
title2 'T-test on the differences (Impact-Control)';
class Period;
var diff;
ods output ttests = TtestTest;
ods output ConfLimits=TtestCL;
ods output Statistics=TtestStat;
run;
ods graphics on;
*---part105e;
ods document close;
/* Nonparametric test on the differences */
ods document name=NparDiff(write);
*---part107b;
ods graphics on;
proc npar1way data=Transfish plot=all wilcoxon;
title2 'T-test on the differences (Impact-Control)';
class Period;
var diff;
ods output WilcoxonTest = WilcoxonTest;
run;
ods graphics on;
*---part107e;
ods document close;
/* Analysis of the raw data using Proc Mixed. */
ods document name=mixed2(write);
*---part300b;
ods graphics on;
proc mixed data=fish plots=all;
title2 'BACI analysis on raw data using MIXED';
class SiteClass Period site sampletime; /* class statement identifies factors */
model count = SiteClass Period SiteClass*Period / ddfm=kr;
random SampleTime;
lsmeans SiteClass / cl adjust=tukey ;
lsmeans Period / cl adjust=tukey ;
lsmeans SiteClass*Period / cl adjust=tukey ;
estimate 'BACI effect' SiteClass*Period 1 -1 -1 1 / cl;
ods output tests3 =Mixed2Test; /* needed for the pdmix800 */
ods output lsmeans =Mixed2Lsmeans;
ods output diffs =Mixed2Diffs;
ods output estimates=Mixed2Ests;
ods output covparms =Mixed2CovParms;
run;
ods graphics off;
*---part300e;
ods document close;
ods pdf close;
/* Now to create the various outputs for my LaTeX files */
/* Create LaTeX files for inclusion by my notes */
%include "../../MyLatexTagset.sas"; run;
title;
footnote;
ods listing;
proc document name=npardiff;
list /levels=all;
run;
ods tagsets.mycolorlatex file='baci-fish-SAS-001.tex' (notop nobot) stylesheet="sas.sty";
proc print data=fish(obs=10);
run;
ods tagsets.mycolorlatex close;
ods listing;
ods graphics on / imagefmt=png imagename='baci-fish-SAS-010' reset=index;
proc document name=timeplot;
replay \Sgplot#1\SGPlot#1 / dest=listing;
run;
ods graphics off;
ods listing close;
ods tagsets.mycolorlatex file='baci-fish-SAS-101.tex' (notop nobot);
proc print data=transfish(obs=10);
run;
ods tagsets.mycolorlatex close;
ods listing;
ods graphics on / imagefmt=png imagename='baci-fish-SAS-102' reset=index;
proc document name=timeplotdiff;
replay \Sgplot#1\SGPlot#1 / dest=listing;
run;
ods graphics off;
ods listing close;
/* Output from Proc Ttest on differences */
ods tagsets.mycolorlatex file='baci-fish-SAS-105a.tex' (notop nobot);
proc print data=TtestTest noobs label split=" " ;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-105b.tex' (notop nobot);
proc print data=TtestCL noobs label split=" " ;
where index(lowcase(class),'diff')>0;
var variable class method variances mean lowerclmean upperclmean;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-105c.tex' (notop nobot);
proc print data=TtestStat noobs label split=" " ;
var variable class n mean stderr lowerclmean upperclmean;
run;
ods tagsets.mycolorlatex close;
ods listing;
ods graphics on / imagefmt=png imagename='baci-fish-SAS-105d' reset=index;
proc document name=ttestdiff;
replay \Ttest#1\diff#1\Interval#1 / dest=listing;
run;
ods graphics off;
ods listing close;
ods tagsets.mycolorlatex file='baci-fish-SAS-107a.tex' (notop nobot);
proc document name=npardiff;
obstitle \Npar1way#1\diff#1\Wilcoxon#1\WilcoxonTest#1; /* kill titles */
obtitle \Npar1way#1\diff#1\Wilcoxon#1\WilcoxonTest#1;
replay \Npar1way#1\diff#1\Wilcoxon#1\WilcoxonTest#1;
run;
ods tagsets.mycolorlatex close;
/* Output from Proc Mixed from the analysis on the individual values */
ods tagsets.mycolorlatex file='baci-fish-SAS-300-type3.tex' (notop nobot);
proc document name=mixed2;
obstitle \Mixed#1\Tests3#1; /* kill titles */
obtitle \Mixed#1\Tests3#1;
replay \Mixed#1\Tests3#1;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-vc.tex' (notop nobot);
proc print data=Mixed2CovParms noobs label split=" " ;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-LSMint.tex' (notop nobot);
proc print data=Mixed2LSmeans noobs label split=" " ;
where index(lowcase(effect),'siteclass')>0 and index(lowcase(effect),'period')>0;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-LSMme1.tex' (notop nobot);
proc print data=Mixed2LSmeans noobs label split=" " ;
where index(lowcase(effect),'siteclass')>0 and index(lowcase(effect),'period')=0;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-LSMme2.tex' (notop nobot);
proc print data=Mixed2LSmeans noobs label split=" " ;
where index(lowcase(effect),'siteclass')=0 and index(lowcase(effect),'period')>0;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-LSMintdiff.tex' (notop nobot);
proc print data=Mixed2Diffs noobs label split=" " ;
where index(lowcase(effect),'siteclass')>0 and index(lowcase(effect),'period')>0;
var SiteClass Period _SiteClass _Period estimate stderr adjustment adjp adjlower adjupper;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-LSMme1diff.tex' (notop nobot);
proc print data=Mixed2Diffs noobs label split=" " ;
where index(lowcase(effect),'siteclass')>0 and index(lowcase(effect),'period')=0;
var SiteClass Period _SiteClass _Period estimate stderr adjustment adjp adjlower adjupper;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-LSMme2diff.tex' (notop nobot);
proc print data=Mixed2Diffs noobs label split=" " ;
where index(lowcase(effect),'siteclass')=0 and index(lowcase(effect),'period')>0;
var SiteClass Period _SiteClass _Period estimate stderr adjustment adjp adjlower adjupper;
run;
ods tagsets.mycolorlatex close;
ods tagsets.mycolorlatex file='baci-fish-SAS-300-BACIeff.tex' (notop nobot);
proc print data=Mixed2Ests noobs label split=" " ;
run;
ods tagsets.mycolorlatex close;
ods listing;
goptions device=png colors=(black) rotate=landscape;
ods graphics on / imagefmt=png imagename='baci-fish-SAS-300-diagnostic' reset=index;
proc document name=mixed2;
replay \Mixed#1\ResidualPlots#1\ResidualPanel#1 / dest=listing;
run;
ods graphics off;
ods listing close;