D.G. Bonett (7/2017)

SAS Programs

Part I - Sample Size for Desired Precision

Program 1: Sample size to estimate one mean

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

var = 264.4; /* planning value of DV variance */

w = 10; /* desired confidence interval width */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int(4*var*(z/w)**2 + z**2/2) + 1;

print "Estimate Mean: One-group Design";

print ,,"Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print ,,"Sample size requirement = " n [format = 9.0];

quit;

Program 2: Sample size to estimate a mean difference (2-group design)

proc IML;
alpha = .05; /* alpha for 1-alpha confidence */

var = 37.1; /* planning value of within-group DV variance */

w = 5; /* desired confidence interval width */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int(8*var*(z/w)**2 + z**2/4) + 1;

print "Estimate Mean Difference: Two-group Design";

print ,,"Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print ,,"Sample size requirement per group = " n [format = 9.0];

quit;

Program 3: Sample size to estimate a standardized mean difference (2-group design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

d = .029; /* planning value of standardized mean difference */

w = .4; /* desired confidence interval width */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int((d**2 + 8)*(z/w)**2) + 1;

print "Estimate Standardized Mean Difference: Two-group Design";

print ,,"Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Std difference planning value = " d [format = 9.3];

print ,,"Sample size requirement per group = " n [format = 9.0];

quit;

Program 4: Sample size to estimate a ratio of means (2-group design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

var = .4; /* planning value of within-group DV variance */

m1 = 3.5; /* planning value of mean for group 1 */

m2 = 3.1; /* planning value of mean for group 2 */

r = 1.2; /* desired upper to lower confidence interval */

/* endpoint ratio */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int(8*var*(1/m1**2 + 1/m2**2)*(z/log(r))**2 + z**2/4) + 1;

print "Estimate Ratio of Means: Two-group Design";

print ,,"Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired upper to lower CI ratio = " r [format = 9.3];

print "Mean 1 planning value = " m1 [format = 9.3];

print "Mean 2 planning value = " m2 [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print ,,"Sample size requirement per group = " n [format = 9.0];

quit;

Program 5: Sample size to estimate a linear contrast of means (between-subjects design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

var = 5.62; /* planning values of within-group DV variance */

w = 2.0; /* desired confidence interval width */

c = {.5, .5, -1}; /* vector of contrast coefficients */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

m = sum(c ^= 0);

n = int(4*var*(c`*c)*(z/w)**2 + z**2/(2*m)) + 1;

print "Estimate Linear Contrast of Means: Between-subjects Design";

print ,,"Contrast coefficients = " (c`) [format = 5.4];

print "Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print ,,"Sample size requirement per group = " n [format = 9.0];

quit;

Program 6: Sample size to estimate a mean difference (within-subjects design)

proc IML;

alpha = .0167; /* alpha for 1-alpha confidence */

var = 45.67; /* planning value of DV variance */

cor = .919; /* planning of correlation */

w = 2; /* desired confidence interval width */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int(8*var*(1 - cor)*(z/w)**2 + z**2/2) + 1;

print "Estimate Mean Difference: Within-subjects Design";

print ,,"Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print "Correlation planning value = " cor [format = 9.3];

print ,,"Sample size requirement = " n [format = 9.0];

quit;

Program 7: Sample size to estimate a standardized mean difference (within-subjects design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

d = 1; /* planning value of standardized mean difference */

cor = .65; /* planning of correlation */

w = .6; /* desired confidence interval width */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int(4*(d**2*(1 + cor**2)/4 + 2*(1 - cor))*(z/w)**2) + 1;

print "Estimate Standardized Mean Difference: Within-subjects Design";

print ,,"Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Standardized difference planning value = " d [format = 9.3];

print "Correlation planning value = " cor [format = 9.3];

print ,,"Sample size requirement = " n [format = 9.0];

quit;

Program 8: Sample size to estimate a ratio of means (within-subjects design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

var = 400; /* planning value of average measurement 1 & 2 variance */

m1 = 150; /* planning value of mean for measurement 1 */

m2 = 100; /* planning value of mean for measurement 2 */

cor = .7; /* planning value of measurement correlation */

r = 1.2; /* desired upper to lower confidence interval endpoint ratio */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int(8*var*(1/m1**2 + 1/m2**2 - 2*cor/(m1*m2))*(z/log(r))**2 + z**2/2) + 1;

print "Estimate Ratio of Means: Within-subjects Design";

print ,,"Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired upper to lower CI ratio = " r [format = 9.3];

print "Mean 1 planning value = " m1 [format = 9.3];

print "Mean 2 planning value = " m2 [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print "Correlation planning value = " cor [format = 9.3];

print ,,"Sample size requirement = " n [format = 9.0];

quit;

Program 9: Sample size to estimate a linear contrast of means (within-subjects design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

var = 45.67; /* planning value of largest DV variance */

cor = .919; /* planning of smallest correlation */

w = 2; /* desired confidence interval width */

h = {.5, .5, -1}; /* vector of contrast coefficients */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

n = int(4*var*(h`*h)*(1 - cor)*(z/w)**2 + z**2/2) + 1;

print "Estimate Linear Contrast of Means: Within-subjects Design";

print ,,"Contrast coefficients = " (h`) [format = 5.3];

print "Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print "Correlation planning value = " cor [format = 9.3];

print ,,"Sample size requirement = " n [format = 9.0];

quit;

Program 10: Sample size to estimate a standardized linear contrast of means (between-subjects

design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

d = 1; /* planning value of DV variance */

w = .6; /* desired confidence interval width */

c = {.5, .5, -.5, -.5}; /* vector of contrast coefficients */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

a = nrow(c);

n = int((2*d**2/a + 4*(c`*c))*(z/w)**2) + 1;

print "Estimate Standardized Linear Contrast of Means: Between-subjects Design";

print ,,"Contrast coefficients = " (c`) [format = 5.3];

print "Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Standardized contrast planning value = " d [format = 9.3];

print ,,"Sample size requirement per group = " n [format = 9.0];

quit;

Program 11: Sample size to estimate a standardized linear contrast of means (within-subjects

design)

proc IML;

alpha = .05; /* alpha for 1-alpha confidence */

d = 1; /* planning value of standardized contrast */

cor = .7; /* planning of correlation */

w = .6; /* desired confidence interval width */

h = {.5, .5, -.5, -.5}; /* vector of contrast coefficients */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

z = probit(1 - alpha/2);

a = nrow(h);

n = int(4*(d**2*(1 + (a - 1)*cor**2)/(2*a) + (h`*h)*(1 - cor))*(z/w)**2) + 1;

print "Estimate Standardized Linear Contrast of Means: Within-subjects Design";

print ,,"Contrast coefficients = " (c`) [format = 5.3];

print "Desired confidence = " ((1 - alpha)*100) [format = 9.3];

print "Desired CI width = " w [format = 9.3];

print "Standardized contrast planning value = " d [format = 9.3];

print "Correlation planning value = " cor [format = 9.3];

print ,,"Sample size requirement = " n [format = 9.0];

quit;

Program 12: Second-stage sample size requirement

proc IML;

n0 = 20; /* first-stage sample size */

w0 = 5.3; /* first-stage CI width */

w = 2.5; /* desired CI width */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

n = int(((w0/w)**2 - 1)*n0) + 1;

print "Two-stage Sampling";

print ,,"Desired confidence interval width = " w [format = 9.3];

print "Obtained 1st-stage confidence interval width = " w0 [format = 9.3];

print ,,"Final sample size requirement = " n [format = 9.0];

quit;

Part II - Sample Size for Desired Power

Program 13: Sample size for one sample t-test

proc IML;

alpha = .05; /* alpha value for test */

var = 80.5; /* planning value of DV variance */

pow = .90; /* desired power */

es = 7.0; /* mean planning value minus */

/* null hypothesis value */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

za = probit(1 - alpha/2);

zb = probit(pow);

n = int(var*(za + zb)**2/es**2 + za**2/2) + 1;

print "Test Mean = b: One-group Design";

print ,,"Alpha level = " alpha [format = 9.3];

print "Desired power = " pow [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print "Effect size = " es [format = 9.3];

print ,,"Sample size requirement = " n [format = 9.0];

quit;

Program 14: Sample size for independent-samples t-test

proc IML;

alpha = .05; /* alpha value for test */

var = 100.0; /* planning value of within-group DV variance */

pow = .95; /* desired power */

es = 10.0; /* planning value of mean difference */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

za = probit(1 - alpha/2);

zb = probit(pow);

n = int(2*var*(za + zb)**2/es**2 + za**2/4) + 1;

print "Test Mean Difference: Two-group Design";

print ,,"Alpha level = " alpha [format = 9.3];

print "Desired power = " pow [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print "Effect size = " es [format = 9.3];

print ,,"Sample size requirement per group = " n [format = 9.0];

quit;

Program 15: Sample size to test a linear contrast of means (between-subjects design)

proc IML;

alpha = .05; /* alpha value for test */

var = 27.5; /* planning value of within-group DV variance */

pow = .90; /* desired power */

es = 5.0; /* planning value of linear contrast */

c = {1, -1, -1, 1}; /* vector of contrast coefficients */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;

za = probit(1 - alpha/2);

zb = probit(pow);

m = sum(c ^= 0);

n = int(var*(c`*c)*(za + zb)**2/es**2 + za**2/(2*m)) + 1;

print "Test Linear Contrast of Means: Between-subjects Design";

print ,,"Contrast coefficients = " (c`) [format = 5.3];

print "Alpha level = " alpha [format = 9.3];

print "Desired power = " pow [format = 9.3];

print "Variance planning value = " var [format = 9.3];

print "Effect size = " es [format = 9.3];

print ,,"Sample size requirement per group = " n [format = 9.0];

quit;

Program 16: Sample size for paired-samples t-test

proc IML;

alpha = .05; /* alpha value for test */

var = 1.25; /* planning value of DV variance */

cor = .75; /* planning value of correlation */

pow = .80; /* desired power */

es = .5; /* planning value of mean difference */

/* ======*/

reset noname printadv = 0;

options nodate nonumber nocenter;

ods graphics off; ods html close; ods listing;