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