forked from burakbayramli/books
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbaci-crabs.sas
241 lines (184 loc) · 7.31 KB
/
baci-crabs.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
/* Simple BACI design; 2 factor; interaction; */
/* A simple BACI design was used to assess the impact
of cooling water discharge on the density of
shore crabs. The beach near the outlet of the
cooling water was sampled using several quadrats
before and after the plant started operation,
as was a control beach on the other side of the
body of water.
*/
/* 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-crabs-SAS.pdf';
goptions device=pdf colors=(black) rotate=landscape;
title 'Simple BACI - Shore crab density near power plan ';
*---part001b;
data crabs;
infile 'baci-crabs.csv' dlm=',' dsd missover firstobs=2;
length SiteClass Site Period quadrat $10 trt $20;
input SiteClass site Period quadrat density;
trt = compress(SiteClass || "." || Period);
run;
*---part001e;
proc print data=crabs;
title2 'raw data';
run;
ods document name=dotplot(write);
*---part010b;
proc sgplot data=crabs;
title2 'Side-by-side dot plots';
yaxis label='Density' offsetmin=.05 offsetmax=.05;
xaxis label='Treatmemt' offsetmin=.05 offsetmax=.05;
scatter x=trt y=density / markerattrs=(symbol=circlefilled);
run;
*---part010e;
ods document close;
/*------------------------- */
/* Find some simple summary statistics.*/
ods document name=meanstable(write);
*---part020b;
proc tabulate data=crabs; /* proc tabulate is not for the faint of heart */
title2 'Summary table of means, std devs';
class SiteClass Site Period;
var Density;
table SiteClass*Site*Period, density*(n*f=5.0 mean*f=5.2 std*f=5.2 stderr*f=5.2) /rts=15;
run;
*---part020e;
ods document close;
/* Create a profile plot of the means */
/* Because this is a crd, it is easy to create the se and 95% for each mean */
/* Need to sort the data first */
ods document name=profileplot(write);
*---part030b;
proc sort data=crabs;
by SiteClass Period;
run;
proc means data=crabs noprint; /* find simple summary statistics */
by SiteClass Period;
var density;
output out=means n=n mean=mean std=stddev stderr=stderr lclm=lclm uclm=uclm;
run;
proc sgplot data=means;
title2 'Profile plot with 95% ci on each mean';
series y=mean x=SiteClass / group=Period;
highlow x=SiteClass high=uclm low=lclm / group=Period;
yaxis label='Density' offsetmin=.05 offsetmax=.05;
xaxis label='SiteClass' offsetmin=.05 offsetmax=.05;
run;
*---part030e;
ods document close;
/* Analysis of the design using Proc Mixed. You could also use GLM
but GLM won't be helpful when you have multipe sites etc */
ods document name=mixed(write);
*---part200b;
ods graphics on;
proc mixed data=crabs plots=all;
title2 'Mixed BACI analysis';
class SiteClass Period; /* class statement identifies factors */
model density = SiteClass Period SiteClass*Period / ddfm=kr;
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 =MixedTest; /* needed for the pdmix800 */
ods output lsmeans =MixedLsmeans;
ods output diffs =MixedDiffs;
ods output estimates=MixedEsts;
run;
ods graphics off;
*---part200e;
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=mixed;
list /levels=all;
run;
ods tagsets.mycolorlatex file='baci-crabs-SAS-001.tex' (notop nobot) stylesheet="sas.sty";
proc print data=crabs(obs=10);
run;
ods tagsets.mycolorlatex close;
ods listing;
ods graphics on / imagefmt=png imagename='baci-crabs-SAS-010' reset=index;
proc document name=dotplot;
replay \Sgplot#1\SGPlot#1 / dest=listing;
run;
ods graphics off;
ods listing close;
ods tagsets.mycolorlatex file='baci-crabs-SAS-020.tex' (notop nobot);
proc document name=meanstable;
obstitle \Tabulate#1\Report#1\Table#1; /* kill titles */
obtitle \Tabulate#1\Report#1\Table#1;
replay \Tabulate#1\Report#1\Table#1;
run;
ods tagsets.mycolorlatex close;
ods listing;
ods graphics on / imagefmt=png imagename='baci-crabs-SAS-030' reset=index;
proc document name=profileplot;
replay \Sgplot#1\SGPlot#1 / dest=listing;
run;
ods graphics off;
ods listing close;
/* Output from Proc Mixed */
ods tagsets.mycolorlatex file='baci-crabs-SAS-200-type3.tex' (notop nobot);
proc document name=mixed;
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-crabs-SAS-200-LSMint.tex' (notop nobot);
proc print data=MixedLSmeans 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-crabs-SAS-200-LSMme1.tex' (notop nobot);
proc print data=MixedLSmeans 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-crabs-SAS-200-LSMme2.tex' (notop nobot);
proc print data=MixedLSmeans 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-crabs-SAS-200-LSMintdiff.tex' (notop nobot);
proc print data=MixedDiffs 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-crabs-SAS-200-LSMme1diff.tex' (notop nobot);
proc print data=MixedDiffs 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-crabs-SAS-200-LSMme2diff.tex' (notop nobot);
proc print data=MixedDiffs 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-crabs-SAS-200-BACIeff.tex' (notop nobot);
proc print data=MixedEsts noobs label split=" " ;
run;
ods tagsets.mycolorlatex close;
ods listing;
goptions device=png colors=(black) rotate=landscape;
ods graphics on / imagefmt=png imagename='baci-crabs-SAS-200-diagnostic' reset=index;
proc document name=mixed;
replay \Mixed#1\ResidualPlots#1\ResidualPanel#1 / dest=listing;
run;
ods graphics off;
ods listing close;