SAS Programs for Selecting Sample Size
/************************** sampvar1.sas **************************/ /* Finds n needed for significance, for a given proportion of */ /* remaining variation */ /*******************************************************************/ options linesize = 79 pagesize = 200; data explvar; /* Can replace alpha, s, p, and a below. */ alpha = 0.05; /* Significance level. */ s = 6; /* Numerator df = # IVs being tested. */ p = 26; /* There are p beta parameters. */ a = .10 ; /* Proportion of remaining variation after */ /* controlling for all other variables. */ /* Initializing ... */ pval = 1; n = p+1; do until (pval <= alpha); F = (n-p)/s * a/(1-a); df2 = n-p; pval = 1-probf(F,s,df2); n = n+1 ; end; /* When finished, n is one too many */ n = n-1; F = (n-p)/s * a/(1-a); df2 = n-p; pval = 1-probf(F,s,df2); put ' *********************************************************'; put ' '; put ' For a multiple regression model with ' p 'betas, '; put ' testing ' s ' variables controlling for the others,'; put ' a sample size of ' n 'is needed for significance at the'; put ' alpha = ' alpha 'level, when the effect explains a = ' a ; put ' of the remaining variation after allowing for all other '; put ' variables in the model. '; put ' F = ' F ',df = (' s ',' df2 '), p = ' pval; put ' '; put ' *********************************************************';
/************************** sampvar2.sas ****************************/ /* Finds proportion of remaining variation needed for significance, */ /* given sample size n */ /*********************************************************************/ options linesize = 79 pagesize = 200; data explvar; /* Replace alpha, s, p, and a below. */ alpha = 0.05; /* Significance level. */ s = 6; /* Numerator df = # IVs being tested. */ p = 26; /* There are p beta parameters. */ n = 120 ; /* Sample size */ /* Initializing ... */ pval = 1; a = 0; df2 = n-p; do until (pval <= alpha); F = (n-p)/s * a/(1-a); pval = 1-probf(F,s,df2); a = a + .001 ; end; /* When finished, a is .001 too much */ a = a-.001; F = (n-p)/s * a/(1-a); pval = 1-probf(F,s,df2); put ' ******************************************************'; put ' '; put ' For a multiple regression model with ' p 'betas, '; put ' testing ' s ' variables at significance level '; put ' alpha = ' alpha ' controlling for the other variables,'; put ' and a sample size of ' n', the variables need to explain'; put ' a = ' a ' of the remaining variation to be significant.'; put ' F = ' F ', df = (' s ',' df2 '), p = ' pval; put ' '; put ' *******************************************************';
/*********************** popvar.sas *****************************/ options linesize = 79 pagesize = 200; data fpower; /* Replace alpha, s, p, and wantpow below */ alpha = 0.05; /* Significance level */ s = 6; /* Numerator df = # IVs being tested */ p = 26; /* There are p beta parameters */ a = .10 ; /* Effect size */ wantpow = .80; /* Find n to yield this power. */ power = 0; n = p+1; oneminus = 1-alpha; /* Initializing ... */ do until (power >= wantpow); ncp = (n-p)*a/(1-a); df2 = n-p; power = 1-probf(finv(oneminus,s,df2),s,df2,ncp); n = n+1 ; end; n = n-1; put ' *********************************************************'; put ' '; put ' For a multiple regression model with ' p 'betas, '; put ' testing ' s 'independent variables using alpha = ' alpha ','; put ' a sample size of ' n 'is needed'; put ' in order to have probability ' wantpow 'of rejecting H0'; put ' for an effect of size a = ' a ; put ' '; put ' *********************************************************';