-
Notifications
You must be signed in to change notification settings - Fork 192
/
baci-crabs-mod-power.sas
143 lines (115 loc) · 4.82 KB
/
baci-crabs-mod-power.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
/* This is a power analysis for a BACI design with multiple sites (modified crabs monitoring) */
/* Read in the scenarios (i.e. the design specifications) and generate the
data for use in the power analysis. The data are expected values for
each observed data point. These are then passed to Proc Mixed for 'analysis'
as outlined in the Stroup paper */
/* This is the monitoring for fry example presented in the notes */
/* The input data are the
Alpha level (usually .05 or .10)
Variance components
std_site -> site to site STANDARD DEVIATION
std_year -> year to year STANDARD DEVIATION
std_site_year -> site-year interaction STANDARD DEVIATION
std_Resid -> within site sub-sampling STANDARD DEVIATION
Sub-sampling sample sizes.
We allow for different sample sizes in the treatment-time combinations
but all sites in that combination must have the same sample size.
It is possible to generalize this; contact me for details.
n_TA -> number of Resids in Treatment-After combination
n_TB -> number of Resids in Treatment-Before combination
n_CA -> number of Resids in Control-After combination
n_CB -> number of Resids in Control-Before combination
Number of sites
We allow for a different number of sites for Treatment and Control areaa
ns_T -> number of treatment sites
ns_C -> number of control sites
Number of years of monitoring before/after impact
ny_b
ny_a
Marginal Means
These are used to form the BACI contrast of interest
mu_TA, mu_TB, mu_CA, mu_CB
*/
/* In the simple design, there is only one site in each of treatment or control and it is impossible to
separate the SiteYear variance component from the residual variance component */
options nodate noovp orientation=landscape;
title 'Modified Crabs example BACI power analysis';
ods pdf file='baci-crabs-mod-power-SAS.pdf';
%include '../baci-power.sas'; /* get the baci power macro */
*---part500b;
proc datasets; /* delete any existing data set */
delete all_power;
run;
data scenarios;
input alpha
sdSite sdYear sdSiteYear sdResid
n_TA n_TB n_CA n_CB
ns_T ns_C
ny_B ny_A
mu_TA mu_TB mu_CA mu_CB;
datalines;
.05 3.831 10 1.296 3.30 5 5 5 5 1 2 1 1 30 35 35 35
.05 3.831 10 1.296 3.30 40 40 40 40 1 2 1 1 30 35 35 35
.05 3.831 10 1.296 3.30 5 5 5 5 1 4 1 1 30 35 35 35
.05 3.831 10 1.296 3.30 20 20 20 20 1 4 1 1 30 35 35 35
.05 3.831 10 1.296 3.30 20 20 5 5 1 4 1 1 30 35 35 35
.05 3.831 10 1.296 3.30 5 5 5 5 1 10 1 1 30 35 35 35
.05 3.831 10 1.296 3.30 5 5 5 5 2 10 1 1 30 35 35 35
.05 3.831 10 1.296 3.30 40 40 40 40 2 10 1 1 30 35 35 35
run;
data _null_; /* compute the power for the various scenarios */
set scenarios;
call execute(
'%baci_power(alpha=' || alpha ||
" , sdSite= " || sdSite ||
" , sdYear= " || sdYear ||
" , sdSiteYear=" || sdSiteYear ||
" , sdResid=" || sdResid ||
" , n_TA=" || n_ta ||
" , n_TB=" || n_tb ||
" , n_CA=" || n_CA ||
" , n_CB=" || n_CB ||
" , ns_T=" || ns_t ||
" , ns_C=" || ns_C ||
" , ny_B=" || ny_B ||
" , ny_A=" || ny_A ||
" , mu_TA=" || mu_TA ||
" , mu_TB=" || mu_TB ||
" , mu_CA=" || mu_CA ||
" , mu_CB=" || mu_CB || ");" );
* put "***temp***" temp;
run;
*---part500e;
proc print data=all_power;
title2 'Compute power';
run;
data scenarios;
merge scenarios all_power;
run;
proc print data=scenarios split="_" label;
title2 'Estimated power under various scenarios';
run;
proc print data=scenarios split="_" label;
var alpha
sdSite sdYear sdSiteYear sdResid
n_TA n_TB n_CA n_CB
ns_T ns_C
ny_B ny_A
mu_TA mu_TB mu_CA mu_CB power;
run;
ods pdf close;
/* Create LaTeX files for inclusion by my notes */
%include "../../MyLatexTagset.sas"; run;
title;
footnote;
ods listing;
ods tagsets.mycolorlatex file='baci-crabs-mod-power-SAS-500.tex' (notop nobot) stylesheet="sas.sty";
proc print data=scenarios split="_" label noobs;
var alpha
/* sdSite sdYear sdSiteYear sdResid */
n_TA n_TB n_CA n_CB
ns_T ns_C
ny_B ny_A
mu_TA mu_TB mu_CA mu_CB power;
run;
ods tagsets.mycolorlatex close;