· web viewsas programs part i - sample size for desired precision program 1: sample size to...

21

Click here to load reader

Upload: dinhdat

Post on 23-Mar-2018

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

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;

Page 2: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

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;

Page 3: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

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;

Page 4: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

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;

Page 5: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

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;

Page 6: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

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;

Page 7: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

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;

Page 8: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

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;za = probit(1 - alpha/2);zb = probit(pow);n = int(2*var*(1 - cor)*(za + zb)**2/es**2 + za**2/2) + 1;print "Test Mean Difference: Within-subjects Design";print ,,"Alpha level = " alpha [format = 9.3];print "Desired power = " pow [format = 9.3];print "Variance planning value = " var [format = 9.3];print "Correlation planning value = " cor [format = 9.3];print "Effect size = " es [format = 9.3];print ,,"Sample size requirement = " n [format = 9.0];quit;

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

Page 9: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

proc IML;alpha = .05; /* alpha value for test */var = 50.7; /* planning value of largest DV variance */pow = .90; /* desired power */es = 2.0; /* planning value of linear contrast */cor = .8; /* planning value of smallest correlation */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;za = probit(1 - alpha/2);zb = probit(pow);n = int(var*(h`*h)*(1 - cor)*(za + zb)**2/(es**2) + za**2/2) + 1;print "Test Linear Contrast of Means: Within-subjects Design";print ,,"Contrast coefficients = " (h`) [format = 5.3];print "Alpha level = " alpha [format = 9.3];print "Desired power = " pow [format = 9.3];print "Effect size = " es [format = 9.5];print "Variance planning value = " var [format = 9.3];print "Correlation planning value = " cor [format = 9.3];print "Effect size = " es [format = 9.3];print ,,"Sample size requirement = " n [format = 9.0];quit;

Program 18: Sample size for Sign test (1-group design)

proc IML;alpha = .05; /* alpha value for test */ p = .3; /* expected proportion of cases with scores greater than hypothesized median */pow = .90; /* desired power *//* ================================================================= */reset noname printadv = 0;options nodate nonumber nocenter;ods graphics off; ods html close; ods listing;za = probit(1 - alpha/2);zb = probit(pow);es = p - .5;n = int((za + zb)**2/(4*es**2)) + 1;print "Sign Test of Median: One-group Design";print ,,"Alpha level = " alpha [format = 9.3];print "Desired power = " pow [format = 9.3];print "Proportion planning value = " p [format = 9.3];print ,,"Sample size requirement = " n [format = 9.0];quit;

Program 19: Sample size for Mann-Whitney test

Page 10: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

proc IML;alpha = .05; /* alpha value for test */p = .3; /* expected proportion of cases with scores higher under treatment 1 than treatment 2 */pow = .9; /* desired power *//* =============================================================== */reset noname printadv = 0;options nodate nonumber nocenter;ods graphics off; ods html close; ods listing;za = probit(1 - alpha/2);zb = probit(pow);es = p - .5;n = int((za + zb)**2/(6*es**2)) + 1;print "Mann-Whitney Test";print ,,"Alpha level = " alpha [format = 9.3];print "Desired power = " pow [format = 9.3];print "Proportion planning value = " p [format = 9.3];print ,,"Sample size requirement per group = " n [format = 9.0];quit;

Program 20: Sample size for Sign Test (within-subjects design)

proc IML;alpha = .05; /* alpha value for test */p = .75; /* expected proportion of cases with scores greater under treatment 1 than treatment 2 */pow = .9; /* desired power *//* =============================================================== */reset noname printadv = 0;options nodate nonumber nocenter;ods graphics off; ods html close; ods listing;za = probit(1 - alpha/2);zb = probit(pow);es = p - .5;n = int((za + zb)**2/(4*es**2)) + 1;print "Sign Test: Within-subjects Design";print ,,"Alpha level = " alpha [format = 9.3];print "Desired power = " pow [format = 9.3];print "Proportion planning value = " p [format = 9.3];print ,,"Sample size requirement = " n [format = 9.0];quit;

Page 11: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

Part III – Confidence Intervals

Program 21: Confidence interval for a standardized mean difference (2-group design)

proc IML;alpha = .05; /* alpha for 1-alpha confidence level */n1 = 12; /* sample size for group 1 */n2 = 12; /* sample size for group 2 */m1 = 11.83; /* sample mean for group 1 */m2 = 14.25; /* sample mean for group 2 */s1 = 2.04; /* sample SD for group 1 */s2 = 2.42; /* sample SD for group 2 *//*====================================================================== */reset noname printadv = 0;options nodate nonumber nocenter;ods graphics off; ods html close; ods listing;print "CONFIDENCE INTERVALS FOR STANDARDIZED MEAN DIFFERENCE: 2-GROUP DESIGN";z = probit(1 - alpha/2);s = sqrt((s1**2 + s2**2)/2);df1 = n1 - 1;df2 = n2 - 1;d1 = (m1 - m2)/s;v = d1**2*(s1**4/df1 + s2**4/df2)/(8*s**4) + (s1**2/df1 + s2**2/df2)/s**2;se1 = sqrt(v);ll1 = d1 - z*se1;ul1 = d1 + z*se1;sp = sqrt((df1*s1**2 + df2*s2**2)/(n1 + n2 - 2));d2 = (m1 - m2)/sp;v = d2**2*(1/df1 + 1/df2)/8 + 1/n1 + 1/n2;se2 = sqrt(v);ll2 = d2 - z*se2;ul2 = d2 + z*se2;d3 = (m1 - m2)/s1;v = d3**2/(2*df1) + 1/df1 + s2**2/(df2*s1**2);se3 = sqrt(v);ll3 = d3 - z*se3;ul3 = d3 + z*se3;d4 = (m1 - m2)/s2;v = d4**2/(2*df2) + 1/df2 + s1**2/(df1*s2**2);se4 = sqrt(v);ll4 = d4 - z*se4;ul4 = d4 + z*se4;print, "Confidence = " (1 - alpha) [format = 5.3];print "n1 = " n1 [format = 5.0];print "n2 = " n2 [format = 5.0];print, " Estimate SE LL UL";text = {"Equal variances not assumed", "Equal variances assumed", "Group 1 standardizer", "Group 2 standardizer"};out = ((d1||se1||ll1||ul1)//(d1||se2||ll2||ul2) //(d3||se3||ll3||ul3)//(d4||se4||ll4||ul4));print text out[format = 9.4];quit;

Page 12: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

Program 22: Confidence interval for a standardized mean difference (within-subjects design)

data;proc IML;alpha = .05; /* alpha for 1-alpha confidence level */n = 25; /* sample size */m1 = 110.4; /* sample mean for condition 1 */m2 = 102.1; /* sample mean for condition 2 */s1 = 15.3; /* sample SD for condition 1 */ s2 = 14.6; /* sample SD for condition 2 */r = .75; /* sample correlation *//*====================================================================== */reset noname printadv = 0;options nodate nonumber nocenter;ods graphics off; ods html close; ods listing;print "CONFIDENCE INTERVALS FOR STANDARDIZED MEAN DIFFERENCE: WITHIN-SUBJECTS DESIGN";z = probit(1 - alpha/2);v1 = s1**2;v2 = s2**2;vd = v1 + v2 - 2*r*s1*s2s = sqrt((v1 + v2)/2);d1 = (m1 - m2)/s;v = d1**2*(v1**2 + v2**2 + 2*r**2*v1*v2)/(8*(n - 1)*s**4) + vd/((n - 1)*s**2);se1 = sqrt(v);ll1 = d1 - z*se1;ul1 = d1 + z*se1;v = d1**2*(1 + r**2)/(4*(n - 1)) + 2*(1 - r)/n;se2 = sqrt(v);ll2 = d1 - z*se2;ul2 = d1 + z*se2;d3 = (m1 - m2)/s1;v = d3**2/(2*(n - 1)) + vd/((n - 1)*s1**2);se3 = sqrt(v);ll3 = d3 - z*se3;ul3 = d3 + z*se3;d4 = (m1 - m2)/s2;v = d4**2/(2*(n - 1)) + vd/((n - 1)*s2**2);se4 = sqrt(v);ll4 = d4 - z*se4;ul4 = d4 + z*se4;print ,,"Confidence = " (1 - alpha) [format = 5.3];print "n = " n [format = 5.0];print , " Estimate SE LL UL";text = {"Equal variances not assumed", "Equal variances assumed", "Level 1 standardizer", "Level 2 standardizer"};out = ((d1||se1||ll1||ul1)//(d1||se2||ll2||ul2) //(d3||se3||ll3||ul3)//(d4||se4||ll4||ul4));print text out[format = 9.4];quit;

Page 13: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

Program 23: Confidence interval for a linear contrast of unstandardized and standardized means (between-subjects design)

data mydata;input n mean std c; /* n = sample size */ /* mean = sample mean */ /* std = sample standard deviation */ /* c = contrast coefficient *//* ===================================================================== */datalines; /* Example data - replace with your data */10 33.5 3.84 .5 10 37.9 3.84 .510 38.0 3.65 -.510 44.1 4.98 -.5;/* ==================================================================== */proc IML;alpha = .05; /* alpha for 1-alpha confidence *//* ==================================================================== */reset noname printadv = 0; options nodate nonumber nocenter;ods graphics off; ods html close; ods listing;use mydata;read all into data;n = data[,1];m = data[,2];s = data[,3];c = data[,4];print "CONFIDENCE INTERVALS FOR LINEAR CONTRASTS OF MEANS: BETWEEN-SUBJECTS DESIGN";file print;print , "Confidence level: " (1 - alpha)[format = 4.3];print , "Constrast:" (c`)[format = 6.3];k = nrow(n);h = c ^= 0;b = sum(h);n1 = n[1,1];s1 = s[1,1];v = s##2;s = sqrt(sum(v)/k);s0 = sqrt(sum(h#v)/b);est1 = c`*m;est2 = est1/s;est3 = est1/s0;est4 = est1/s1;z = probit(1 - alpha/2);/* ================ Computations for unequal variance methods =============== */v1 = v/n;se1 = sqrt(c`*diag(v1)*c);a1 = est2**2/(k**2*s**4);a2 = a1*sum((s##4/(2#(n - 1))));a3 = sum((c##2)#(s##2/(n - 1)));a4 = est3**2/(b**2*s0**4);a5 = a4*sum(h#(s##4/(2#(n - 1))));a6 = sum(h#(c##2)#(s##2/(n - 1)));se2 = sqrt(a2 + a3/s**2);se3 = sqrt(a5 + a6/s0**2);se4 = sqrt(est4**2/(2*n1 - 2) + a3/s1**2);u1 = (sum(v1#c##2))**2;u2 = sum((c##4)#v1##2/(n - 1));df = u1/u2;t = tinv(1 - alpha/2, df);t1 = est1/se1;ll1 = est1 - t*se1;

Page 14: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

ul1 = est1 + t*se1;ll2 = est2 - z*se2;ul2 = est2 + z*se2;ll3 = est3 - z*se3;ul3 = est3 + z*se3;ll4 = est4 - z*se4;ul4 = est4 + z*se4;text = {"Standardized (a) ", "Standardized (b) ", "Standardized (c) "};out = (est2||se2||ll2||ul2)//(est3||se3||ll3||ul3)//(est4||se4||ll4||ul4);print ,, "Equal variances not assumed:";print , " Contrast SE LL UL t df";print "Unstandardized " est1[format = 10.4] se1[format = 10.4] ll1[format = 10.4] ul1[format = 10.4] t1[format = 10.4] df[format = 10.2]; print text out[format = 10.4];/* ================= Computations for Equal Variance Methods ================= */df = sum(n) - k;sp = sum((n - 1)#v)/df;se1 = sqrt(sp*c`*diag(1/n)*c);a1 = est2**2/k**2;a2 = a1*sum(1/(2#(n - 1)));a3 = sum(c##2/n);a4 = est3**2/b**2;a5 = a4*sum(h/(2#(n - 1));a6 = sum(h#c##2/n);se2 = sqrt(a2 + a3);se3 = sqrt(a5 + a6);se4 = sqrt(est4**2/(2*n1 - 2) + a3);t = tinv(1 - alpha/2, df);t1 = est1/se1;ll1 = est1 - t*se1;ul1 = est1 + t*se1;ll2 = est2 - z*se2;ul2 = est2 + z*se2;ll3 = est3 - z*se3;ul3 = est3 + z*se3;ll4 = est4 - z*se4;ul4 = est4 + z*se4;text = {"Standardized (a) ", "Standardized (b) ", "Standardized (c) "};out = (est2||se2||ll2||ul2)//(est3||se3||ll3||ul3)//(est4||se4||ll4||ul4);print ,, "Equal variances assumed:";print , " Contrast SE LL UL t df";print "Unstandardized " est1[format = 10.4] se1[format = 10.4] ll1[format = 10.4] ul1[format = 10.4] t1[format = 10.4] df[format = 10.2]; print text out[format = 10.4];print ,, "Notes:";print "a = standardizer based on variances from all groups";print "b = standardizer based on variances from groups with nonzero coefficients";print "c = standardizer based on variances from group 1 (assumed control group)";quit;

Page 15: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

Part IV – Power for Specified Sample Size

Program 24: Power for one-sample t-test

proc power; onesamplemeans /* NOTE: no semicolon until last statement */ power = . /* solve for power */ alpha = 0.05 /* alpha value for test */ stddev = 15 /* square root of planning variance */ mean = 105.0 /* planning mean */ nullmean = 100 /* null hypothesis value */ ntotal = 75; /* sample size */run;

Program 25: Power for independent-samples t-test

proc power; twosamplemeans /* NOTE: no semicolon until last statement */ power = . /* solve for power */ alpha = 0.05 /* alpha value for test */ stddev = 6.1 /* square root of planning variance */ meandiff = 5.0 /* difference in planning means */ npergroup = 20; /* sample size per group */run;

Program 26: Power for paired-samples t-test

proc power; pairedmeans /* NOTE: no semicolon until last statement */ power = . /* solve for power */ alpha = 0.05 /* alpha value for test */ stddev = 10.0 /* square root of planning variance */ corr = .8 /* planning correlation */ meandiff = 5.0 /* difference in planning means */ npairs = 20; /* sample size (number of pairs) */run;

Program 27: Power of F-test in one-way ANOVA (between-subjects design)

proc power; onewayanova /* NOTE: no semicolon until last statement */ power = . /* solve for power */ alpha = 0.05 /* alpha value for test */ groupmeans = 10|15|20|22 /* planning value means */ groupns = 20|20|20|20 /* group sample sizes */ stddev = 12 /* squared root of planning variance */ test = overall_F; /* specify F-test of equal means */run;

Page 16: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

Program 28: Power of test of linear contrast of means (between-subjects design)

proc power; onewayanova /* NOTE: no semicolon until last statement */ power = . /* solve for power */ alpha = 0.05 /* alpha value for test */ groupmeans = 10|15|20|22 /* planning value means (4 group design) */ groupns = 20|20|20|20 /* group sample sizes */ stddev = 12 /* square root of planning variance */ contrast =(.5 .5 -.5 -.5); /* contrast coefficients */run;

Page 17: · Web viewSAS Programs Part I - Sample Size for Desired Precision Program 1: Sample size to estimat e one mean proc IML; alpha = .05; /* alpha for 1-alpha confidence */ var = 264.4;

D.G. Bonett (7/2017)

Part V – Random Sample and Randomization Programs

Program 29: Random sample generator

data random (keep = ID); N = 4000;                           /* study population size */do ID = 1 to N;output;end;proc surveyselect data = random method = SRS rep = 1 seed = 0 out = sample   sampsize = 32;                     /* sample size           */   ID _all_;                                run;proc print data = sample;  var ID;run;

Program 30: Randomization into groups

proc print data = sample; var ID;options nonumber;proc format;value treatment 1 = 'Treatment 1' 2 = 'Treatment 2'; /* Give a label for each treatment condition */ /* add 3 ='Treatment 3'; for 3 group design, etc. */ /* put semicolon at end of last line only */run;proc plan;factors subject = 10 random treatment = 2 /* number of subjects per group in subject = */ /* number of treatment groups in treatment = */random/noprint;output out = first treatment nvals = (1 2) random; /* integers 1 2 ... k where k is number of groups */run;data first(keep = ID subject treatment);set first;id = put(_n_, z3.);run;proc sort; by ID;run;proc print noobs split = "*";var ID treatment;label ID = "SUBJECT*ID"treatment = "TREATMENT*GROUP";format treatment treatment.;run;