. * do-file for lecture 13 of VHM 802, Winter 2025 . version 18 /* works also with versions 14-17 */ . set more off . set scheme stcolor_alt . cd "r:\" r:\ . . * power and sample size calculations are best done from the menu . * this do-file shows the corresponding commands . . * sample size based on precision/ margin of error . * method has additional probability of achieving target CI width, set at 0.5 for similar results as without it . * blood pressure example . ciwidth onemean, probwidth(.8) width(6) sd(10) Performing iteration ... Estimated sample size for a one-mean CI Student's t two-sided CI Study parameters: level = 95.00 Pr_width = 0.8000 width = 6.0000 sd = 10.0000 Estimated sample size: N = 53 . ciwidth onemean, probwidth(.5) width(6) sd(10) Performing iteration ... Estimated sample size for a one-mean CI Student's t two-sided CI Study parameters: level = 95.00 Pr_width = 0.5000 width = 6.0000 sd = 10.0000 Estimated sample size: N = 45 . * VOR example . ciwidth twomeans, probwidth(.8) width(.5) sd(0.2739) Performing iteration ... Estimated sample sizes for a two-means-difference CI Student's t two-sided CI assuming sd1 = sd2 = sd Study parameters: level = 95.00 Pr_width = 0.8000 width = 0.5000 sd = 0.2739 Estimated sample sizes: N = 26 N per group = 13 . ciwidth twomeans, probwidth(.5) width(.5) sd(0.2739) Performing iteration ... Estimated sample sizes for a two-means-difference CI Student's t two-sided CI assuming sd1 = sd2 = sd Study parameters: level = 95.00 Pr_width = 0.5000 width = 0.5000 sd = 0.2739 Estimated sample sizes: N = 22 N per group = 11 . . * sample size based on power . * blood pressure example . power onemean 0 3, sd(10) Performing iteration ... Estimated sample size for a one-sample mean test t test H0: m = m0 versus Ha: m != m0 Study parameters: alpha = 0.0500 power = 0.8000 delta = 0.3000 m0 = 0.0000 ma = 3.0000 sd = 10.0000 Estimated sample size: N = 90 . * VOR example . power oneway 2.82 3.89 3.04, varerror(.075) alpha(0.01) npergroup(4) Estimated power for one-way ANOVA F test for group effect H0: delta = 0 versus Ha: delta != 0 Study parameters: alpha = 0.0100 N = 12 N per group = 4 delta = 1.6847 N_g = 3 m1 = 2.8200 m2 = 3.8900 m3 = 3.0400 Var_m = 0.2129 Var_e = 0.0750 Estimated power: power = 0.9298 . . * calcium supplementation example . * no interaction ~ test by main effect . power twoway 0 0\ 5 5, varerror(100) factor(row) /* note that mean diff between rows is 5 */ Performing iteration ... Estimated sample size for two-way ANOVA F test for row effect H0: delta = 0 versus Ha: delta != 0 Study parameters: alpha = 0.0500 power = 0.8000 delta = 0.2500 N_r = 2 N_c = 2 means = Var_r = 6.2500 Var_e = 100.0000 Estimated sample sizes: N = 128 N per cell = 32 . * interaction . power twoway 0 0\ 0 5, varerror(100) factor(rowcol) /* note that interaction must be 5 */ Performing iteration ... Estimated sample size for two-way ANOVA F test for row-by-column effect H0: delta = 0 versus Ha: delta != 0 Study parameters: alpha = 0.0500 power = 0.8000 delta = 0.1250 N_r = 2 N_c = 2 means = Var_rc = 1.5625 Var_e = 100.0000 Estimated sample sizes: N = 508 N per cell = 127 . . * cat food example . import delimited catfood.csv, clear (encoding automatically selected: ISO-8859-1) (2 vars, 19 obs) . ttest protein, by(product) unequal Two-sample t test with unequal variances ------------------------------------------------------------------------------ Group | Obs Mean Std. err. Std. dev. [95% conf. interval] ---------+-------------------------------------------------------------------- Discount | 10 33.971 .1836147 .5806408 33.55563 34.38637 Original | 9 34.09222 .0871265 .2613796 33.89131 34.29314 ---------+-------------------------------------------------------------------- Combined | 19 34.02842 .1033143 .4503365 33.81137 34.24548 ---------+-------------------------------------------------------------------- diff | -.1212217 .2032373 -.561058 .3186146 ------------------------------------------------------------------------------ diff = mean(Discount) - mean(Original) t = -0.5965 H0: diff = 0 Satterthwaite's degrees of freedom = 12.7802 Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 Pr(T < t) = 0.2806 Pr(|T| > |t|) = 0.5613 Pr(T > t) = 0.7194 . ttest protein, by(product) unequal level(90) Two-sample t test with unequal variances ------------------------------------------------------------------------------ Group | Obs Mean Std. err. Std. dev. [90% conf. interval] ---------+-------------------------------------------------------------------- Discount | 10 33.971 .1836147 .5806408 33.63441 34.30759 Original | 9 34.09222 .0871265 .2613796 33.93021 34.25424 ---------+-------------------------------------------------------------------- Combined | 19 34.02842 .1033143 .4503365 33.84927 34.20757 ---------+-------------------------------------------------------------------- diff | -.1212217 .2032373 -.4816154 .239172 ------------------------------------------------------------------------------ diff = mean(Discount) - mean(Original) t = -0.5965 H0: diff = 0 Satterthwaite's degrees of freedom = 12.7802 Ha: diff < 0 Ha: diff != 0 Ha: diff > 0 Pr(T < t) = 0.2806 Pr(|T| > |t|) = 0.5613 Pr(T > t) = 0.7194 . * using add-on package tost . tostt protein, by(product) eqvlevel(.5) unequal Two-sample unpaired t test for mean equivalence with unequal variances ------------------------------------------------------------------------------ Group | Obs Mean Std. err. Std. dev. [95% conf. interval] ---------+-------------------------------------------------------------------- | 10 33.971 .1836147 .5806408 33.55563 34.38637 | 9 34.09222 .0871265 .2613796 33.89131 34.29314 ---------+-------------------------------------------------------------------- D-diff | .6212217 .2032373 .1813854 1.061058 diff+D | .3787783 .2032373 -.061058 .8186146 ------------------------------------------------------------------------------ diff = mean(protein|product = .) - mean(protein|product = .) Delta (D) = 0.5000 Delta expressed in same units as protein df = 12.7802 using Satterthwaite's formula Ho: |diff| >= Delta: t1 = 3.057 t2 = 1.864 Ho1: Delta-diff >= 0 Ho2: diff+Delta <= 0 Ha1: Delta-diff < 0 Ha2: diff+Delta > 0 Pr(T > t1) = 0.0047 Pr(T > t2) = 0.0427 . * shows the two one-sided t-tests .