1 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
70
71 /****************************** matpow2.sas ******************************/
72 title 'Power analysis for fixed-effects factorial ANOVA: Matrix approach';
73 title2 'Specify a beta vector instead of just an effect';
74 proc iml;
NOTE: IML Ready
75 /********* Edit this input: Rows of matrices are separated by commas ********/
76 alpha = 0.05;
77 wantpow = .80;
78 f = {1,1,1,1,1,1};
78 ! /* Relative sample sizes */
79 C = { 1 -1 -1 1 0 0, /* Contrast matrix */
80 0 0 1 -1 -1 1};
81 beta = {0,.25,0,.25,0,-.25};
82
83 /* In standard deviation units */
84 /*****************************************************************************/
85 eff = C*beta;
86 r = nrow(f) ;
86 ! q = nrow(eff);
86 ! f = f/sum(f);
87 /*** Echoing input ***/
88 print " Significance level: " alpha;
89 print " Desired power: " wantpow;
90 print " Relative sample sizes:" f;
91 print " Contrast matrix ";
91 ! print C;
92 print " Beta matrix (in SD units): " beta;
93 print " Effect (h) matrix in SD units: " eff;
94 /*** Checking input ***/
95 print " Checking input ... ";
96 inerr = 0;
96 ! /* Input error = no. This may be changed below */
97 if nrow(C) ^= q then do;
98 print "Error: Length of eff must equal number of rows in C";
99 inerr=1;
100 end;
101 if ncol(C) ^= r then do;
102 print "Error: Length of f must equal number of cols in C";
103 inerr=1;
104 end;
105 if eff`*eff = 0 then do;
106 print "Error: eff can't be zero; this would cause an infinite loop!";
107 inerr=1;
108 end;
109 aa = min(f##2);
110 if aa = 0 then do;
111 print "Error: No sample size may be zero.";
112 inerr=1;
113 end;
114
115 /*** Proceed if no input errors ***/
116 if inerr = 1 then abort;
117 else do;
118 print "Input appears to be okay. ";
119 core = inv(C*inv(diag(f))*C`);
120 effsize = eff`*core*eff;
120 ! print " Effect size = " effsize;
121 power = 0;
121 ! n = r+1;
121 ! oneminus = 1-alpha;
121 ! /* Initializing ...*/
122 do until (power >= wantpow);
123 n = n+1 ;
124 ncp = n * effsize;
125 df2 = n-r;
126 power = 1-probf(finv(oneminus,q,df2),q,df2,ncp);
127 end;
127 ! /* End Loop */
128 print " Required sample size is " n;
129 end;
129 ! /* End computation (Conditional on no input errors) */
130 quit;
NOTE: Exiting IML.
NOTE: PROCEDURE IML used (Total process time):
real time 0.06 seconds
user cpu time 0.06 seconds
system cpu time 0.00 seconds
memory 2331.81k
OS Memory 29604.00k
Timestamp 03/18/2020 03:07:57 AM
Step Count 42 Switch Count 0
Page Faults 0
Page Reclaims 373
Page Swaps 0
Voluntary Context Switches 0
Involuntary Context Switches 0
Block Input Operations 0
Block Output Operations 0
131
132 OPTIONS NONOTES NOSTIMER NOSOURCE NOSYNTAXCHECK;
143